#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 /*<<< orphan*/ ft_putchar(char);
int /*<<< orphan*/ ft_putnbr(int);
int ft_sqrt(int nb) {
  int x;
  int min;
  int max;
  int n;
  min = 0;
  max = nb;
  n = 50;
  while (n > 0) {
    ft_putnbr(x);
    ft_putchar('\n');
    x = (max + min) / 2;
    if ((x * x) > nb)
      max = x;
    if ((x * x) < nb)
      min = x;
    if ((x * x) == nb)
      return (x);
    n--;
  }
  return (0);
}


x86 assembly (clang, -O0):
<ft_sqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x32,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11c1 <ft_sqrt+0xa1>
mov    -0xc(%rbp),%edi
call   1040 <ft_putnbr@plt>
mov    $0xa,%edi
call   1030 <ft_putchar@plt>
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jle    1182 <ft_sqrt+0x62>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1198 <ft_sqrt+0x78>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11b3 <ft_sqrt+0x93>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c8 <ft_sqrt+0xa8>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    113f <ft_sqrt+0x1f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
LLVM IR (-O0):
define i32 @ft_sqrt(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
%8 = load i32, i32* %3
store i32 %8, i32* %6
store i32 50, i32* %7
br label %9
9: ; preds = %43, %1
%10 = load i32, i32* %7
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %46
12: ; preds = %9
%13 = load i32, i32* %4
%14 = call i32 @ft_putnbr(i32 %13)
%15 = call i32 @ft_putchar(i8 signext 10)
%16 = load i32, i32* %6
%17 = load i32, i32* %5
%18 = add nsw i32 %16, %17
%19 = sdiv i32 %18, 2
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = load i32, i32* %4
%22 = mul nsw i32 %20, %21
%23 = load i32, i32* %3
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %12
%26 = load i32, i32* %4
store i32 %26, i32* %6
br label %27
27: ; preds = %25, %12
%28 = load i32, i32* %4
%29 = load i32, i32* %4
%30 = mul nsw i32 %28, %29
%31 = load i32, i32* %3
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = load i32, i32* %4
store i32 %34, i32* %5
br label %35
35: ; preds = %33, %27
%36 = load i32, i32* %4
%37 = load i32, i32* %4
%38 = mul nsw i32 %36, %37
%39 = load i32, i32* %3
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = load i32, i32* %4
store i32 %42, i32* %2
br label %47
43: ; preds = %35
%44 = load i32, i32* %7
%45 = add nsw i32 %44, -1
store i32 %45, i32* %7
br label %9
46: ; preds = %9
store i32 0, i32* %2
br label %47
47: ; preds = %46, %41
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):