#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 */
int FixedDiv(int, int);
int fsqrt(int number) {
  int samples = 15;
  if (number == 1.0)
    return 1.0;
  if (number <= 0)
    return 0;
  int val = samples << 17 + samples << 19;
  for (int i = 0; i < samples; ++i)
    val = (val + FixedDiv(number, val)) >> 1;
  return val;
}


x86 assembly (clang, -O0):
<fsqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0xf,-0xc(%rbp)
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  0xed1(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    114b <fsqrt+0x3b>
jp     114b <fsqrt+0x3b>
movl   $0x1,-0x4(%rbp)
jmp    11b7 <fsqrt+0xa7>
cmpl   $0x0,-0x8(%rbp)
jg     1161 <fsqrt+0x51>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <fsqrt+0xa7>
mov    -0xc(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    $0x11,%ecx
shl    %cl,%eax
shl    $0x13,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b1 <fsqrt+0xa1>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <FixedDiv@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
sar    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1179 <fsqrt+0x69>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsqrt>:
mov    $0x1,%eax
cmp    $0x1,%edi
je     1187 <fsqrt+0x77>
jl     1188 <fsqrt+0x78>
push   %rbx
mov    %edi,%ebx
call   1030 <FixedDiv@plt>
mov    %ebx,%edi
call   1030 <FixedDiv@plt>
mov    %ebx,%edi
call   1030 <FixedDiv@plt>
mov    %ebx,%edi
call   1030 <FixedDiv@plt>
mov    %ebx,%edi
call   1030 <FixedDiv@plt>
mov    %ebx,%edi
call   1030 <FixedDiv@plt>
mov    %ebx,%edi
call   1030 <FixedDiv@plt>
mov    %ebx,%edi
call   1030 <FixedDiv@plt>
mov    %ebx,%edi
call   1030 <FixedDiv@plt>
mov    %ebx,%edi
call   1030 <FixedDiv@plt>
mov    %ebx,%edi
call   1030 <FixedDiv@plt>
mov    %ebx,%edi
call   1030 <FixedDiv@plt>
mov    %ebx,%edi
call   1030 <FixedDiv@plt>
mov    %ebx,%edi
call   1030 <FixedDiv@plt>
mov    %ebx,%edi
call   1030 <FixedDiv@plt>
pop    %rbx
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @fsqrt(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 15, i32* %4
%7 = load i32, i32* %3
%8 = sitofp i32 %7 to double
%9 = fcmp oeq double %8, 1.000000e+00
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 1, i32* %2
br label %37
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 0, i32* %2
br label %37
15: ; preds = %11
%16 = load i32, i32* %4
%17 = load i32, i32* %4
%18 = add nsw i32 17, %17
%19 = shl i32 %16, %18
%20 = shl i32 %19, 19
store i32 %20, i32* %5
store i32 0, i32* %6
br label %21
21: ; preds = %32, %15
%22 = load i32, i32* %6
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = load i32, i32* %5
%27 = load i32, i32* %3
%28 = load i32, i32* %5
%29 = call i32 @FixedDiv(i32 %27, i32 %28)
%30 = add nsw i32 %26, %29
%31 = ashr i32 %30, 1
store i32 %31, i32* %5
br label %32
32: ; preds = %25
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %21
35: ; preds = %21
%36 = load i32, i32* %5
store i32 %36, i32* %2
br label %37
37: ; preds = %35, %14, %10
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @fsqrt(i32 %0) {
%2 = icmp eq i32 %0, 1
br i1 %2, label %21, label %3
3: ; preds = %1
%4 = icmp slt i32 %0, 1
br i1 %4, label %21, label %5
5: ; preds = %3
%6 = tail call i32 @FixedDiv(i32 %0, i32 poison)
%7 = tail call i32 @FixedDiv(i32 %0, i32 poison)
%8 = tail call i32 @FixedDiv(i32 %0, i32 poison)
%9 = tail call i32 @FixedDiv(i32 %0, i32 poison)
%10 = tail call i32 @FixedDiv(i32 %0, i32 poison)
%11 = tail call i32 @FixedDiv(i32 %0, i32 poison)
%12 = tail call i32 @FixedDiv(i32 %0, i32 poison)
%13 = tail call i32 @FixedDiv(i32 %0, i32 poison)
%14 = tail call i32 @FixedDiv(i32 %0, i32 poison)
%15 = tail call i32 @FixedDiv(i32 %0, i32 poison)
%16 = tail call i32 @FixedDiv(i32 %0, i32 poison)
%17 = tail call i32 @FixedDiv(i32 %0, i32 poison)
%18 = tail call i32 @FixedDiv(i32 %0, i32 poison)
%19 = tail call i32 @FixedDiv(i32 %0, i32 poison)
%20 = tail call i32 @FixedDiv(i32 %0, i32 poison)
br label %21
21: ; preds = %5, %3, %1
%22 = phi i32 [ 1, %1 ], [ 0, %3 ], [ poison, %5 ]
ret i32 %22
}