#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 */
long double sqrt(long double);
int arrangeCoins(int n) {
  if (n <= 0)
    return 0;
  long double f =
      sqrt((long double)n + 0.125) * sqrt((long double)2.0) - (long double)1.5;
  int i = (int)f;
  i = f == (long double)i ? i : (i + 1);
  return i;
}


x86 assembly (clang, -O0):
<arrangeCoins>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1131 <arrangeCoins+0x21>
movl   $0x0,-0x4(%rbp)
jmp    11d4 <arrangeCoins+0xc4>
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
fildl  -0x30(%rbp)
flds   0xec0(%rip)
faddp  %st,%st(1)
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <sqrt@plt>
fstpt  -0x40(%rbp)
mov    %rsp,%rax
flds   0xeac(%rip)
fstpt  (%rax)
call   1030 <sqrt@plt>
fldt   -0x40(%rbp)
fmulp  %st,%st(1)
flds   0xe9e(%rip)
faddp  %st,%st(1)
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
fnstcw -0x32(%rbp)
movzwl -0x32(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x34(%rbp)
fldcw  -0x34(%rbp)
fistpl -0x2c(%rbp)
fldcw  -0x32(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
fldt   -0x20(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
fildl  -0x28(%rbp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    11bf <arrangeCoins+0xaf>
jp     11bf <arrangeCoins+0xaf>
jmp    11b4 <arrangeCoins+0xa4>
mov    -0x24(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    11c8 <arrangeCoins+0xb8>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arrangeCoins>:
test   %edi,%edi
jle    119b <arrangeCoins+0x8b>
sub    $0x28,%rsp
mov    %edi,0x24(%rsp)
fildl  0x24(%rsp)
fadds  0xed6(%rip)
fld    %st(0)
fsqrt
fldz
fxch   %st(2)
fucomi %st(2),%st
fstp   %st(2)
jae    1146 <arrangeCoins+0x36>
fstp   %st(0)
fstpt  (%rsp)
call   1030 <sqrt@plt>
fldz
fxch   %st(1)
fstp   %st(1)
flds   0xeb6(%rip)
fsqrt
fmulp  %st,%st(1)
fadds  0xeb0(%rip)
fnstcw 0x18(%rsp)
movzwl 0x18(%rsp),%eax
or     $0xc00,%eax
mov    %ax,0x1a(%rsp)
fldcw  0x1a(%rsp)
fistl  0x1c(%rsp)
fldcw  0x18(%rsp)
mov    0x1c(%rsp),%ecx
mov    %ecx,0x20(%rsp)
fildl  0x20(%rsp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
setp   %al
setne  %dl
or     %al,%dl
movzbl %dl,%eax
add    %ecx,%eax
add    $0x28,%rsp
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @arrangeCoins(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca x86_fp80
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp sle i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %30
9: ; preds = %1
%10 = load i32, i32* %3
%11 = sitofp i32 %10 to x86_fp80
%12 = fadd x86_fp80 %11, 0xK3FFC8000000000000000
%13 = call x86_fp80 @sqrt(x86_fp80 %12)
%14 = call x86_fp80 @sqrt(x86_fp80 0xK40008000000000000000)
%15 = call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %13, x86_fp80 %14, x86_fp80 0xKBFFFC000000000000000)
store x86_fp80 %15, x86_fp80* %4
%16 = load x86_fp80, x86_fp80* %4
%17 = fptosi x86_fp80 %16 to i32
store i32 %17, i32* %5
%18 = load x86_fp80, x86_fp80* %4
%19 = load i32, i32* %5
%20 = sitofp i32 %19 to x86_fp80
%21 = fcmp oeq x86_fp80 %18, %20
br i1 %21, label %22, label %24
22: ; preds = %9
%23 = load i32, i32* %5
br label %27
24: ; preds = %9
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
br label %27
27: ; preds = %24, %22
%28 = phi i32 [ %23, %22 ], [ %26, %24 ]
store i32 %28, i32* %5
%29 = load i32, i32* %5
store i32 %29, i32* %2
br label %30
30: ; preds = %27, %8
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @arrangeCoins(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = sitofp i32 %0 to x86_fp80
%5 = fadd x86_fp80 %4, 0xK3FFC8000000000000000
%6 = tail call x86_fp80 @sqrt(x86_fp80 %5)
%7 = tail call x86_fp80 @sqrt(x86_fp80 0xK40008000000000000000)
%8 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %6, x86_fp80 %7, x86_fp80 0xKBFFFC000000000000000)
%9 = fptosi x86_fp80 %8 to i32
%10 = sitofp i32 %9 to x86_fp80
%11 = fcmp une x86_fp80 %8, %10
%12 = zext i1 %11 to i32
%13 = add nsw i32 %12, %9
br label %14
14: ; preds = %1, %3
%15 = phi i32 [ %13, %3 ], [ 0, %1 ]
ret i32 %15
}