#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 */
scalar_t__ isinf(double);
int to_percentile(double quantile, int *percentile) {
  if (quantile < 0 || quantile > 1) {
    return -1;
  }
  quantile *= 100;
  while (quantile != (int)quantile) {
    quantile *= 10;
    if (isinf(quantile)) {
      return -1;
    }
  }
  *percentile = (int)quantile;
  return 0;
}


x86 assembly (clang, -O0):
<to_percentile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
ja     1146 <to_percentile+0x36>
movsd  -0x10(%rbp),%xmm0
movsd  0xec4(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1152 <to_percentile+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <to_percentile+0xc0>
movsd  0xeae(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
cvttsd2si -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm1
ucomisd %xmm1,%xmm0
jne    1187 <to_percentile+0x77>
jp     1187 <to_percentile+0x77>
jmp    11be <to_percentile+0xae>
movsd  0xe81(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <isinf@plt>
cmp    $0x0,%rax
je     11b9 <to_percentile+0xa9>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <to_percentile+0xc0>
jmp    1164 <to_percentile+0x54>
cvttsd2si -0x10(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_percentile>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
mov    $0xffffffff,%ebx
ja     1177 <to_percentile+0x67>
ucomisd 0xed2(%rip),%xmm0
ja     1177 <to_percentile+0x67>
mov    %rdi,%r14
mulsd  0xecd(%rip),%xmm0
nopl   0x0(%rax,%rax,1)
cvttpd2dq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1150 <to_percentile+0x40>
jnp    116e <to_percentile+0x5e>
mulsd  0xeb8(%rip),%xmm0
movapd %xmm0,(%rsp)
call   1030 <isinf@plt>
movapd (%rsp),%xmm0
test   %rax,%rax
je     1140 <to_percentile+0x30>
jmp    1177 <to_percentile+0x67>
cvttsd2si %xmm0,%eax
mov    %eax,(%r14)
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @to_percentile(double %0, i32* %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca i32*
store double %0, double* %4
store i32* %1, i32** %5
%6 = load double, double* %4
%7 = fcmp olt double %6, 0.000000e+00
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load double, double* %4
%10 = fcmp ogt double %9, 1.000000e+00
br i1 %10, label %11, label %12
11: ; preds = %8, %2
store i32 -1, i32* %3
br label %33
12: ; preds = %8
%13 = load double, double* %4
%14 = fmul double %13, 1.000000e+02
store double %14, double* %4
br label %15
15: ; preds = %28, %12
%16 = load double, double* %4
%17 = load double, double* %4
%18 = fptosi double %17 to i32
%19 = sitofp i32 %18 to double
%20 = fcmp une double %16, %19
br i1 %20, label %21, label %29
21: ; preds = %15
%22 = load double, double* %4
%23 = fmul double %22, 1.000000e+01
store double %23, double* %4
%24 = load double, double* %4
%25 = call i64 @isinf(double %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 -1, i32* %3
br label %33
28: ; preds = %21
br label %15
29: ; preds = %15
%30 = load double, double* %4
%31 = fptosi double %30 to i32
%32 = load i32*, i32** %5
store i32 %31, i32* %32
store i32 0, i32* %3
br label %33
33: ; preds = %29, %27, %11
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
define i32 @to_percentile(double %0, i32* nocapture writeonly %1) {
%3 = fcmp olt double %0, 0.000000e+00
%4 = fcmp ogt double %0, 1.000000e+00
%5 = or i1 %3, %4
br i1 %5, label %18, label %6
6: ; preds = %2
%7 = fmul double %0, 1.000000e+02
br label %8
8: ; preds = %13, %6
%9 = phi double [ %7, %6 ], [ %14, %13 ]
%10 = fptosi double %9 to i32
%11 = sitofp i32 %10 to double
%12 = fcmp une double %9, %11
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = fmul double %9, 1.000000e+01
%15 = tail call i64 @isinf(double %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %8, label %18
17: ; preds = %8
store i32 %10, i32* %1
br label %18
18: ; preds = %13, %2, %17
%19 = phi i32 [ 0, %17 ], [ -1, %2 ], [ -1, %13 ]
ret i32 %19
}