#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 QP2Qstep(int);
int Qstep2QP(double Qstep) {
  int q_per = 0, q_rem = 0;
  if (Qstep < QP2Qstep(0))
    return 0;
  else if (Qstep > QP2Qstep(51))
    return 51;
  while (Qstep > QP2Qstep(5)) {
    Qstep /= 2.0;
    q_per += 1;
  }
  if (Qstep <= 0.65625) {
    Qstep = 0.625;
    q_rem = 0;
  } else if (Qstep <= 0.75) {
    Qstep = 0.6875;
    q_rem = 1;
  } else if (Qstep <= 0.84375) {
    Qstep = 0.8125;
    q_rem = 2;
  } else if (Qstep <= 0.9375) {
    Qstep = 0.875;
    q_rem = 3;
  } else if (Qstep <= 1.0625) {
    Qstep = 1.0;
    q_rem = 4;
  } else {
    Qstep = 1.125;
    q_rem = 5;
  }
  return (q_per * 6 + q_rem);
}


x86 assembly (clang, -O0):
<Qstep2QP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xor    %edi,%edi
call   1030 <QP2Qstep@plt>
movsd  -0x20(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    1157 <Qstep2QP+0x47>
movl   $0x0,-0x4(%rbp)
jmp    12eb <Qstep2QP+0x1db>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x33,%edi
call   1030 <QP2Qstep@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1189 <Qstep2QP+0x79>
movl   $0x33,-0x4(%rbp)
jmp    12eb <Qstep2QP+0x1db>
jmp    118e <Qstep2QP+0x7e>
jmp    1193 <Qstep2QP+0x83>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x5,%edi
call   1030 <QP2Qstep@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11dd <Qstep2QP+0xcd>
movsd  -0x10(%rbp),%xmm0
movsd  0xe92(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <Qstep2QP+0x83>
movsd  0xe1b(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1209 <Qstep2QP+0xf9>
movsd  0xe58(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    12e1 <Qstep2QP+0x1d1>
movsd  0xdf7(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1235 <Qstep2QP+0x125>
movsd  0xe24(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
jmp    12dc <Qstep2QP+0x1cc>
movsd  0xdd3(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1261 <Qstep2QP+0x151>
movsd  0xdf0(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x2,-0x18(%rbp)
jmp    12d7 <Qstep2QP+0x1c7>
movsd  0xdaf(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     128d <Qstep2QP+0x17d>
movsd  0xdbc(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x3,-0x18(%rbp)
jmp    12d2 <Qstep2QP+0x1c2>
movsd  0xd8b(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     12b9 <Qstep2QP+0x1a9>
movsd  0xd88(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x4,-0x18(%rbp)
jmp    12cd <Qstep2QP+0x1bd>
movsd  0xd67(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x5,-0x18(%rbp)
jmp    12d2 <Qstep2QP+0x1c2>
jmp    12d7 <Qstep2QP+0x1c7>
jmp    12dc <Qstep2QP+0x1cc>
jmp    12e1 <Qstep2QP+0x1d1>
imul   $0x6,-0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Qstep2QP>:
push   %rbp
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <QP2Qstep@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
ja     11f2 <Qstep2QP+0xe2>
mov    $0x33,%ebx
mov    $0x33,%edi
call   1030 <QP2Qstep@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     11f2 <Qstep2QP+0xe2>
mov    $0x5,%edi
call   1030 <QP2Qstep@plt>
movsd  (%rsp),%xmm1
xor    %ebx,%ebx
xor    %ebp,%ebp
ucomisd %xmm0,%xmm1
jbe    1195 <Qstep2QP+0x85>
nopw   0x0(%rax,%rax,1)
mulsd  0xe88(%rip),%xmm1
movsd  %xmm1,(%rsp)
mov    $0x5,%edi
call   1030 <QP2Qstep@plt>
movsd  (%rsp),%xmm1
add    $0x6,%ebp
ucomisd %xmm0,%xmm1
ja     1170 <Qstep2QP+0x60>
movsd  0xe6b(%rip),%xmm0
ucomisd %xmm1,%xmm0
jae    11f0 <Qstep2QP+0xe0>
mov    $0x1,%ebx
movsd  0xe60(%rip),%xmm0
ucomisd %xmm1,%xmm0
jae    11f0 <Qstep2QP+0xe0>
mov    $0x2,%ebx
movsd  0xe55(%rip),%xmm0
ucomisd %xmm1,%xmm0
jae    11f0 <Qstep2QP+0xe0>
mov    $0x3,%ebx
movsd  0xe4a(%rip),%xmm0
ucomisd %xmm1,%xmm0
jae    11f0 <Qstep2QP+0xe0>
movsd  0xe44(%rip),%xmm0
xor    %ebx,%ebx
ucomisd %xmm1,%xmm0
setb   %bl
or     $0x4,%ebx
add    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @Qstep2QP(double %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
store double %0, double* %3
store i32 0, i32* %4
store i32 0, i32* %5
%6 = load double, double* %3
%7 = call double @QP2Qstep(i32 0)
%8 = fcmp olt double %6, %7
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %56
10: ; preds = %1
%11 = load double, double* %3
%12 = call double @QP2Qstep(i32 51)
%13 = fcmp ogt double %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 51, i32* %2
br label %56
15: ; preds = %10
br label %16
16: ; preds = %15
br label %17
17: ; preds = %21, %16
%18 = load double, double* %3
%19 = call double @QP2Qstep(i32 5)
%20 = fcmp ogt double %18, %19
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load double, double* %3
%23 = fdiv double %22, 2.000000e+00
store double %23, double* %3
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %17
26: ; preds = %17
%27 = load double, double* %3
%28 = fcmp ole double %27, 6.562500e-01
br i1 %28, label %29, label %30
29: ; preds = %26
store double 6.250000e-01, double* %3
store i32 0, i32* %5
br label %51
30: ; preds = %26
%31 = load double, double* %3
%32 = fcmp ole double %31, 7.500000e-01
br i1 %32, label %33, label %34
33: ; preds = %30
store double 6.875000e-01, double* %3
store i32 1, i32* %5
br label %50
34: ; preds = %30
%35 = load double, double* %3
%36 = fcmp ole double %35, 8.437500e-01
br i1 %36, label %37, label %38
37: ; preds = %34
store double 8.125000e-01, double* %3
store i32 2, i32* %5
br label %49
38: ; preds = %34
%39 = load double, double* %3
%40 = fcmp ole double %39, 9.375000e-01
br i1 %40, label %41, label %42
41: ; preds = %38
store double 8.750000e-01, double* %3
store i32 3, i32* %5
br label %48
42: ; preds = %38
%43 = load double, double* %3
%44 = fcmp ole double %43, 1.062500e+00
br i1 %44, label %45, label %46
45: ; preds = %42
store double 1.000000e+00, double* %3
store i32 4, i32* %5
br label %47
46: ; preds = %42
store double 1.125000e+00, double* %3
store i32 5, i32* %5
br label %47
47: ; preds = %46, %45
br label %48
48: ; preds = %47, %41
br label %49
49: ; preds = %48, %37
br label %50
50: ; preds = %49, %33
br label %51
51: ; preds = %50, %29
%52 = load i32, i32* %4
%53 = mul nsw i32 %52, 6
%54 = load i32, i32* %5
%55 = add nsw i32 %53, %54
store i32 %55, i32* %2
br label %56
56: ; preds = %51, %14, %9
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
define i32 @Qstep2QP(double %0) {
%2 = tail call double @QP2Qstep(i32 0)
%3 = fcmp ogt double %2, %0
br i1 %3, label %35, label %4
4: ; preds = %1
%5 = tail call double @QP2Qstep(i32 51)
%6 = fcmp olt double %5, %0
br i1 %6, label %35, label %7
7: ; preds = %4
%8 = tail call double @QP2Qstep(i32 5)
%9 = fcmp olt double %8, %0
br i1 %9, label %10, label %19
10: ; preds = %7, %10
%11 = phi i32 [ %14, %10 ], [ 0, %7 ]
%12 = phi double [ %13, %10 ], [ %0, %7 ]
%13 = fmul double %12, 5.000000e-01
%14 = add nuw nsw i32 %11, 1
%15 = tail call double @QP2Qstep(i32 5)
%16 = fcmp ogt double %13, %15
br i1 %16, label %10, label %17
17: ; preds = %10
%18 = mul i32 %14, 6
br label %19
19: ; preds = %17, %7
%20 = phi double [ %0, %7 ], [ %13, %17 ]
%21 = phi i32 [ 0, %7 ], [ %18, %17 ]
%22 = fcmp ugt double %20, 6.562500e-01
br i1 %22, label %23, label %32
23: ; preds = %19
%24 = fcmp ugt double %20, 7.500000e-01
br i1 %24, label %25, label %32
25: ; preds = %23
%26 = fcmp ugt double %20, 8.437500e-01
br i1 %26, label %27, label %32
27: ; preds = %25
%28 = fcmp ugt double %20, 9.375000e-01
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = fcmp ugt double %20, 1.062500e+00
%31 = select i1 %30, i32 5, i32 4
br label %32
32: ; preds = %29, %27, %25, %23, %19
%33 = phi i32 [ 0, %19 ], [ 1, %23 ], [ 2, %25 ], [ 3, %27 ], [ %31, %29 ]
%34 = add nuw nsw i32 %33, %21
br label %35
35: ; preds = %4, %1, %32
%36 = phi i32 [ %34, %32 ], [ 0, %1 ], [ 51, %4 ]
ret i32 %36
}