#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fatalx(char *, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ weightjackx(double *, double *, double, double *, double *,
                               int);
void weightjack(double *est, double *sig, double mean, double *jmean,
                double *jwt, int g) {
  double *jjmean, *jjwt;
  int i, n;
  if ((jjmean = (double *)calloc((g), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", g);
  if ((jjwt = (double *)calloc((g), sizeof(double))) == NULL)
    fatalx("Unable to allocate %d unit(s) for item \n", g);
  n = 0;
  for (i = 0; i < g; ++i) {
    if (jwt[i] < 1.0e-6)
      continue;
    jjmean[n] = jmean[i];
    jjwt[n] = jwt[i];
    ++n;
  }
  weightjackx(est, sig, mean, jjmean, jjwt, n);
  free(jjmean);
  free(jjwt);
}


x86 assembly (clang, -O0):
<weightjack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    118b <weightjack+0x4b>
mov    -0x2c(%rbp),%esi
lea    0xe82(%rip),%rdi
call   1040 <fatalx@plt>
mov    -0x2c(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11b5 <weightjack+0x75>
mov    -0x2c(%rbp),%esi
lea    0xe58(%rip),%rdi
call   1040 <fatalx@plt>
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    123a <weightjack+0xfa>
mov    -0x28(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  0xe21(%rip),%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    11ef <weightjack+0xaf>
jmp    122c <weightjack+0xec>
mov    -0x20(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x40(%rbp),%rax
movslq -0x48(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11c3 <weightjack+0x83>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movsd  -0x18(%rbp),%xmm0
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8d
call   1060 <weightjackx@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<weightjack>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r14d
mov    %rcx,%rbx
mov    %rdx,%rbp
movsd  %xmm0,0x10(%rsp)
mov    %rsi,%r15
mov    %rdi,0x8(%rsp)
mov    %r8d,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1189 <weightjack+0x49>
lea    0xe87(%rip),%rdi
mov    %r14d,%esi
call   1040 <fatalx@plt>
mov    %r14d,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%r13
test   %rax,%rax
je     11f8 <weightjack+0xb8>
test   %r14d,%r14d
jle    120c <weightjack+0xcc>
mov    %r14d,%ecx
cmp    $0x1,%r14d
jne    1246 <weightjack+0x106>
xor    %eax,%eax
xor    %r8d,%r8d
movsd  0x10(%rsp),%xmm0
mov    %r15,%rsi
mov    0x8(%rsp),%rdi
test   $0x1,%cl
je     121d <weightjack+0xdd>
movsd  0xe30(%rip),%xmm1
ucomisd (%rbx,%rax,8),%xmm1
ja     121d <weightjack+0xdd>
movsd  0x0(%rbp,%rax,8),%xmm1
movslq %r8d,%r8
movsd  %xmm1,(%r12,%r8,8)
movsd  (%rbx,%rax,8),%xmm1
movsd  %xmm1,0x0(%r13,%r8,8)
add    $0x1,%r8d
jmp    121d <weightjack+0xdd>
lea    0xe09(%rip),%rdi
mov    %r14d,%esi
call   1040 <fatalx@plt>
test   %r14d,%r14d
jg     11a3 <weightjack+0x63>
xor    %r8d,%r8d
movsd  0x10(%rsp),%xmm0
mov    %r15,%rsi
mov    0x8(%rsp),%rdi
mov    %r12,%rdx
mov    %r13,%rcx
call   1060 <weightjackx@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    %ecx,%edx
and    $0xfffffffe,%edx
xor    %eax,%eax
movsd  0xdab(%rip),%xmm2
xor    %r8d,%r8d
movsd  0x10(%rsp),%xmm0
mov    %r15,%rsi
mov    0x8(%rsp),%rdi
jmp    127d <weightjack+0x13d>
nopl   0x0(%rax,%rax,1)
add    $0x2,%rax
cmp    %rax,%rdx
je     11c3 <weightjack+0x83>
ucomisd (%rbx,%rax,8),%xmm2
ja     12a3 <weightjack+0x163>
movsd  0x0(%rbp,%rax,8),%xmm1
movslq %r8d,%r8
movsd  %xmm1,(%r12,%r8,8)
movsd  (%rbx,%rax,8),%xmm1
movsd  %xmm1,0x0(%r13,%r8,8)
add    $0x1,%r8d
ucomisd 0x8(%rbx,%rax,8),%xmm2
ja     1270 <weightjack+0x130>
movsd  0x8(%rbp,%rax,8),%xmm1
movslq %r8d,%r8
movsd  %xmm1,(%r12,%r8,8)
movsd  0x8(%rbx,%rax,8),%xmm1
movsd  %xmm1,0x0(%r13,%r8,8)
add    $0x1,%r8d
jmp    1270 <weightjack+0x130>

LLVM IR (-O0):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define void @weightjack(double* %0, double* %1, double %2, double* %3, double* %4, i32 %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca double
%10 = alloca double*
%11 = alloca double*
%12 = alloca i32
%13 = alloca double*
%14 = alloca double*
%15 = alloca i32
%16 = alloca i32
store double* %0, double** %7
store double* %1, double** %8
store double %2, double* %9
store double* %3, double** %10
store double* %4, double** %11
store i32 %5, i32* %12
%17 = load i32, i32* %12
%18 = call i64 @calloc(i32 %17, i32 8)
%19 = inttoptr i64 %18 to double*
store double* %19, double** %13
%20 = icmp eq double* %19, null
br i1 %20, label %21, label %24
21: ; preds = %6
%22 = load i32, i32* %12
%23 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %6
%25 = load i32, i32* %12
%26 = call i64 @calloc(i32 %25, i32 8)
%27 = inttoptr i64 %26 to double*
store double* %27, double** %14
%28 = icmp eq double* %27, null
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* %12
%31 = call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %29, %24
store i32 0, i32* %16
store i32 0, i32* %15
br label %33
33: ; preds = %66, %32
%34 = load i32, i32* %15
%35 = load i32, i32* %12
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %69
37: ; preds = %33
%38 = load double*, double** %11
%39 = load i32, i32* %15
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = fcmp olt double %42, 0x3EB0C6F7A0B5ED8D
br i1 %43, label %44, label %45
44: ; preds = %37
br label %66
45: ; preds = %37
%46 = load double*, double** %10
%47 = load i32, i32* %15
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = load double*, double** %13
%52 = load i32, i32* %16
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
store double %50, double* %54
%55 = load double*, double** %11
%56 = load i32, i32* %15
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
%60 = load double*, double** %14
%61 = load i32, i32* %16
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
store double %59, double* %63
%64 = load i32, i32* %16
%65 = add nsw i32 %64, 1
store i32 %65, i32* %16
br label %66
66: ; preds = %45, %44
%67 = load i32, i32* %15
%68 = add nsw i32 %67, 1
store i32 %68, i32* %15
br label %33
69: ; preds = %33
%70 = load double*, double** %7
%71 = load double*, double** %8
%72 = load double, double* %9
%73 = load double*, double** %13
%74 = load double*, double** %14
%75 = load i32, i32* %16
%76 = call i32 @weightjackx(double* %70, double* %71, double %72, double* %73, double* %74, i32 %75)
%77 = load double*, double** %13
%78 = call i32 @free(double* %77)
%79 = load double*, double** %14
%80 = call i32 @free(double* %79)
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"Unable to allocate %d unit(s) for item \0A\00"
define void @weightjack(double* %0, double* %1, double %2, double* nocapture %3, double* nocapture %4, i32 %5) {
%7 = tail call i64 @calloc(i32 %5, i32 8)
%8 = inttoptr i64 %7 to double*
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %12
12: ; preds = %10, %6
%13 = tail call i64 @calloc(i32 %5, i32 8)
%14 = inttoptr i64 %13 to double*
%15 = icmp eq i64 %13, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @fatalx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %18
18: ; preds = %16, %12
%19 = icmp sgt i32 %5, 0
br i1 %19, label %20, label %77
20: ; preds = %18
%21 = zext i32 %5 to i64
%22 = and i64 %21, 1
%23 = icmp eq i32 %5, 1
br i1 %23, label %60, label %24
24: ; preds = %20
%25 = and i64 %21, 4294967294
br label %26
26: ; preds = %55, %24
%27 = phi i64 [ 0, %24 ], [ %57, %55 ]
%28 = phi i32 [ 0, %24 ], [ %56, %55 ]
%29 = phi i64 [ 0, %24 ], [ %58, %55 ]
%30 = getelementptr inbounds double, double* %4, i64 %27
%31 = load double, double* %30
%32 = fcmp olt double %31, 0x3EB0C6F7A0B5ED8D
br i1 %32, label %41, label %33
33: ; preds = %26
%34 = getelementptr inbounds double, double* %3, i64 %27
%35 = load double, double* %34
%36 = sext i32 %28 to i64
%37 = getelementptr inbounds double, double* %8, i64 %36
store double %35, double* %37
%38 = load double, double* %30
%39 = getelementptr inbounds double, double* %14, i64 %36
store double %38, double* %39
%40 = add nsw i32 %28, 1
br label %41
41: ; preds = %26, %33
%42 = phi i32 [ %28, %26 ], [ %40, %33 ]
%43 = or i64 %27, 1
%44 = getelementptr inbounds double, double* %4, i64 %43
%45 = load double, double* %44
%46 = fcmp olt double %45, 0x3EB0C6F7A0B5ED8D
br i1 %46, label %55, label %47
47: ; preds = %41
%48 = getelementptr inbounds double, double* %3, i64 %43
%49 = load double, double* %48
%50 = sext i32 %42 to i64
%51 = getelementptr inbounds double, double* %8, i64 %50
store double %49, double* %51
%52 = load double, double* %44
%53 = getelementptr inbounds double, double* %14, i64 %50
store double %52, double* %53
%54 = add nsw i32 %42, 1
br label %55
55: ; preds = %47, %41
%56 = phi i32 [ %42, %41 ], [ %54, %47 ]
%57 = add nuw nsw i64 %27, 2
%58 = add i64 %29, 2
%59 = icmp eq i64 %58, %25
br i1 %59, label %60, label %26
60: ; preds = %55, %20
%61 = phi i32 [ undef, %20 ], [ %56, %55 ]
%62 = phi i64 [ 0, %20 ], [ %57, %55 ]
%63 = phi i32 [ 0, %20 ], [ %56, %55 ]
%64 = icmp eq i64 %22, 0
br i1 %64, label %77, label %65
65: ; preds = %60
%66 = getelementptr inbounds double, double* %4, i64 %62
%67 = load double, double* %66
%68 = fcmp olt double %67, 0x3EB0C6F7A0B5ED8D
br i1 %68, label %77, label %69
69: ; preds = %65
%70 = getelementptr inbounds double, double* %3, i64 %62
%71 = load double, double* %70
%72 = sext i32 %63 to i64
%73 = getelementptr inbounds double, double* %8, i64 %72
store double %71, double* %73
%74 = load double, double* %66
%75 = getelementptr inbounds double, double* %14, i64 %72
store double %74, double* %75
%76 = add nsw i32 %63, 1
br label %77
77: ; preds = %60, %69, %65, %18
%78 = phi i32 [ 0, %18 ], [ %61, %60 ], [ %63, %65 ], [ %76, %69 ]
%79 = tail call i32 @weightjackx(double* %0, double* %1, double %2, double* %8, double* %14, i32 %78)
%80 = tail call i32 @free(double* %8)
%81 = tail call i32 @free(double* %14)
ret void
}