#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 sqrt(double);
int qtz_ref_cof(double *ref, unsigned char ord, short *q_ref) {
  for (int i = 0; i < ord; i++) {
    if (i == 0)
      q_ref[i] = 64 * (-1 + 1.41421356237 * sqrt(ref[i] + 1));
    else if (i == 1)
      q_ref[i] = 64 * (-1 + 1.41421356237 * sqrt(-ref[i] + 1));
    else
      q_ref[i] = 64 * ref[i];
  }
  return (0);
}


x86 assembly (clang, -O0):
<qtz_ref_cof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
movzbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jge    1248 <qtz_ref_cof+0x138>
cmpl   $0x0,-0x1c(%rbp)
jne    11a0 <qtz_ref_cof+0x90>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xead(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  0xea4(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xea0(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe7c(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,%dx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
jmp    1235 <qtz_ref_cof+0x125>
cmpl   $0x1,-0x1c(%rbp)
jne    1204 <qtz_ref_cof+0xf4>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  0xe49(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  0xe40(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe3c(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xe18(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,%dx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
jmp    1230 <qtz_ref_cof+0x120>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xde7(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,%dx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
jmp    1235 <qtz_ref_cof+0x125>
jmp    123a <qtz_ref_cof+0x12a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112d <qtz_ref_cof+0x1d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qtz_ref_cof>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     123b <qtz_ref_cof+0x12b>
mov    %rdx,%r14
mov    %rdi,%r15
movzbl %sil,%r12d
xor    %ebx,%ebx
movsd  0xecc(%rip),%xmm1
xorpd  %xmm2,%xmm2
movsd  0xec8(%rip),%xmm3
movsd  0xec8(%rip),%xmm4
movsd  0xec8(%rip),%xmm5
jmp    1180 <qtz_ref_cof+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  (%r15,%rbx,8),%xmm0
mulsd  %xmm5,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,(%r14,%rbx,2)
add    $0x1,%rbx
cmp    %rbx,%r12
je     123b <qtz_ref_cof+0x12b>
cmp    $0x1,%ebx
je     11a0 <qtz_ref_cof+0x90>
test   %ebx,%ebx
jne    1160 <qtz_ref_cof+0x50>
movsd  (%r15),%xmm0
addsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jb     11b6 <qtz_ref_cof+0xa6>
sqrtsd %xmm0,%xmm0
jmp    11df <qtz_ref_cof+0xcf>
xchg   %ax,%ax
movapd %xmm1,%xmm0
subsd  0x8(%r15),%xmm0
ucomisd %xmm2,%xmm0
jb     11f8 <qtz_ref_cof+0xe8>
sqrtsd %xmm0,%xmm0
jmp    1221 <qtz_ref_cof+0x111>
call   1030 <sqrt@plt>
movsd  0xe55(%rip),%xmm5
movsd  0xe45(%rip),%xmm4
movsd  0xe35(%rip),%xmm3
xorpd  %xmm2,%xmm2
movsd  0xe21(%rip),%xmm1
mulsd  %xmm3,%xmm0
addsd  %xmm4,%xmm0
mulsd  %xmm5,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,(%r14)
jmp    1173 <qtz_ref_cof+0x63>
call   1030 <sqrt@plt>
movsd  0xe13(%rip),%xmm5
movsd  0xe03(%rip),%xmm4
movsd  0xdf3(%rip),%xmm3
xorpd  %xmm2,%xmm2
movsd  0xddf(%rip),%xmm1
mulsd  %xmm3,%xmm0
addsd  %xmm4,%xmm0
mulsd  %xmm5,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,0x2(%r14)
jmp    1173 <qtz_ref_cof+0x63>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @qtz_ref_cof(double* %0, i8 zeroext %1, i16* %2) {
%4 = alloca double*
%5 = alloca i8
%6 = alloca i16*
%7 = alloca i32
store double* %0, double** %4
store i8 %1, i8* %5
store i16* %2, i16** %6
store i32 0, i32* %7
br label %8
8: ; preds = %64, %3
%9 = load i32, i32* %7
%10 = load i8, i8* %5
%11 = zext i8 %10 to i32
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %67
13: ; preds = %8
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %31
16: ; preds = %13
%17 = load double*, double** %4
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %17, i64 %19
%21 = load double, double* %20
%22 = fadd double %21, 1.000000e+00
%23 = call double @sqrt(double %22)
%24 = call double @llvm.fmuladd.f64(double 0x3FF6A09E667F055A, double %23, double -1.000000e+00)
%25 = fmul double 6.400000e+01, %24
%26 = fptosi double %25 to i16
%27 = load i16*, i16** %6
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i16, i16* %27, i64 %29
store i16 %26, i16* %30
br label %63
31: ; preds = %13
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %50
34: ; preds = %31
%35 = load double*, double** %4
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = fneg double %39
%41 = fadd double %40, 1.000000e+00
%42 = call double @sqrt(double %41)
%43 = call double @llvm.fmuladd.f64(double 0x3FF6A09E667F055A, double %42, double -1.000000e+00)
%44 = fmul double 6.400000e+01, %43
%45 = fptosi double %44 to i16
%46 = load i16*, i16** %6
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i16, i16* %46, i64 %48
store i16 %45, i16* %49
br label %62
50: ; preds = %31
%51 = load double*, double** %4
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
%55 = load double, double* %54
%56 = fmul double 6.400000e+01, %55
%57 = fptosi double %56 to i16
%58 = load i16*, i16** %6
%59 = load i32, i32* %7
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i16, i16* %58, i64 %60
store i16 %57, i16* %61
br label %62
62: ; preds = %50, %34
br label %63
63: ; preds = %62, %16
br label %64
64: ; preds = %63
%65 = load i32, i32* %7
%66 = add nsw i32 %65, 1
store i32 %66, i32* %7
br label %8
67: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
define i32 @qtz_ref_cof(double* nocapture %0, i8 zeroext %1, i16* nocapture writeonly %2) {
%4 = icmp eq i8 %1, 0
br i1 %4, label %9, label %5
5: ; preds = %3
%6 = getelementptr inbounds double, double* %0, i64 1
%7 = getelementptr inbounds i16, i16* %2, i64 1
%8 = zext i8 %1 to i64
br label %10
9: ; preds = %33, %3
ret i32 0
10: ; preds = %5, %33
%11 = phi i64 [ 0, %5 ], [ %34, %33 ]
%12 = trunc i64 %11 to i32
switch i32 %12, label %27 [
i32 0, label %13
i32 1, label %20
]
13: ; preds = %10
%14 = load double, double* %0
%15 = fadd double %14, 1.000000e+00
%16 = tail call double @sqrt(double %15)
%17 = tail call double @llvm.fmuladd.f64(double %16, double 0x3FF6A09E667F055A, double -1.000000e+00)
%18 = fmul double %17, 6.400000e+01
%19 = fptosi double %18 to i16
store i16 %19, i16* %2
br label %33
20: ; preds = %10
%21 = load double, double* %6
%22 = fsub double 1.000000e+00, %21
%23 = tail call double @sqrt(double %22)
%24 = tail call double @llvm.fmuladd.f64(double %23, double 0x3FF6A09E667F055A, double -1.000000e+00)
%25 = fmul double %24, 6.400000e+01
%26 = fptosi double %25 to i16
store i16 %26, i16* %7
br label %33
27: ; preds = %10
%28 = getelementptr inbounds double, double* %0, i64 %11
%29 = load double, double* %28
%30 = fmul double %29, 6.400000e+01
%31 = fptosi double %30 to i16
%32 = getelementptr inbounds i16, i16* %2, i64 %11
store i16 %31, i16* %32
br label %33
33: ; preds = %13, %27, %20
%34 = add nuw nsw i64 %11, 1
%35 = icmp eq i64 %34, %8
br i1 %35, label %9, label %10
}