#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ memcpy(double *, double *, int);
double moment1(int, double *);
double sqrt(double);
double stub1(int, double *);
double stub2(int, double *);
int /*<<< orphan*/ swapvalues(int, int, double *);
double tss_m(double *, int, int, double);
double *xmalloc(int);
double jackknife(int datalength, double *data, double *jack_error, int funcargs,
                 double functoest(double *), double (*fun[])(int, double *)) {
  double *datajack = xmalloc(datalength * sizeof(double));
  double jackknife_est;
  double *arguments = xmalloc(funcargs * sizeof(double));
  double fjotesmean;
  double *fjotes = xmalloc(datalength * sizeof(double));
  int i, j;
  memcpy(datajack, data, datalength * sizeof(double));
  for (i = 0; i < datalength; ++i) {
    for (j = 0; j < funcargs; ++j) {
      arguments[j] = fun[j](datalength - 1, datajack);
    }
    fjotes[i] = functoest(arguments);
    swapvalues(i, datalength - 1, datajack);
  }
  for (j = 0; j < funcargs; ++j) {
    arguments[j] = fun[j](datalength, datajack);
  }
  fjotesmean = moment1(datalength, fjotes);
  jackknife_est =
      datalength * functoest(arguments) - (datalength - 1) * fjotesmean;
  if (jack_error != NULL) {
    *jack_error = sqrt((double)(datalength - 1) / datalength *
                       tss_m(fjotes, 1, datalength, fjotesmean));
  }
  free(datajack);
  free(arguments);
  free(fjotes);
  return jackknife_est;
}


x86 assembly (clang, -O0):
<jackknife>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x38(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x48(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    126e <jackknife+0xfe>
movl   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1237 <jackknife+0xc7>
mov    -0x30(%rbp),%rax
movslq -0x60(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x4(%rbp),%edi
sub    $0x1,%edi
mov    -0x38(%rbp),%rsi
call   *%rax
mov    -0x48(%rbp),%rax
movslq -0x60(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    11f8 <jackknife+0x88>
mov    -0x28(%rbp),%rax
mov    -0x48(%rbp),%rdi
call   *%rax
mov    -0x58(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x5c(%rbp),%edi
mov    -0x4(%rbp),%esi
sub    $0x1,%esi
mov    -0x38(%rbp),%rdx
call   1070 <swapvalues@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    11e5 <jackknife+0x75>
movl   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12b1 <jackknife+0x141>
mov    -0x30(%rbp),%rax
movslq -0x60(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x4(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   *%rax
mov    -0x48(%rbp),%rax
movslq -0x60(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1275 <jackknife+0x105>
mov    -0x4(%rbp),%edi
mov    -0x58(%rbp),%rsi
call   1080 <moment1@plt>
movsd  %xmm0,-0x50(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x48(%rbp),%rdi
call   *%rax
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  -0x50(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1363 <jackknife+0x1f3>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x4(%rbp),%edx
movsd  -0x50(%rbp),%xmm0
mov    $0x1,%esi
call   1050 <tss_m@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1090 <sqrt@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x40(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jackknife>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r9,0x20(%rsp)
mov    %r8,0x28(%rsp)
mov    %ecx,%r12d
mov    %rdx,0x48(%rsp)
mov    %rsi,%r13
mov    %edi,%ebx
lea    0x0(,%rbx,8),%ebp
mov    %ebp,%edi
call   1040 <xmalloc@plt>
mov    %rax,%r15
lea    0x0(,%r12,8),%edi
call   1040 <xmalloc@plt>
mov    %rax,0x40(%rsp)
mov    %ebp,%edi
call   1040 <xmalloc@plt>
mov    %rax,0x38(%rsp)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1060 <memcpy@plt>
mov    %r12,0x10(%rsp)
mov    %r12d,%eax
mov    %rax,0x18(%rsp)
mov    %rbx,0x30(%rsp)
test   %ebx,%ebx
jle    127b <jackknife+0x10b>
mov    0x30(%rsp),%rax
lea    -0x1(%rax),%ebx
mov    %eax,%eax
mov    %rax,0x50(%rsp)
xor    %r14d,%r14d
mov    0x40(%rsp),%r13
mov    0x20(%rsp),%r12
jmp    1242 <jackknife+0xd2>
nopl   0x0(%rax)
mov    %r13,%rdi
call   *0x28(%rsp)
mov    0x38(%rsp),%rax
mov    0x8(%rsp),%r14
movsd  %xmm0,(%rax,%r14,8)
mov    %r14d,%edi
mov    %ebx,%esi
mov    %rbp,%rdx
call   1070 <swapvalues@plt>
add    $0x1,%r14
cmp    0x50(%rsp),%r14
mov    %rbp,%r15
je     127b <jackknife+0x10b>
mov    %r14,0x8(%rsp)
cmpl   $0x0,0x10(%rsp)
mov    %r15,%rbp
mov    0x18(%rsp),%r14
jle    1210 <jackknife+0xa0>
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %rbp,%rsi
call   *(%r12,%r15,8)
movsd  %xmm0,0x0(%r13,%r15,8)
add    $0x1,%r15
cmp    %r15,%r14
jne    1260 <jackknife+0xf0>
jmp    1210 <jackknife+0xa0>
cmpl   $0x0,0x10(%rsp)
mov    0x40(%rsp),%r13
mov    0x30(%rsp),%r14
mov    0x20(%rsp),%r12
mov    0x18(%rsp),%rbx
jle    12ba <jackknife+0x14a>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %r15,%rsi
call   *(%r12,%rbp,8)
movsd  %xmm0,0x0(%r13,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    12a0 <jackknife+0x130>
mov    %r14d,%edi
mov    0x38(%rsp),%rbx
mov    %rbx,%rsi
call   1080 <moment1@plt>
movsd  %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r13,%rdi
call   *0x28(%rsp)
movsd  0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
lea    -0x1(%r14),%eax
cvtsi2sd %eax,%xmm3
mov    0x48(%rsp),%rbp
test   %rbp,%rbp
je     1365 <jackknife+0x1f5>
movsd  %xmm0,0x28(%rsp)
movsd  %xmm3,0x20(%rsp)
divsd  %xmm1,%xmm3
movsd  %xmm3,0x18(%rsp)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
movapd %xmm2,%xmm0
call   1050 <tss_m@plt>
mulsd  0x18(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1343 <jackknife+0x1d3>
sqrtsd %xmm0,%xmm0
jmp    1348 <jackknife+0x1d8>
call   1090 <sqrt@plt>
movsd  %xmm0,0x0(%rbp)
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
movsd  0x28(%rsp),%xmm0
movsd  0x20(%rsp),%xmm3
mulsd  %xmm2,%xmm3
mulsd  %xmm0,%xmm1
subsd  %xmm3,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @jackknife(i32 %0, double* %1, double* %2, i32 %3, double (double*)* %4, double (i32, double*)** %5) {
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca double (double*)*
%12 = alloca double (i32, double*)**
%13 = alloca double*
%14 = alloca double
%15 = alloca double*
%16 = alloca double
%17 = alloca double*
%18 = alloca i32
%19 = alloca i32
store i32 %0, i32* %7
store double* %1, double** %8
store double* %2, double** %9
store i32 %3, i32* %10
store double (double*)* %4, double (double*)** %11
store double (i32, double*)** %5, double (i32, double*)*** %12
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 8
%23 = trunc i64 %22 to i32
%24 = call double* @xmalloc(i32 %23)
store double* %24, double** %13
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 8
%28 = trunc i64 %27 to i32
%29 = call double* @xmalloc(i32 %28)
store double* %29, double** %15
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 8
%33 = trunc i64 %32 to i32
%34 = call double* @xmalloc(i32 %33)
store double* %34, double** %17
%35 = load double*, double** %13
%36 = load double*, double** %8
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = mul i64 %38, 8
%40 = trunc i64 %39 to i32
%41 = call i32 @memcpy(double* %35, double* %36, i32 %40)
store i32 0, i32* %18
br label %42
42: ; preds = %81, %6
%43 = load i32, i32* %18
%44 = load i32, i32* %7
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %84
46: ; preds = %42
store i32 0, i32* %19
br label %47
47: ; preds = %65, %46
%48 = load i32, i32* %19
%49 = load i32, i32* %10
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %68
51: ; preds = %47
%52 = load double (i32, double*)**, double (i32, double*)*** %12
%53 = load i32, i32* %19
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double (i32, double*)*, double (i32, double*)** %52, i64 %54
%56 = load double (i32, double*)*, double (i32, double*)** %55
%57 = load i32, i32* %7
%58 = sub nsw i32 %57, 1
%59 = load double*, double** %13
%60 = call double %56(i32 %58, double* %59)
%61 = load double*, double** %15
%62 = load i32, i32* %19
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
store double %60, double* %64
br label %65
65: ; preds = %51
%66 = load i32, i32* %19
%67 = add nsw i32 %66, 1
store i32 %67, i32* %19
br label %47
68: ; preds = %47
%69 = load double (double*)*, double (double*)** %11
%70 = load double*, double** %15
%71 = call double %69(double* %70)
%72 = load double*, double** %17
%73 = load i32, i32* %18
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds double, double* %72, i64 %74
store double %71, double* %75
%76 = load i32, i32* %18
%77 = load i32, i32* %7
%78 = sub nsw i32 %77, 1
%79 = load double*, double** %13
%80 = call i32 @swapvalues(i32 %76, i32 %78, double* %79)
br label %81
81: ; preds = %68
%82 = load i32, i32* %18
%83 = add nsw i32 %82, 1
store i32 %83, i32* %18
br label %42
84: ; preds = %42
store i32 0, i32* %19
br label %85
85: ; preds = %102, %84
%86 = load i32, i32* %19
%87 = load i32, i32* %10
%88 = icmp slt i32 %86, %87
br i1 %88, label %89, label %105
89: ; preds = %85
%90 = load double (i32, double*)**, double (i32, double*)*** %12
%91 = load i32, i32* %19
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds double (i32, double*)*, double (i32, double*)** %90, i64 %92
%94 = load double (i32, double*)*, double (i32, double*)** %93
%95 = load i32, i32* %7
%96 = load double*, double** %13
%97 = call double %94(i32 %95, double* %96)
%98 = load double*, double** %15
%99 = load i32, i32* %19
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds double, double* %98, i64 %100
store double %97, double* %101
br label %102
102: ; preds = %89
%103 = load i32, i32* %19
%104 = add nsw i32 %103, 1
store i32 %104, i32* %19
br label %85
105: ; preds = %85
%106 = load i32, i32* %7
%107 = load double*, double** %17
%108 = call double @moment1(i32 %106, double* %107)
store double %108, double* %16
%109 = load i32, i32* %7
%110 = sitofp i32 %109 to double
%111 = load double (double*)*, double (double*)** %11
%112 = load double*, double** %15
%113 = call double %111(double* %112)
%114 = load i32, i32* %7
%115 = sub nsw i32 %114, 1
%116 = sitofp i32 %115 to double
%117 = load double, double* %16
%118 = fmul double %116, %117
%119 = fneg double %118
%120 = call double @llvm.fmuladd.f64(double %110, double %113, double %119)
store double %120, double* %14
%121 = load double*, double** %9
%122 = icmp ne double* %121, null
br i1 %122, label %123, label %137
123: ; preds = %105
%124 = load i32, i32* %7
%125 = sub nsw i32 %124, 1
%126 = sitofp i32 %125 to double
%127 = load i32, i32* %7
%128 = sitofp i32 %127 to double
%129 = fdiv double %126, %128
%130 = load double*, double** %17
%131 = load i32, i32* %7
%132 = load double, double* %16
%133 = call double @tss_m(double* %130, i32 1, i32 %131, double %132)
%134 = fmul double %129, %133
%135 = call double @sqrt(double %134)
%136 = load double*, double** %9
store double %135, double* %136
br label %137
137: ; preds = %123, %105
%138 = load double*, double** %13
%139 = call i32 @free(double* %138)
%140 = load double*, double** %15
%141 = call i32 @free(double* %140)
%142 = load double*, double** %17
%143 = call i32 @free(double* %142)
%144 = load double, double* %14
ret double %144
}

LLVM IR (-O2):
define double @jackknife(i32 %0, double* %1, double* writeonly %2, i32 %3, double (double*)* nocapture %4, double (i32, double*)** nocapture %5) {
%7 = shl i32 %0, 3
%8 = tail call double* @xmalloc(i32 %7)
%9 = shl i32 %3, 3
%10 = tail call double* @xmalloc(i32 %9)
%11 = tail call double* @xmalloc(i32 %7)
%12 = tail call i32 @memcpy(double* %8, double* %1, i32 %7)
%13 = icmp sgt i32 %0, 0
br i1 %13, label %14, label %21
14: ; preds = %6
%15 = icmp sgt i32 %3, 0
%16 = add nsw i32 %0, -1
%17 = zext i32 %0 to i64
%18 = zext i32 %3 to i64
br label %19
19: ; preds = %14, %33
%20 = phi i64 [ 0, %14 ], [ %38, %33 ]
br i1 %15, label %25, label %33
21: ; preds = %33, %6
%22 = icmp sgt i32 %3, 0
br i1 %22, label %23, label %48
23: ; preds = %21
%24 = zext i32 %3 to i64
br label %40
25: ; preds = %19, %25
%26 = phi i64 [ %31, %25 ], [ 0, %19 ]
%27 = getelementptr inbounds double (i32, double*)*, double (i32, double*)** %5, i64 %26
%28 = load double (i32, double*)*, double (i32, double*)** %27
%29 = tail call double %28(i32 %16, double* %8)
%30 = getelementptr inbounds double, double* %10, i64 %26
store double %29, double* %30
%31 = add nuw nsw i64 %26, 1
%32 = icmp eq i64 %31, %18
br i1 %32, label %33, label %25
33: ; preds = %25, %19
%34 = tail call double %4(double* %10)
%35 = getelementptr inbounds double, double* %11, i64 %20
store double %34, double* %35
%36 = trunc i64 %20 to i32
%37 = tail call i32 @swapvalues(i32 %36, i32 %16, double* %8)
%38 = add nuw nsw i64 %20, 1
%39 = icmp eq i64 %38, %17
br i1 %39, label %21, label %19
40: ; preds = %23, %40
%41 = phi i64 [ 0, %23 ], [ %46, %40 ]
%42 = getelementptr inbounds double (i32, double*)*, double (i32, double*)** %5, i64 %41
%43 = load double (i32, double*)*, double (i32, double*)** %42
%44 = tail call double %43(i32 %0, double* %8)
%45 = getelementptr inbounds double, double* %10, i64 %41
store double %44, double* %45
%46 = add nuw nsw i64 %41, 1
%47 = icmp eq i64 %46, %24
br i1 %47, label %48, label %40
48: ; preds = %40, %21
%49 = tail call double @moment1(i32 %0, double* %11)
%50 = sitofp i32 %0 to double
%51 = tail call double %4(double* %10)
%52 = add nsw i32 %0, -1
%53 = sitofp i32 %52 to double
%54 = icmp eq double* %2, null
br i1 %54, label %60, label %55
55: ; preds = %48
%56 = fdiv double %53, %50
%57 = tail call double @tss_m(double* %11, i32 1, i32 %0, double %49)
%58 = fmul double %56, %57
%59 = tail call double @sqrt(double %58)
store double %59, double* %2
br label %60
60: ; preds = %55, %48
%61 = fneg double %49
%62 = fmul double %53, %61
%63 = tail call double @llvm.fmuladd.f64(double %50, double %51, double %62)
%64 = tail call i32 @free(double* %8)
%65 = tail call i32 @free(double* %10)
%66 = tail call i32 @free(double* %11)
ret double %63
}