#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 */
float kernel_value_CPU(float);
scalar_t__ malloc(unsigned int);
float sqrt(double);
void calculateLUT(float beta, float width, float **LUT, unsigned int *sizeLUT) {
  float v;
  float cutoff2 = (width * width) / 4.0;
  unsigned int size;
  if (width > 0) {
    size = (unsigned int)(10000 * width);
    (*LUT) = (float *)malloc(size * sizeof(float));
    unsigned int k;
    for (k = 0; k < size; ++k) {
      v = (((float)k) / ((float)size)) * cutoff2;
      (*LUT)[k] = kernel_value_CPU(beta * sqrt(1.0 - (v / cutoff2)));
    }
    (*sizeLUT) = size;
  }
}


x86 assembly (clang, -O0):
<calculateLUT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movss  -0x8(%rbp),%xmm0
mulss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea0(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    1240 <calculateLUT+0x110>
movss  -0x8(%rbp),%xmm0
movss  0xe85(%rip),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    1237 <calculateLUT+0x107>
mov    -0x28(%rbp),%eax
cvtsi2ss %rax,%xmm0
mov    -0x24(%rbp),%eax
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
mulss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x1c(%rbp),%xmm0
divss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe08(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
mulss  %xmm1,%xmm0
call   1030 <kernel_value_CPU@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%ecx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11b6 <calculateLUT+0x86>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculateLUT>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
xorps  %xmm2,%xmm2
movss  %xmm1,0x4(%rsp)
ucomiss %xmm2,%xmm1
jbe    1216 <calculateLUT+0xe6>
mov    %rsi,%r14
mov    %rdi,%r12
movss  0xea7(%rip),%xmm1
mulss  0x4(%rsp),%xmm1
cvttss2si %xmm1,%r15
lea    0x0(,%r15,4),%edi
movss  %xmm0,0xc(%rsp)
call   1040 <malloc@plt>
mov    %rax,(%r12)
test   %r15d,%r15d
je     1213 <calculateLUT+0xe3>
movss  0x4(%rsp),%xmm0
mulss  %xmm0,%xmm0
mov    %r15d,%r13d
xorps  %xmm1,%xmm1
cvtsi2ss %r13,%xmm1
movss  %xmm1,0x8(%rsp)
mulss  0xe55(%rip),%xmm0
movss  %xmm0,0x4(%rsp)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  0x8(%rsp),%xmm0
movss  0x4(%rsp),%xmm1
mulss  %xmm1,%xmm0
divss  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  0xe1b(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
mulss  0xc(%rsp),%xmm0
call   1030 <kernel_value_CPU@plt>
mov    (%r12),%rax
movss  %xmm0,(%rax,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11c0 <calculateLUT+0x90>
mov    %r15d,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @calculateLUT(float %0, float %1, float** %2, i32* %3) {
%5 = alloca float
%6 = alloca float
%7 = alloca float**
%8 = alloca i32*
%9 = alloca float
%10 = alloca float
%11 = alloca i32
%12 = alloca i32
store float %0, float* %5
store float %1, float* %6
store float** %2, float*** %7
store i32* %3, i32** %8
%13 = load float, float* %6
%14 = load float, float* %6
%15 = fmul float %13, %14
%16 = fpext float %15 to double
%17 = fdiv double %16, 4.000000e+00
%18 = fptrunc double %17 to float
store float %18, float* %10
%19 = load float, float* %6
%20 = fcmp ogt float %19, 0.000000e+00
br i1 %20, label %21, label %64
21: ; preds = %4
%22 = load float, float* %6
%23 = fmul float 1.000000e+04, %22
%24 = fptoui float %23 to i32
store i32 %24, i32* %11
%25 = load i32, i32* %11
%26 = zext i32 %25 to i64
%27 = mul i64 %26, 4
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to float*
%31 = load float**, float*** %7
store float* %30, float** %31
store i32 0, i32* %12
br label %32
32: ; preds = %58, %21
%33 = load i32, i32* %12
%34 = load i32, i32* %11
%35 = icmp ult i32 %33, %34
br i1 %35, label %36, label %61
36: ; preds = %32
%37 = load i32, i32* %12
%38 = uitofp i32 %37 to float
%39 = load i32, i32* %11
%40 = uitofp i32 %39 to float
%41 = fdiv float %38, %40
%42 = load float, float* %10
%43 = fmul float %41, %42
store float %43, float* %9
%44 = load float, float* %5
%45 = load float, float* %9
%46 = load float, float* %10
%47 = fdiv float %45, %46
%48 = fpext float %47 to double
%49 = fsub double 1.000000e+00, %48
%50 = call float @sqrt(double %49)
%51 = fmul float %44, %50
%52 = call float @kernel_value_CPU(float %51)
%53 = load float**, float*** %7
%54 = load float*, float** %53
%55 = load i32, i32* %12
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds float, float* %54, i64 %56
store float %52, float* %57
br label %58
58: ; preds = %36
%59 = load i32, i32* %12
%60 = add i32 %59, 1
store i32 %60, i32* %12
br label %32
61: ; preds = %32
%62 = load i32, i32* %11
%63 = load i32*, i32** %8
store i32 %62, i32* %63
br label %64
64: ; preds = %61, %4
ret void
}

LLVM IR (-O2):
define void @calculateLUT(float %0, float %1, float** nocapture %2, i32* nocapture writeonly %3) {
%5 = fmul float %1, %1
%6 = fmul float %5, 2.500000e-01
%7 = fcmp ogt float %1, 0.000000e+00
br i1 %7, label %8, label %35
8: ; preds = %4
%9 = fmul float %1, 1.000000e+04
%10 = fptoui float %9 to i32
%11 = shl i32 %10, 2
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to float*
store float* %13, float** %2
%14 = icmp eq i32 %10, 0
br i1 %14, label %34, label %15
15: ; preds = %8
%16 = uitofp i32 %10 to float
%17 = zext i32 %10 to i64
br label %18
18: ; preds = %15, %18
%19 = phi i64 [ 0, %15 ], [ %32, %18 ]
%20 = trunc i64 %19 to i32
%21 = uitofp i32 %20 to float
%22 = fdiv float %21, %16
%23 = fmul float %6, %22
%24 = fdiv float %23, %6
%25 = fpext float %24 to double
%26 = fsub double 1.000000e+00, %25
%27 = tail call float @sqrt(double %26)
%28 = fmul float %27, %0
%29 = tail call float @kernel_value_CPU(float %28)
%30 = load float*, float** %2
%31 = getelementptr inbounds float, float* %30, i64 %19
store float %29, float* %31
%32 = add nuw nsw i64 %19, 1
%33 = icmp eq i64 %32, %17
br i1 %33, label %34, label %18
34: ; preds = %18, %8
store i32 %10, i32* %3
br label %35
35: ; preds = %34, %4
ret void
}