use crate::sexprec::{SEXP, SEXPTYPE};
use ::libc;
extern "C" {
#[no_mangle]
fn memset(_: *mut libc::c_void, _: libc::c_int, _: libc::c_ulong) -> *mut libc::c_void;
#[no_mangle]
fn memcpy(_: *mut libc::c_void, _: *const libc::c_void, _: libc::c_ulong) -> *mut libc::c_void;
#[no_mangle]
fn LENGTH(x: SEXP) -> libc::c_int;
#[no_mangle]
fn REAL(x: SEXP) -> *mut libc::c_double;
#[no_mangle]
fn coerceVector(_: SEXP, _: SEXPTYPE) -> SEXP;
#[no_mangle]
fn asInteger(x: SEXP) -> libc::c_int;
#[no_mangle]
fn allocVector(_: SEXPTYPE, _: R_xlen_t) -> SEXP;
#[no_mangle]
fn ScalarReal(_: libc::c_double) -> SEXP;
#[no_mangle]
fn protect(_: SEXP) -> SEXP;
#[no_mangle]
fn unprotect(_: libc::c_int);
}
pub type size_t = libc::c_ulong;
pub type ptrdiff_t = libc::c_long;
pub type R_xlen_t = ptrdiff_t;
unsafe extern "C" fn R_pp_sum(
mut u: *mut libc::c_double,
mut n: libc::c_int,
mut l: libc::c_int,
) -> libc::c_double {
let mut tmp1: libc::c_double = 0.;
let mut tmp2: libc::c_double = 0.;
tmp1 = 0.0f64;
let mut i: libc::c_int = 1 as libc::c_int;
while i <= l {
tmp2 = 0.0f64;
let mut j: libc::c_int = i;
while j < n {
tmp2 += *u.offset(j as isize) * *u.offset((j - i) as isize);
j += 1
}
tmp2 *= 1.0f64 - i as libc::c_double / (l as libc::c_double + 1.0f64);
tmp1 += tmp2;
i += 1
}
return 2.0f64 * tmp1 / n as libc::c_double;
}
#[no_mangle]
pub unsafe extern "C" fn pp_sum(mut u: SEXP, mut sl: SEXP) -> SEXP {
u = protect(coerceVector(u, 14 as libc::c_int as SEXPTYPE));
let mut n: libc::c_int = LENGTH(u);
let mut l: libc::c_int = asInteger(sl);
let mut trm: libc::c_double = R_pp_sum(REAL(u), n, l);
unprotect(1 as libc::c_int);
return ScalarReal(trm);
}
#[no_mangle]
pub unsafe extern "C" fn intgrt_vec(mut x: SEXP, mut xi: SEXP, mut slag: SEXP) -> SEXP {
x = protect(coerceVector(x, 14 as libc::c_int as SEXPTYPE));
xi = protect(coerceVector(xi, 14 as libc::c_int as SEXPTYPE));
let mut n: libc::c_int = LENGTH(x);
let mut lag: libc::c_int = asInteger(slag);
let mut ans: SEXP = protect(allocVector(
14 as libc::c_int as SEXPTYPE,
(n + lag) as R_xlen_t,
));
let mut rx: *mut libc::c_double = REAL(x);
let mut y: *mut libc::c_double = REAL(ans);
memset(
y as *mut libc::c_void,
0 as libc::c_int,
((n + lag) as size_t)
.wrapping_mul(::std::mem::size_of::<libc::c_double>() as libc::c_ulong),
);
memcpy(
y as *mut libc::c_void,
REAL(xi) as *const libc::c_void,
(lag as size_t).wrapping_mul(::std::mem::size_of::<libc::c_double>() as libc::c_ulong),
);
let mut i: libc::c_int = lag;
while i < lag + n {
*y.offset(i as isize) = *rx.offset((i - lag) as isize) + *y.offset((i - lag) as isize);
i += 1
}
unprotect(3 as libc::c_int);
return ans;
}