#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 */
float f(float);
double fabs(float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *, float *);
int main() {
  float x1, x2, x3, f1, f2, f3;
  int i;
  printf("Enter x1 and x2:");
  scanf("%f %f", &x1, &x2);
  do {
    f1 = f(x1);
    f2 = f(x2);
    x3 = x1 - (x2 - x1) / (f2 - f1) * f1;
    f3 = f(x3);
    if (f1 * f3 > 0) {
      x2 = x3;
    } else {
      x1 = x3;
    }
    i++;
    printf("Number of iteration %d\t root is %f\n", i, x3);
  } while (fabs(f3) > 0.001);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <scanf@plt>
movss  -0x8(%rbp),%xmm0
call   1030 <f@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
movss  -0x18(%rbp),%xmm2
subss  -0x14(%rbp),%xmm2
divss  %xmm2,%xmm0
movss  -0x14(%rbp),%xmm2
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
call   1030 <f@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    11ff <main+0xbf>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    1209 <main+0xc9>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdfa(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  -0x1c(%rbp),%xmm0
call   1050 <fabs@plt>
movsd  0xdc2(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1171 <main+0x31>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec2(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1060 <scanf@plt>
lea    0xeb2(%rip),%rbx
jmp    11b4 <main+0x74>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movss  0xc(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0x14(%rsp),%xmm0
call   1050 <fabs@plt>
add    $0x1,%ebp
ucomisd 0xe4e(%rip),%xmm0
jbe    1232 <main+0xf2>
movss  0x8(%rsp),%xmm0
call   1030 <f@plt>
movss  %xmm0,0x10(%rsp)
movss  0x4(%rsp),%xmm0
call   1030 <f@plt>
movss  0x8(%rsp),%xmm2
movss  0x4(%rsp),%xmm1
subss  %xmm2,%xmm1
movss  0x10(%rsp),%xmm3
subss  %xmm3,%xmm0
divss  %xmm0,%xmm1
mulss  %xmm3,%xmm1
subss  %xmm1,%xmm2
movss  %xmm2,0xc(%rsp)
movaps %xmm2,%xmm0
call   1030 <f@plt>
movss  0x10(%rsp),%xmm1
mulss  %xmm0,%xmm1
ucomiss 0xdf3(%rip),%xmm1
movss  %xmm0,0x14(%rsp)
jbe    1180 <main+0x40>
movss  0xc(%rsp),%xmm0
movss  %xmm0,0x4(%rsp)
jmp    118c <main+0x4c>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter x1 and x2:\00"
@.str.1 = [6 x i8] c"%f %f\00"
@.str.2 = [36 x i8] c"Number of iteration %d\09 root is %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), float* %2, float* %3)
br label %11
11: ; preds = %44, %0
%12 = load float, float* %2
%13 = call float @f(float %12)
store float %13, float* %5
%14 = load float, float* %3
%15 = call float @f(float %14)
store float %15, float* %6
%16 = load float, float* %2
%17 = load float, float* %3
%18 = load float, float* %2
%19 = fsub float %17, %18
%20 = load float, float* %6
%21 = load float, float* %5
%22 = fsub float %20, %21
%23 = fdiv float %19, %22
%24 = load float, float* %5
%25 = fneg float %23
%26 = call float @llvm.fmuladd.f32(float %25, float %24, float %16)
store float %26, float* %4
%27 = load float, float* %4
%28 = call float @f(float %27)
store float %28, float* %7
%29 = load float, float* %5
%30 = load float, float* %7
%31 = fmul float %29, %30
%32 = fcmp ogt float %31, 0.000000e+00
br i1 %32, label %33, label %35
33: ; preds = %11
%34 = load float, float* %4
store float %34, float* %3
br label %37
35: ; preds = %11
%36 = load float, float* %4
store float %36, float* %2
br label %37
37: ; preds = %35, %33
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = load float, float* %4
%42 = fpext float %41 to double
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %40, double %42)
br label %44
44: ; preds = %37
%45 = load float, float* %7
%46 = call double @fabs(float %45)
%47 = fcmp ogt double %46, 1.000000e-03
br i1 %47, label %11, label %48
48: ; preds = %44
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter x1 and x2:\00"
@.str.1 = [6 x i8] c"%f %f\00"
@.str.2 = [36 x i8] c"Number of iteration %d\09 root is %f\0A\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = bitcast float* %1 to i8*
%4 = bitcast float* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), float* %1, float* %2)
br label %7
7: ; preds = %25, %0
%8 = phi i32 [ undef, %0 ], [ %26, %25 ]
%9 = load float, float* %1
%10 = call float @f(float %9)
%11 = load float, float* %2
%12 = call float @f(float %11)
%13 = load float, float* %1
%14 = load float, float* %2
%15 = fsub float %14, %13
%16 = fsub float %12, %10
%17 = fneg float %15
%18 = fdiv float %17, %16
%19 = call float @llvm.fmuladd.f32(float %18, float %10, float %13)
%20 = call float @f(float %19)
%21 = fmul float %10, %20
%22 = fcmp ogt float %21, 0.000000e+00
br i1 %22, label %23, label %24
23: ; preds = %7
store float %19, float* %2
br label %25
24: ; preds = %7
store float %19, float* %1
br label %25
25: ; preds = %24, %23
%26 = add nsw i32 %8, 1
%27 = fpext float %19 to double
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %26, double %27)
%29 = call double @fabs(float %20)
%30 = fcmp ogt double %29, 1.000000e-03
br i1 %30, label %7, label %31
31: ; preds = %25
ret i32 0
}