#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 fabs(float);
float fun(float n) {
  float x1 = 1, x2 = (x1 + n / x1) / 2;
  while (fabs(x2 - x1) > 1e-4) {
    x1 = x2;
    x2 = (x1 + n / x1) / 2;
  }
  return x2;
}


x86 assembly (clang, -O0):
<fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
movss  0xedf(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x4(%rbp),%xmm1
divss  -0x8(%rbp),%xmm1
addss  %xmm1,%xmm0
movss  0xebb(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe9f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11a6 <fun+0x96>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x4(%rbp),%xmm1
divss  -0x8(%rbp),%xmm1
addss  %xmm1,%xmm0
movss  0xe68(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    114e <fun+0x3e>
movss  -0xc(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun>:
push   %rax
movss  0xee7(%rip),%xmm1
movss  %xmm0,0x4(%rsp)
addss  %xmm0,%xmm1
mulss  0xed9(%rip),%xmm1
movss  0xed5(%rip),%xmm0
movss  %xmm1,(%rsp)
addss  %xmm1,%xmm0
call   1030 <fabs@plt>
test   %eax,%eax
jle    1182 <fun+0x72>
movss  (%rsp),%xmm1
nopw   0x0(%rax,%rax,1)
movss  0x4(%rsp),%xmm0
divss  %xmm1,%xmm0
addss  %xmm1,%xmm0
mulss  0xe9e(%rip),%xmm0
movss  %xmm0,(%rsp)
subss  %xmm1,%xmm0
call   1030 <fabs@plt>
movss  (%rsp),%xmm0
movaps %xmm0,%xmm1
test   %eax,%eax
jg     1150 <fun+0x40>
pop    %rax
ret
movss  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define float @fun(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca float
store float %0, float* %2
store float 1.000000e+00, float* %3
%5 = load float, float* %3
%6 = load float, float* %2
%7 = load float, float* %3
%8 = fdiv float %6, %7
%9 = fadd float %5, %8
%10 = fdiv float %9, 2.000000e+00
store float %10, float* %4
br label %11
11: ; preds = %18, %1
%12 = load float, float* %4
%13 = load float, float* %3
%14 = fsub float %12, %13
%15 = call i32 @fabs(float %14)
%16 = sitofp i32 %15 to double
%17 = fcmp ogt double %16, 1.000000e-04
br i1 %17, label %18, label %26
18: ; preds = %11
%19 = load float, float* %4
store float %19, float* %3
%20 = load float, float* %3
%21 = load float, float* %2
%22 = load float, float* %3
%23 = fdiv float %21, %22
%24 = fadd float %20, %23
%25 = fdiv float %24, 2.000000e+00
store float %25, float* %4
br label %11
26: ; preds = %11
%27 = load float, float* %4
ret float %27
}

LLVM IR (-O2):
define float @fun(float %0) {
%2 = fadd float %0, 1.000000e+00
%3 = fmul float %2, 5.000000e-01
%4 = fadd float %3, -1.000000e+00
%5 = tail call i32 @fabs(float %4)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %1, %7
%8 = phi float [ %11, %7 ], [ %3, %1 ]
%9 = fdiv float %0, %8
%10 = fadd float %8, %9
%11 = fmul float %10, 5.000000e-01
%12 = fsub float %11, %8
%13 = tail call i32 @fabs(float %12)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %7, label %15
15: ; preds = %7, %1
%16 = phi float [ %3, %1 ], [ %11, %7 ]
ret float %16
}