r2rs-stats 0.1.1

Statistics programming for Rust based on R's stats package
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
use crate::sexprec::{SEXP, SEXPTYPE};
use ::libc;
extern "C" {

    /*
     *  R : A Computer Language for Statistical Data Analysis
     *  Copyright (C) 1998-2005   The R Core Team
     *
     *  This header file is free software; you can redistribute it and/or modify
     *  it under the terms of the GNU Lesser General Public License as published by
     *  the Free Software Foundation; either version 2.1 of the License, or
     *  (at your option) any later version.
     *
     *  This file is part of R. R is distributed under the terms of the
     *  GNU General Public License, either Version 2, June 1991 or Version 3,
     *  June 2007. See doc/COPYRIGHTS for details of the copyright status of R.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU Lesser General Public License for more details.
     *
     *  You should have received a copy of the GNU Lesser General Public License
     *  along with this program; if not, a copy is available at
     *  https://www.R-project.org/Licenses/
     */
    /* Included by R.h: API */
    #[no_mangle]
    fn error(_: *const libc::c_char, _: ...) -> !;
    #[no_mangle]
    fn R_alloc(_: size_t, _: libc::c_int) -> *mut libc::c_char;
    #[no_mangle]
    fn XLENGTH(x: SEXP) -> R_xlen_t;
    #[no_mangle]
    fn REAL(x: SEXP) -> *mut libc::c_double;
    #[no_mangle]
    fn SET_STRING_ELT(x: SEXP, i: R_xlen_t, v: SEXP);
    #[no_mangle]
    fn SET_VECTOR_ELT(x: SEXP, i: R_xlen_t, v: SEXP) -> SEXP;
    #[no_mangle]
    static mut R_NamesSymbol: SEXP;
    #[no_mangle]
    fn asInteger(x: SEXP) -> libc::c_int;
    #[no_mangle]
    fn mkChar(_: *const libc::c_char) -> SEXP;
    #[no_mangle]
    fn setAttrib(_: SEXP, _: SEXP, _: SEXP) -> SEXP;
    #[no_mangle]
    fn allocVector(_: SEXPTYPE, _: R_xlen_t) -> SEXP;
    #[no_mangle]
    fn ScalarInteger(_: libc::c_int) -> SEXP;
    #[no_mangle]
    fn ScalarLogical(_: libc::c_int) -> SEXP;
    #[no_mangle]
    fn protect(_: SEXP) -> SEXP;
    #[no_mangle]
    fn unprotect(_: libc::c_int);
    #[no_mangle]
    fn dcgettext(
        __domainname: *const libc::c_char,
        __msgid: *const libc::c_char,
        __category: libc::c_int,
    ) -> *mut libc::c_char;
}
pub type size_t = libc::c_ulong;
pub type ptrdiff_t = libc::c_long;
/*
 *  R : A Computer Language for Statistical Data Analysis
 *  Copyright (C) 2000, 2001 The R Core Team.
 *
 *  This header file is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2.1 of the License, or
 *  (at your option) any later version.
 *
 *  This file is part of R. R is distributed under the terms of the
 *  GNU General Public License, either Version 2, June 1991 or Version 3,
 *  June 2007. See doc/COPYRIGHTS for details of the copyright status of R.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, a copy is available at
 *  https://www.R-project.org/Licenses/
 */
/* Included by R.h: API */
pub type Rboolean = libc::c_uint;
pub const TRUE: Rboolean = 1;
pub const FALSE: Rboolean = 0;
pub type R_xlen_t = ptrdiff_t;
pub type C2RustUnnamed = libc::c_uint;
pub const sm_TUKEY_ENDRULE: C2RustUnnamed = 2;
pub const sm_COPY_ENDRULE: C2RustUnnamed = 1;
pub const sm_NO_ENDRULE: C2RustUnnamed = 0;
unsafe extern "C" fn med3(
    mut u: libc::c_double,
    mut v: libc::c_double,
    mut w: libc::c_double,
) -> libc::c_double {
    /*, MAYBE */
    /* Median(u,v,w): */
    if u <= v && v <= w || u >= v && v >= w {
        return v;
    }
    if u <= w && w <= v || u >= w && w >= v {
        return w;
    }
    /* else */
    return u;
}
/* Note: Velleman & Hoaglin use a smarter version,  which returns "change"
   ----
   and change = TRUE, when  med3(u,v,w) != v   ==> makes "R" (in "3R") faster
*/
unsafe extern "C" fn imed3(
    mut u: libc::c_double,
    mut v: libc::c_double,
    mut w: libc::c_double,
) -> libc::c_int {
    /* Return (Index-1) of  median(u,v,w) , i.e.,
       -1 : u
    0 : v
    1 : w
     */
    if u <= v && v <= w || u >= v && v >= w {
        return 0 as libc::c_int;
    }
    if u <= w && w <= v || u >= w && w >= v {
        return 1 as libc::c_int;
    }
    /* else */
    return -(1 as libc::c_int);
}
unsafe extern "C" fn sm_3(
    mut x: *mut libc::c_double,
    mut y: *mut libc::c_double,
    mut n: R_xlen_t,
    mut end_rule: libc::c_int,
) -> Rboolean {
    /* y[] := Running Median of three (x) = "3 (x[])" with "copy ends"
     * ---  return chg := ( y != x ) */
    let mut i: R_xlen_t = 0;
    let mut j: libc::c_int = 0;
    let mut chg: Rboolean = FALSE;
    if n <= 2 as libc::c_int as libc::c_long {
        i = 0 as libc::c_int as R_xlen_t;
        while i < n {
            *y.offset(i as isize) = *x.offset(i as isize);
            i += 1
        }
        return FALSE;
    }
    i = 1 as libc::c_int as R_xlen_t;
    while i < n - 1 as libc::c_int as libc::c_long {
        j = imed3(
            *x.offset((i - 1 as libc::c_int as libc::c_long) as isize),
            *x.offset(i as isize),
            *x.offset((i + 1 as libc::c_int as libc::c_long) as isize),
        );
        *y.offset(i as isize) = *x.offset((i + j as libc::c_long) as isize);
        chg = (chg as libc::c_uint != 0 || j != 0) as libc::c_int as Rboolean;
        i += 1
    }
    /* [y, chg]  :=  sm_DO_ENDRULE(x, y, end_rule, chg) : */
    /* do nothing : don't even assign them */
    /* 1 */
    /* 2 */
    match end_rule {
        0 => {}
        1 => {
            *y.offset(0 as libc::c_int as isize) = *x.offset(0 as libc::c_int as isize);
            *y.offset((n - 1 as libc::c_int as libc::c_long) as isize) =
                *x.offset((n - 1 as libc::c_int as libc::c_long) as isize)
        }
        2 => {
            *y.offset(0 as libc::c_int as isize) = med3(
                3 as libc::c_int as libc::c_double * *y.offset(1 as libc::c_int as isize)
                    - 2 as libc::c_int as libc::c_double * *y.offset(2 as libc::c_int as isize),
                *x.offset(0 as libc::c_int as isize),
                *y.offset(1 as libc::c_int as isize),
            );
            chg = (chg as libc::c_uint != 0
                || *y.offset(0 as libc::c_int as isize) != *x.offset(0 as libc::c_int as isize))
                as libc::c_int as Rboolean;
            *y.offset((n - 1 as libc::c_int as libc::c_long) as isize) = med3(
                *y.offset((n - 2 as libc::c_int as libc::c_long) as isize),
                *x.offset((n - 1 as libc::c_int as libc::c_long) as isize),
                3 as libc::c_int as libc::c_double
                    * *y.offset((n - 2 as libc::c_int as libc::c_long) as isize)
                    - 2 as libc::c_int as libc::c_double
                        * *y.offset((n - 3 as libc::c_int as libc::c_long) as isize),
            );
            chg = (chg as libc::c_uint != 0
                || *y.offset((n - 1 as libc::c_int as libc::c_long) as isize)
                    != *x.offset((n - 1 as libc::c_int as libc::c_long) as isize))
                as libc::c_int as Rboolean
        }
        _ => {
            error(
                dcgettext(
                    b"stats\x00" as *const u8 as *const libc::c_char,
                    b"invalid end-rule for running median of 3: %d\x00" as *const u8
                        as *const libc::c_char,
                    5 as libc::c_int,
                ),
                end_rule,
            );
        }
    }
    return chg;
}
unsafe extern "C" fn sm_3R(
    mut x: *mut libc::c_double,
    mut y: *mut libc::c_double,
    mut z: *mut libc::c_double,
    mut n: R_xlen_t,
    mut end_rule: libc::c_int,
) -> libc::c_int {
    /* y[] := "3R"(x) ; 3R = Median of three, repeated until convergence */
    let mut iter: libc::c_int = 0;
    let mut chg: Rboolean = FALSE;
    chg = sm_3(x, y, n, sm_COPY_ENDRULE as libc::c_int);
    iter = chg as libc::c_int;
    while chg as u64 != 0 {
        chg = sm_3(y, z, n, sm_NO_ENDRULE as libc::c_int);
        if chg as u64 != 0 {
            iter += 1;
            let mut i: R_xlen_t = 1 as libc::c_int as R_xlen_t;
            while i < n - 1 as libc::c_int as libc::c_long {
                *y.offset(i as isize) = *z.offset(i as isize);
                i += 1
            }
        }
    }
    if n > 2 as libc::c_int as libc::c_long {
        match end_rule {
            0 => {}
            1 => {
                *y.offset(0 as libc::c_int as isize) = *x.offset(0 as libc::c_int as isize);
                *y.offset((n - 1 as libc::c_int as libc::c_long) as isize) =
                    *x.offset((n - 1 as libc::c_int as libc::c_long) as isize)
            }
            2 => {
                *y.offset(0 as libc::c_int as isize) = med3(
                    3 as libc::c_int as libc::c_double * *y.offset(1 as libc::c_int as isize)
                        - 2 as libc::c_int as libc::c_double * *y.offset(2 as libc::c_int as isize),
                    *x.offset(0 as libc::c_int as isize),
                    *y.offset(1 as libc::c_int as isize),
                );
                chg = (chg as libc::c_uint != 0
                    || *y.offset(0 as libc::c_int as isize) != *x.offset(0 as libc::c_int as isize))
                    as libc::c_int as Rboolean;
                *y.offset((n - 1 as libc::c_int as libc::c_long) as isize) = med3(
                    *y.offset((n - 2 as libc::c_int as libc::c_long) as isize),
                    *x.offset((n - 1 as libc::c_int as libc::c_long) as isize),
                    3 as libc::c_int as libc::c_double
                        * *y.offset((n - 2 as libc::c_int as libc::c_long) as isize)
                        - 2 as libc::c_int as libc::c_double
                            * *y.offset((n - 3 as libc::c_int as libc::c_long) as isize),
                );
                chg = (chg as libc::c_uint != 0
                    || *y.offset((n - 1 as libc::c_int as libc::c_long) as isize)
                        != *x.offset((n - 1 as libc::c_int as libc::c_long) as isize))
                    as libc::c_int as Rboolean
            }
            _ => {
                error(
                    dcgettext(
                        b"stats\x00" as *const u8 as *const libc::c_char,
                        b"invalid end-rule for running median of 3: %d\x00" as *const u8
                            as *const libc::c_char,
                        5 as libc::c_int,
                    ),
                    end_rule,
                );
            }
        }
    }
    /* =>  chg = TRUE  iff  ends changed */
    return if iter != 0 {
        iter as libc::c_uint
    } else {
        chg as libc::c_uint
    } as libc::c_int;
    /* = 0   <==>  only one "3" w/o any change
       = 1   <==>  either ["3" w/o change + endchange]
           or   [two "3"s, 2nd w/o change  ]
    */
}
unsafe extern "C" fn sptest(mut x: *mut libc::c_double, mut i: R_xlen_t) -> Rboolean {
    /* Split test:
      Are we at a /-\ or \_/ location => split should be made ?
    */
    if *x.offset(i as isize) != *x.offset((i + 1 as libc::c_int as libc::c_long) as isize) {
        return FALSE;
    }
    if *x.offset((i - 1 as libc::c_int as libc::c_long) as isize) <= *x.offset(i as isize)
        && *x.offset((i + 1 as libc::c_int as libc::c_long) as isize)
            <= *x.offset((i + 2 as libc::c_int as libc::c_long) as isize)
        || *x.offset((i - 1 as libc::c_int as libc::c_long) as isize) >= *x.offset(i as isize)
            && *x.offset((i + 1 as libc::c_int as libc::c_long) as isize)
                >= *x.offset((i + 2 as libc::c_int as libc::c_long) as isize)
    {
        return FALSE;
    }
    /* else */
    return TRUE;
}
unsafe extern "C" fn sm_split3(
    mut x: *mut libc::c_double,
    mut y: *mut libc::c_double,
    mut n: R_xlen_t,
    mut do_ends: Rboolean,
) -> Rboolean {
    /* y[] := S(x[])  where S() = "sm_split3"  */
    let mut i: R_xlen_t = 0;
    let mut chg: Rboolean = FALSE;
    i = 0 as libc::c_int as R_xlen_t;
    while i < n {
        *y.offset(i as isize) = *x.offset(i as isize);
        i += 1
    }
    if n <= 4 as libc::c_int as libc::c_long {
        return FALSE;
    }
    /* Colin Goodall doesn't do splits near ends
    in spl() in Statlib's "smoother" code !! */
    if do_ends as libc::c_uint != 0 && sptest(x, 1 as libc::c_int as R_xlen_t) as libc::c_uint != 0
    {
        chg = TRUE;
        *y.offset(1 as libc::c_int as isize) = *x.offset(0 as libc::c_int as isize);
        *y.offset(2 as libc::c_int as isize) = med3(
            *x.offset(2 as libc::c_int as isize),
            *x.offset(3 as libc::c_int as isize),
            3 as libc::c_int as libc::c_double * *x.offset(3 as libc::c_int as isize)
                - 2 as libc::c_int as libc::c_double * *x.offset(4 as libc::c_int as isize),
        )
    }
    i = 2 as libc::c_int as R_xlen_t;
    while i < n - 3 as libc::c_int as libc::c_long {
        if sptest(x, i) as u64 != 0 {
            /* plateau at x[i] == x[i+1] */
            let mut j: libc::c_int = 0;
            /* at left : */
            j = imed3(
                *x.offset(i as isize),
                *x.offset((i - 1 as libc::c_int as libc::c_long) as isize),
                3 as libc::c_int as libc::c_double
                    * *x.offset((i - 1 as libc::c_int as libc::c_long) as isize)
                    - 2 as libc::c_int as libc::c_double
                        * *x.offset((i - 2 as libc::c_int as libc::c_long) as isize),
            );
            if (-(1 as libc::c_int)) < j {
                *y.offset(i as isize) = if j == 0 as libc::c_int {
                    *x.offset((i - 1 as libc::c_int as libc::c_long) as isize)
                } else {
                    (3 as libc::c_int as libc::c_double
                        * *x.offset((i - 1 as libc::c_int as libc::c_long) as isize))
                        - 2 as libc::c_int as libc::c_double
                            * *x.offset((i - 2 as libc::c_int as libc::c_long) as isize)
                };
                chg = (*y.offset(i as isize) != *x.offset(i as isize)) as libc::c_int as Rboolean
            }
            /* at right : */
            j = imed3(
                *x.offset((i + 1 as libc::c_int as libc::c_long) as isize),
                *x.offset((i + 2 as libc::c_int as libc::c_long) as isize),
                3 as libc::c_int as libc::c_double
                    * *x.offset((i + 2 as libc::c_int as libc::c_long) as isize)
                    - 2 as libc::c_int as libc::c_double
                        * *x.offset((i + 3 as libc::c_int as libc::c_long) as isize),
            );
            if (-(1 as libc::c_int)) < j {
                *y.offset((i + 1 as libc::c_int as libc::c_long) as isize) =
                    if j == 0 as libc::c_int {
                        *x.offset((i + 2 as libc::c_int as libc::c_long) as isize)
                    } else {
                        (3 as libc::c_int as libc::c_double
                            * *x.offset((i + 2 as libc::c_int as libc::c_long) as isize))
                            - 2 as libc::c_int as libc::c_double
                                * *x.offset((i + 3 as libc::c_int as libc::c_long) as isize)
                    };
                chg = (*y.offset((i + 1 as libc::c_int as libc::c_long) as isize)
                    != *x.offset((i + 1 as libc::c_int as libc::c_long) as isize))
                    as libc::c_int as Rboolean
            }
        }
        i += 1
    }
    if do_ends as libc::c_uint != 0
        && sptest(x, n - 3 as libc::c_int as libc::c_long) as libc::c_uint != 0
    {
        chg = TRUE;
        *y.offset((n - 2 as libc::c_int as libc::c_long) as isize) =
            *x.offset((n - 1 as libc::c_int as libc::c_long) as isize);
        *y.offset((n - 3 as libc::c_int as libc::c_long) as isize) = med3(
            *x.offset((n - 3 as libc::c_int as libc::c_long) as isize),
            *x.offset((n - 4 as libc::c_int as libc::c_long) as isize),
            3 as libc::c_int as libc::c_double
                * *x.offset((n - 4 as libc::c_int as libc::c_long) as isize)
                - 2 as libc::c_int as libc::c_double
                    * *x.offset((n - 5 as libc::c_int as libc::c_long) as isize),
        )
    }
    return chg;
}
unsafe extern "C" fn sm_3RS3R(
    mut x: *mut libc::c_double,
    mut y: *mut libc::c_double,
    mut z: *mut libc::c_double,
    mut w: *mut libc::c_double,
    mut n: R_xlen_t,
    mut end_rule: libc::c_int,
    mut split_ends: Rboolean,
) -> libc::c_int {
    /* y[1:n] := "3R S 3R"(x[1:n]);  z = "work"; */
    let mut iter: libc::c_int = 0;
    let mut chg: Rboolean = FALSE;
    iter = sm_3R(x, y, z, n, end_rule);
    chg = sm_split3(y, z, n, split_ends);
    if chg as u64 != 0 {
        iter += sm_3R(z, y, w, n, end_rule)
    }
    /* else y == z already */
    return iter + chg as libc::c_int;
}
unsafe extern "C" fn sm_3RSS(
    mut x: *mut libc::c_double,
    mut y: *mut libc::c_double,
    mut z: *mut libc::c_double,
    mut n: R_xlen_t,
    mut end_rule: libc::c_int,
    mut split_ends: Rboolean,
) -> libc::c_int {
    /* y[1:n] := "3RSS"(x[1:n]);  z = "work"; */
    let mut iter: libc::c_int = 0;
    let mut chg: Rboolean = FALSE;
    iter = sm_3R(x, y, z, n, end_rule);
    chg = sm_split3(y, z, n, split_ends);
    if chg as u64 != 0 {
        sm_split3(z, y, n, split_ends);
    }
    /* else  y == z already */
    return iter + chg as libc::c_int;
}
unsafe extern "C" fn sm_3RSR(
    mut x: *mut libc::c_double,
    mut y: *mut libc::c_double,
    mut z: *mut libc::c_double,
    mut w: *mut libc::c_double,
    mut n: R_xlen_t,
    mut end_rule: libc::c_int,
    mut split_ends: Rboolean,
) -> libc::c_int {
    /* y[1:n] := "3RSR"(x[1:n]);  z := residuals; w = "work"; */
    /*== "SR" (as follows) is stupid ! (MM) ==*/
    let mut i: R_xlen_t = 0; /* INF.LOOP stopper */
    let mut iter: libc::c_int = 0;
    let mut chg: Rboolean = FALSE;
    let mut ch2: Rboolean = FALSE;
    iter = sm_3R(x, y, z, n, end_rule);
    loop {
        iter += 1;
        chg = sm_split3(y, z, n, split_ends);
        ch2 = sm_3R(z, y, w, n, end_rule) as Rboolean;
        chg = (chg as libc::c_uint != 0 || ch2 as libc::c_uint != 0) as libc::c_int as Rboolean;
        if chg as u64 == 0 {
            break;
        }
        if iter as libc::c_long > 2 as libc::c_int as libc::c_long * n {
            break;
        }
        i = 0 as libc::c_int as R_xlen_t;
        while i < n {
            *z.offset(i as isize) = *x.offset(i as isize) - *y.offset(i as isize);
            i += 1
        }
        if !(chg as u64 != 0) {
            break;
        }
    }
    return iter;
}
/*-------- These are  called from R : -----------*/
#[no_mangle]
pub unsafe extern "C" fn Rsm(mut x: SEXP, mut stype: SEXP, mut send: SEXP) -> SEXP {
    let mut iend: libc::c_int = asInteger(send);
    let mut type_0: libc::c_int = asInteger(stype);
    let mut n: R_xlen_t = XLENGTH(x);
    let mut ans: SEXP = protect(allocVector(
        19 as libc::c_int as SEXPTYPE,
        2 as libc::c_int as R_xlen_t,
    ));
    let mut y: SEXP = allocVector(14 as libc::c_int as SEXPTYPE, n);
    SET_VECTOR_ELT(ans, 0 as libc::c_int as R_xlen_t, y);
    let mut nm: SEXP = allocVector(16 as libc::c_int as SEXPTYPE, 2 as libc::c_int as R_xlen_t);
    setAttrib(ans, R_NamesSymbol, nm);
    SET_STRING_ELT(
        nm,
        0 as libc::c_int as R_xlen_t,
        mkChar(b"y\x00" as *const u8 as *const libc::c_char),
    );
    if type_0 <= 5 as libc::c_int {
        /* -Wall */
        let mut iter: libc::c_int = 0 as libc::c_int;
        match type_0 {
            1 => {
                let mut z: *mut libc::c_double = R_alloc(
                    n as size_t,
                    ::std::mem::size_of::<libc::c_double>() as libc::c_ulong as libc::c_int,
                ) as *mut libc::c_double;
                let mut w: *mut libc::c_double = R_alloc(
                    n as size_t,
                    ::std::mem::size_of::<libc::c_double>() as libc::c_ulong as libc::c_int,
                ) as *mut libc::c_double;
                iter = sm_3RS3R(
                    REAL(x),
                    REAL(y),
                    z,
                    w,
                    n,
                    iend.abs(),
                    if iend < 0 as libc::c_int {
                        TRUE as libc::c_int
                    } else {
                        FALSE as libc::c_int
                    } as Rboolean,
                )
            }
            2 => {
                let mut z_0: *mut libc::c_double = R_alloc(
                    n as size_t,
                    ::std::mem::size_of::<libc::c_double>() as libc::c_ulong as libc::c_int,
                ) as *mut libc::c_double;
                iter = sm_3RSS(
                    REAL(x),
                    REAL(y),
                    z_0,
                    n,
                    iend.abs(),
                    if iend < 0 as libc::c_int {
                        TRUE as libc::c_int
                    } else {
                        FALSE as libc::c_int
                    } as Rboolean,
                )
            }
            3 => {
                let mut z_1: *mut libc::c_double = R_alloc(
                    n as size_t,
                    ::std::mem::size_of::<libc::c_double>() as libc::c_ulong as libc::c_int,
                ) as *mut libc::c_double;
                let mut w_0: *mut libc::c_double = R_alloc(
                    n as size_t,
                    ::std::mem::size_of::<libc::c_double>() as libc::c_ulong as libc::c_int,
                ) as *mut libc::c_double;
                iter = sm_3RSR(
                    REAL(x),
                    REAL(y),
                    z_1,
                    w_0,
                    n,
                    iend.abs(),
                    if iend < 0 as libc::c_int {
                        TRUE as libc::c_int
                    } else {
                        FALSE as libc::c_int
                    } as Rboolean,
                )
            }
            4 => {
                // "3R"
                let mut z_2: *mut libc::c_double = R_alloc(
                    n as size_t,
                    ::std::mem::size_of::<libc::c_double>() as libc::c_ulong as libc::c_int,
                ) as *mut libc::c_double;
                iter = sm_3R(REAL(x), REAL(y), z_2, n, iend)
            }
            5 => {
                // "3"
                iter = sm_3(REAL(x), REAL(y), n, iend) as libc::c_int
            }
            _ => {}
        }
        SET_VECTOR_ELT(ans, 1 as libc::c_int as R_xlen_t, ScalarInteger(iter));
        SET_STRING_ELT(
            nm,
            1 as libc::c_int as R_xlen_t,
            mkChar(b"iter\x00" as *const u8 as *const libc::c_char),
        );
    } else {
        let mut changed: libc::c_int =
            sm_split3(REAL(x), REAL(y), n, iend as Rboolean) as libc::c_int;
        SET_VECTOR_ELT(ans, 1 as libc::c_int as R_xlen_t, ScalarLogical(changed));
        SET_STRING_ELT(
            nm,
            1 as libc::c_int as R_xlen_t,
            mkChar(b"changed\x00" as *const u8 as *const libc::c_char),
        );
    }
    unprotect(1 as libc::c_int);
    return ans;
}