#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 */
double SplineBlend(int, int, int const *, double, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ xToZ(double const *, double *, int, int, int);
void findWeights(const double *x, const int *knots, double *weights,
                 int numSamples, int splineOrder, int numBins) {
  int curSample;
  int curBin;
  double *z = (double *)calloc(numSamples, sizeof(double));
  xToZ(x, z, numSamples, splineOrder, numBins);
  for (curSample = 0; curSample < numSamples; curSample++) {
    if (z[curSample] == 1e+30) {
      for (curBin = 0; curBin < numBins; curBin++) {
        weights[curBin * numSamples + curSample] = 1e+30;
      }
    } else {
      for (curBin = 0; curBin < numBins; curBin++) {
        weights[curBin * numSamples + curSample] =
            SplineBlend(curBin, splineOrder, knots, z[curSample], numBins);
      }
    }
  }
  free(z);
}


x86 assembly (clang, -O0):
<findWeights>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1040 <xToZ@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1271 <findWeights+0x131>
mov    -0x38(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe51(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    1203 <findWeights+0xc3>
jp     1203 <findWeights+0xc3>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11fe <findWeights+0xbe>
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  0xe15(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c6 <findWeights+0x86>
jmp    125e <findWeights+0x11e>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1259 <findWeights+0x119>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x38(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x24(%rbp),%ecx
call   1060 <SplineBlend@plt>
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    120a <findWeights+0xca>
jmp    125e <findWeights+0x11e>
jmp    1263 <findWeights+0x123>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    118e <findWeights+0x4e>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findWeights>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %r9d,%ebp
mov    %r8d,%ebx
mov    %ecx,%r14d
mov    %rdx,0x10(%rsp)
mov    %rsi,0x40(%rsp)
mov    %rdi,%r15
mov    %ecx,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %r15,%rdi
mov    %rax,0x18(%rsp)
mov    %rax,%rsi
mov    %r14d,%edx
mov    %ebx,0xc(%rsp)
mov    %ebx,%ecx
mov    %ebp,0x8(%rsp)
mov    %ebp,%r8d
call   1040 <xToZ@plt>
test   %r14d,%r14d
jle    1361 <findWeights+0x221>
mov    0x8(%rsp),%ebx
mov    %r14d,%ecx
lea    -0x1(%rbx),%rax
mov    %rax,0x70(%rsp)
mov    %ebx,%eax
and    $0x3,%eax
mov    %rax,0x20(%rsp)
mov    %ebx,%eax
and    $0xfffffffc,%eax
mov    %rax,0x60(%rsp)
mov    0x10(%rsp),%rax
lea    (%rax,%rcx,8),%rdx
mov    %rdx,0x28(%rsp)
lea    0x0(,%rcx,8),%r13
mov    %rcx,%rdx
shl    $0x4,%rdx
mov    %rdx,0x58(%rsp)
mov    %rcx,0x38(%rsp)
shl    $0x5,%rcx
mov    %rcx,0x50(%rsp)
lea    0x0(,%r13,2),%rcx
add    %r13,%rcx
mov    %rcx,0x48(%rsp)
xor    %ebp,%ebp
movabs $0x46293e5939a08cea,%r15
3e 29 46
mov    %rax,0x30(%rsp)
mov    %rbx,0x68(%rsp)
jmp    123b <findWeights+0xfb>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbp
addq   $0x8,0x28(%rsp)
addq   $0x8,0x30(%rsp)
cmp    0x38(%rsp),%rbp
je     1361 <findWeights+0x221>
mov    0x18(%rsp),%rax
movsd  (%rax,%rbp,8),%xmm0
ucomisd 0xdb3(%rip),%xmm0
jne    1270 <findWeights+0x130>
jp     1270 <findWeights+0x130>
cmpl   $0x0,0x8(%rsp)
jle    1220 <findWeights+0xe0>
cmpq   $0x3,0x70(%rsp)
jae    12e4 <findWeights+0x1a4>
xor    %eax,%eax
jmp    131b <findWeights+0x1db>
nopl   0x0(%rax,%rax,1)
cmpl   $0x0,0x8(%rsp)
jle    1220 <findWeights+0xe0>
xor    %edi,%edi
mov    0xc(%rsp),%esi
mov    0x40(%rsp),%rdx
mov    0x8(%rsp),%r14d
mov    %r14d,%ecx
call   1060 <SplineBlend@plt>
mov    0x10(%rsp),%rax
movsd  %xmm0,(%rax,%rbp,8)
cmp    $0x1,%r14d
je     1220 <findWeights+0xe0>
mov    $0x1,%r14d
mov    0x28(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    0x18(%rsp),%rax
movsd  (%rax,%rbp,8),%xmm0
mov    %r14d,%edi
mov    0xc(%rsp),%esi
mov    0x40(%rsp),%rdx
mov    %ebx,%ecx
call   1060 <SplineBlend@plt>
movsd  %xmm0,(%r12)
add    $0x1,%r14
add    %r13,%r12
cmp    %r14,%rbx
jne    12b0 <findWeights+0x170>
jmp    1220 <findWeights+0xe0>
mov    0x30(%rsp),%rcx
xor    %eax,%eax
mov    0x60(%rsp),%rdx
mov    0x58(%rsp),%rsi
mov    0x50(%rsp),%rdi
mov    0x48(%rsp),%rbx
nop
mov    %r15,(%rcx)
mov    %r15,(%rcx,%r13,1)
mov    %r15,(%rcx,%rsi,1)
mov    %r15,(%rcx,%rbx,1)
add    $0x4,%rax
add    %rdi,%rcx
cmp    %rax,%rdx
jne    1300 <findWeights+0x1c0>
cmpq   $0x0,0x20(%rsp)
mov    0x68(%rsp),%rbx
je     1220 <findWeights+0xe0>
imul   0x38(%rsp),%rax
add    %rbp,%rax
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,8),%rax
mov    0x20(%rsp),%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,(%rax)
add    %r13,%rax
add    $0xffffffffffffffff,%rcx
jne    1350 <findWeights+0x210>
jmp    1220 <findWeights+0xe0>
mov    0x18(%rsp),%rdi
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @findWeights(double* %0, i32* %1, double* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca double*
%8 = alloca i32*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double*
store double* %0, double** %7
store i32* %1, i32** %8
store double* %2, double** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%16 = load i32, i32* %10
%17 = call i64 @calloc(i32 %16, i32 8)
%18 = inttoptr i64 %17 to double*
store double* %18, double** %15
%19 = load double*, double** %7
%20 = load double*, double** %15
%21 = load i32, i32* %10
%22 = load i32, i32* %11
%23 = load i32, i32* %12
%24 = call i32 @xToZ(double* %19, double* %20, i32 %21, i32 %22, i32 %23)
store i32 0, i32* %13
br label %25
25: ; preds = %83, %6
%26 = load i32, i32* %13
%27 = load i32, i32* %10
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %86
29: ; preds = %25
%30 = load double*, double** %15
%31 = load i32, i32* %13
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
%34 = load double, double* %33
%35 = fcmp oeq double %34, 1.000000e+30
br i1 %35, label %36, label %54
36: ; preds = %29
store i32 0, i32* %14
br label %37
37: ; preds = %50, %36
%38 = load i32, i32* %14
%39 = load i32, i32* %12
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %53
41: ; preds = %37
%42 = load double*, double** %9
%43 = load i32, i32* %14
%44 = load i32, i32* %10
%45 = mul nsw i32 %43, %44
%46 = load i32, i32* %13
%47 = add nsw i32 %45, %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %42, i64 %48
store double 1.000000e+30, double* %49
br label %50
50: ; preds = %41
%51 = load i32, i32* %14
%52 = add nsw i32 %51, 1
store i32 %52, i32* %14
br label %37
53: ; preds = %37
br label %82
54: ; preds = %29
store i32 0, i32* %14
br label %55
55: ; preds = %78, %54
%56 = load i32, i32* %14
%57 = load i32, i32* %12
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %81
59: ; preds = %55
%60 = load i32, i32* %14
%61 = load i32, i32* %11
%62 = load i32*, i32** %8
%63 = load double*, double** %15
%64 = load i32, i32* %13
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
%67 = load double, double* %66
%68 = load i32, i32* %12
%69 = call double @SplineBlend(i32 %60, i32 %61, i32* %62, double %67, i32 %68)
%70 = load double*, double** %9
%71 = load i32, i32* %14
%72 = load i32, i32* %10
%73 = mul nsw i32 %71, %72
%74 = load i32, i32* %13
%75 = add nsw i32 %73, %74
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds double, double* %70, i64 %76
store double %69, double* %77
br label %78
78: ; preds = %59
%79 = load i32, i32* %14
%80 = add nsw i32 %79, 1
store i32 %80, i32* %14
br label %55
81: ; preds = %55
br label %82
82: ; preds = %81, %53
br label %83
83: ; preds = %82
%84 = load i32, i32* %13
%85 = add nsw i32 %84, 1
store i32 %85, i32* %13
br label %25
86: ; preds = %25
%87 = load double*, double** %15
%88 = call i32 @free(double* %87)
ret void
}

LLVM IR (-O2):
define void @findWeights(double* %0, i32* %1, double* nocapture writeonly %2, i32 %3, i32 %4, i32 %5) {
%7 = tail call i64 @calloc(i32 %3, i32 8)
%8 = inttoptr i64 %7 to double*
%9 = tail call i32 @xToZ(double* %0, double* %8, i32 %3, i32 %4, i32 %5)
%10 = icmp sgt i32 %3, 0
br i1 %10, label %11, label %78
11: ; preds = %6
%12 = icmp sgt i32 %5, 0
%13 = zext i32 %3 to i64
%14 = zext i32 %3 to i64
%15 = zext i32 %5 to i64
%16 = add nsw i64 %15, -1
%17 = icmp eq i32 %5, 1
%18 = and i64 %15, 3
%19 = icmp ult i64 %16, 3
%20 = and i64 %15, 4294967292
%21 = icmp eq i64 %18, 0
br label %22
22: ; preds = %11, %75
%23 = phi i64 [ 0, %11 ], [ %76, %75 ]
%24 = getelementptr inbounds double, double* %8, i64 %23
%25 = load double, double* %24
%26 = fcmp oeq double %25, 1.000000e+30
br i1 %26, label %31, label %27
27: ; preds = %22
br i1 %12, label %28, label %75
28: ; preds = %27
%29 = tail call double @SplineBlend(i32 0, i32 %4, i32* %1, double %25, i32 %5)
%30 = getelementptr inbounds double, double* %2, i64 %23
store double %29, double* %30
br i1 %17, label %75, label %54
31: ; preds = %22
br i1 %12, label %32, label %75
32: ; preds = %31
br i1 %19, label %64, label %33
33: ; preds = %32, %33
%34 = phi i64 [ %51, %33 ], [ 0, %32 ]
%35 = phi i64 [ %52, %33 ], [ 0, %32 ]
%36 = mul nsw i64 %34, %13
%37 = add nuw nsw i64 %36, %23
%38 = getelementptr inbounds double, double* %2, i64 %37
store double 1.000000e+30, double* %38
%39 = or i64 %34, 1
%40 = mul nsw i64 %39, %13
%41 = add nuw nsw i64 %40, %23
%42 = getelementptr inbounds double, double* %2, i64 %41
store double 1.000000e+30, double* %42
%43 = or i64 %34, 2
%44 = mul nsw i64 %43, %13
%45 = add nuw nsw i64 %44, %23
%46 = getelementptr inbounds double, double* %2, i64 %45
store double 1.000000e+30, double* %46
%47 = or i64 %34, 3
%48 = mul nsw i64 %47, %13
%49 = add nuw nsw i64 %48, %23
%50 = getelementptr inbounds double, double* %2, i64 %49
store double 1.000000e+30, double* %50
%51 = add nuw nsw i64 %34, 4
%52 = add i64 %35, 4
%53 = icmp eq i64 %52, %20
br i1 %53, label %64, label %33
54: ; preds = %28, %54
%55 = phi i64 [ %62, %54 ], [ 1, %28 ]
%56 = load double, double* %24
%57 = trunc i64 %55 to i32
%58 = tail call double @SplineBlend(i32 %57, i32 %4, i32* %1, double %56, i32 %5)
%59 = mul nsw i64 %55, %13
%60 = add nuw nsw i64 %59, %23
%61 = getelementptr inbounds double, double* %2, i64 %60
store double %58, double* %61
%62 = add nuw nsw i64 %55, 1
%63 = icmp eq i64 %62, %15
br i1 %63, label %75, label %54
64: ; preds = %33, %32
%65 = phi i64 [ 0, %32 ], [ %51, %33 ]
br i1 %21, label %75, label %66
66: ; preds = %64, %66
%67 = phi i64 [ %72, %66 ], [ %65, %64 ]
%68 = phi i64 [ %73, %66 ], [ 0, %64 ]
%69 = mul nsw i64 %67, %13
%70 = add nuw nsw i64 %69, %23
%71 = getelementptr inbounds double, double* %2, i64 %70
store double 1.000000e+30, double* %71
%72 = add nuw nsw i64 %67, 1
%73 = add i64 %68, 1
%74 = icmp eq i64 %73, %18
br i1 %74, label %75, label %66
75: ; preds = %54, %64, %66, %28, %27, %31
%76 = add nuw nsw i64 %23, 1
%77 = icmp eq i64 %76, %14
br i1 %77, label %78, label %22
78: ; preds = %75, %6
%79 = tail call i32 @free(double* %8)
ret void
}