#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 asin(double);
double sin(double);
void QuantizeReflectionCoeffs(int fOrder, int coeffRes, double *kArray,
                              int *indexArray) {
  double iqfac, iqfac_m;
  int i;
  iqfac = ((1 << (coeffRes - 1)) - 0.5) / (3.14159265358979323846 / 2);
  iqfac_m = ((1 << (coeffRes - 1)) + 0.5) / (3.14159265358979323846 / 2);
  for (i = 1; i <= fOrder; i++) {
    indexArray[i] =
        (int)(0.5 + (asin(kArray[i]) * ((kArray[i] >= 0) ? iqfac : iqfac_m)));
    kArray[i] =
        sin((double)indexArray[i] / ((indexArray[i] >= 0) ? iqfac : iqfac_m));
  }
}


x86 assembly (clang, -O0):
<QuantizeReflectionCoeffs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2sd %eax,%xmm0
movsd  0xeb9(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xea5(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe8b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe77(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1283 <QuantizeReflectionCoeffs+0x163>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <asin@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11e5 <QuantizeReflectionCoeffs+0xc5>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11ef <QuantizeReflectionCoeffs+0xcf>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe03(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cvtsi2sdl (%rax,%rcx,4),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jl     124b <QuantizeReflectionCoeffs+0x12b>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    1255 <QuantizeReflectionCoeffs+0x135>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1030 <sin@plt>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1199 <QuantizeReflectionCoeffs+0x79>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<QuantizeReflectionCoeffs>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
lea    -0x1(%rsi),%ecx
mov    $0x1,%eax
shl    %cl,%eax
test   %edi,%edi
jle    1200 <QuantizeReflectionCoeffs+0xe0>
mov    %rdx,%r12
mov    %edi,%r15d
cvtsi2sd %eax,%xmm1
movsd  0xeae(%rip),%xmm2
addsd  %xmm1,%xmm2
movsd  0xeaa(%rip),%xmm0
divsd  %xmm0,%xmm2
movapd %xmm2,0x10(%rsp)
addsd  0xea0(%rip),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
add    $0x1,%r15d
mov    $0x1,%ebx
jmp    11b0 <QuantizeReflectionCoeffs+0x90>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cvttpd2dq %xmm1,%xmm0
cvtdq2pd %xmm0,%xmm0
divsd  %xmm2,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
je     1200 <QuantizeReflectionCoeffs+0xe0>
movsd  (%r12,%rbx,8),%xmm0
call   1040 <asin@plt>
xorpd  %xmm1,%xmm1
cmplesd (%r12,%rbx,8),%xmm1
movapd %xmm1,%xmm2
movapd 0x10(%rsp),%xmm3
andpd  %xmm3,%xmm2
andnpd (%rsp),%xmm1
orpd   %xmm2,%xmm1
mulsd  %xmm0,%xmm1
addsd  0xe27(%rip),%xmm1
cvttsd2si %xmm1,%eax
mov    %eax,(%r14,%rbx,4)
movapd %xmm3,%xmm2
test   %eax,%eax
jns    1190 <QuantizeReflectionCoeffs+0x70>
movapd (%rsp),%xmm2
jmp    1190 <QuantizeReflectionCoeffs+0x70>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @QuantizeReflectionCoeffs(i32 %0, i32 %1, double* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca i32*
%9 = alloca double
%10 = alloca double
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store double* %2, double** %7
store i32* %3, i32** %8
%12 = load i32, i32* %6
%13 = sub nsw i32 %12, 1
%14 = shl i32 1, %13
%15 = sitofp i32 %14 to double
%16 = fsub double %15, 5.000000e-01
%17 = fdiv double %16, 0x3FF921FB54442D18
store double %17, double* %9
%18 = load i32, i32* %6
%19 = sub nsw i32 %18, 1
%20 = shl i32 1, %19
%21 = sitofp i32 %20 to double
%22 = fadd double %21, 5.000000e-01
%23 = fdiv double %22, 0x3FF921FB54442D18
store double %23, double* %10
store i32 1, i32* %11
br label %24
24: ; preds = %77, %4
%25 = load i32, i32* %11
%26 = load i32, i32* %5
%27 = icmp sle i32 %25, %26
br i1 %27, label %28, label %80
28: ; preds = %24
%29 = load double*, double** %7
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = call double @asin(double %33)
%35 = load double*, double** %7
%36 = load i32, i32* %11
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = fcmp oge double %39, 0.000000e+00
br i1 %40, label %41, label %43
41: ; preds = %28
%42 = load double, double* %9
br label %45
43: ; preds = %28
%44 = load double, double* %10
br label %45
45: ; preds = %43, %41
%46 = phi double [ %42, %41 ], [ %44, %43 ]
%47 = call double @llvm.fmuladd.f64(double %34, double %46, double 5.000000e-01)
%48 = fptosi double %47 to i32
%49 = load i32*, i32** %8
%50 = load i32, i32* %11
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
store i32 %48, i32* %52
%53 = load i32*, i32** %8
%54 = load i32, i32* %11
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
%57 = load i32, i32* %56
%58 = sitofp i32 %57 to double
%59 = load i32*, i32** %8
%60 = load i32, i32* %11
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
%63 = load i32, i32* %62
%64 = icmp sge i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %45
%66 = load double, double* %9
br label %69
67: ; preds = %45
%68 = load double, double* %10
br label %69
69: ; preds = %67, %65
%70 = phi double [ %66, %65 ], [ %68, %67 ]
%71 = fdiv double %58, %70
%72 = call double @sin(double %71)
%73 = load double*, double** %7
%74 = load i32, i32* %11
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double, double* %73, i64 %75
store double %72, double* %76
br label %77
77: ; preds = %69
%78 = load i32, i32* %11
%79 = add nsw i32 %78, 1
store i32 %79, i32* %11
br label %24
80: ; preds = %24
ret void
}

LLVM IR (-O2):
define void @QuantizeReflectionCoeffs(i32 %0, i32 %1, double* nocapture %2, i32* nocapture writeonly %3) {
%5 = add nsw i32 %1, -1
%6 = shl nuw i32 1, %5
%7 = sitofp i32 %6 to double
%8 = fadd double %7, -5.000000e-01
%9 = fdiv double %8, 0x3FF921FB54442D18
%10 = fadd double %7, 5.000000e-01
%11 = fdiv double %10, 0x3FF921FB54442D18
%12 = icmp slt i32 %0, 1
br i1 %12, label %34, label %13
13: ; preds = %4
%14 = add nuw i32 %0, 1
%15 = zext i32 %14 to i64
br label %16
16: ; preds = %13, %16
%17 = phi i64 [ 1, %13 ], [ %32, %16 ]
%18 = getelementptr inbounds double, double* %2, i64 %17
%19 = load double, double* %18
%20 = tail call double @asin(double %19)
%21 = load double, double* %18
%22 = fcmp oge double %21, 0.000000e+00
%23 = select i1 %22, double %9, double %11
%24 = tail call double @llvm.fmuladd.f64(double %20, double %23, double 5.000000e-01)
%25 = fptosi double %24 to i32
%26 = getelementptr inbounds i32, i32* %3, i64 %17
store i32 %25, i32* %26
%27 = sitofp i32 %25 to double
%28 = icmp sgt i32 %25, -1
%29 = select i1 %28, double %9, double %11
%30 = fdiv double %27, %29
%31 = tail call double @sin(double %30)
store double %31, double* %18
%32 = add nuw nsw i64 %17, 1
%33 = icmp eq i64 %32, %15
br i1 %33, label %34, label %16
34: ; preds = %16, %4
ret void
}