#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 */
double fabs(float);
double func(float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *, float *);
int main() {
  float x1, x2, x0, e;
  int k = 0;
  e = 0.0001;
  printf("Enter values of x1 and x2: ");
  do {
    scanf("%f %f", &x1, &x2);
  } while (func(x1) * func(x2) > 0);
  printf("x1 and x2 are %f %f\n", x1, x2);
  printf("Absolute value of difference :%f\n", fabs(x1 - x2));
  while (fabs(x2 - x1) > e) {
    k++;
    x0 = (x1 + x2) / 2;
    printf("%2d %f %f %f %f\n", k, func(x1), func(x2), x0, fabs(x2 - x1));
    if (func(x1) * func(x2) < 0)
      x2 = x0;
    else
      x1 = x0;
  }
  printf("Root = %f\n", x0);
  printf("No of iterations = %d\n", k);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
movss  0xea2(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <scanf@plt>
movss  -0x8(%rbp),%xmm0
call   1050 <func@plt>
movsd  %xmm0,-0x20(%rbp)
movss  -0xc(%rbp),%xmm0
call   1050 <func@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
ja     1171 <main+0x31>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe5a(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movss  -0x8(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
call   1040 <fabs@plt>
lea    0xe52(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
call   1040 <fabs@plt>
movss  -0x14(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12eb <main+0x1ab>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movss  -0x8(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  0xdd3(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
movss  -0x8(%rbp),%xmm0
call   1050 <func@plt>
movsd  %xmm0,-0x30(%rbp)
movss  -0xc(%rbp),%xmm0
call   1050 <func@plt>
movsd  %xmm0,-0x40(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
call   1040 <fabs@plt>
mov    -0x44(%rbp),%esi
movsd  -0x40(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x30(%rbp),%xmm0
lea    0xdca(%rip),%rdi
mov    $0x4,%al
call   1030 <printf@plt>
movss  -0x8(%rbp),%xmm0
call   1050 <func@plt>
movsd  %xmm0,-0x28(%rbp)
movss  -0xc(%rbp),%xmm0
call   1050 <func@plt>
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    12dc <main+0x19c>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    12e6 <main+0x1a6>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    11f4 <main+0xb4>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd77(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed6(%rip),%r14
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <scanf@plt>
movss  0xc(%rsp),%xmm0
call   1050 <func@plt>
movsd  %xmm0,0x10(%rsp)
movss  0x8(%rsp),%xmm0
call   1050 <func@plt>
mulsd  0x10(%rsp),%xmm0
ucomisd 0xe68(%rip),%xmm0
ja     1170 <main+0x30>
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  0x8(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xe75(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movss  0xc(%rsp),%xmm0
subss  0x8(%rsp),%xmm0
call   1040 <fabs@plt>
lea    0xe6b(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movss  0x8(%rsp),%xmm0
subss  0xc(%rsp),%xmm0
call   1040 <fabs@plt>
xor    %ebx,%ebx
lea    0xe6c(%rip),%r14
jmp    123c <main+0xfc>
nopw   0x0(%rax,%rax,1)
movss  0x10(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
movss  0x8(%rsp),%xmm1
subss  %xmm0,%xmm1
movaps %xmm1,%xmm0
call   1040 <fabs@plt>
ucomisd 0xdd2(%rip),%xmm0
jbe    1302 <main+0x1c2>
add    $0x1,%ebx
movss  0xc(%rsp),%xmm0
movss  0x8(%rsp),%xmm1
addss  %xmm0,%xmm1
mulss  0xda9(%rip),%xmm1
movss  %xmm1,0x10(%rsp)
call   1050 <func@plt>
movsd  %xmm0,0x18(%rsp)
movss  0x8(%rsp),%xmm0
call   1050 <func@plt>
movsd  %xmm0,0x28(%rsp)
movss  0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x20(%rsp)
movss  0x8(%rsp),%xmm0
subss  0xc(%rsp),%xmm0
call   1040 <fabs@plt>
movaps %xmm0,%xmm3
mov    %r14,%rdi
mov    %ebx,%esi
movsd  0x18(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
mov    $0x4,%al
call   1030 <printf@plt>
movss  0xc(%rsp),%xmm0
call   1050 <func@plt>
movsd  %xmm0,0x18(%rsp)
movss  0x8(%rsp),%xmm0
call   1050 <func@plt>
mulsd  0x18(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    1210 <main+0xd0>
movss  0x10(%rsp),%xmm1
movss  %xmm1,0x8(%rsp)
movss  0xc(%rsp),%xmm0
jmp    1222 <main+0xe2>
lea    0xd79(%rip),%rdi
movsd  0x20(%rsp),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xd70(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Enter values of x1 and x2: \00"
@.str.1 = [6 x i8] c"%f %f\00"
@.str.2 = [21 x i8] c"x1 and x2 are %f %f\0A\00"
@.str.3 = [34 x i8] c"Absolute value of difference :%f\0A\00"
@.str.4 = [17 x i8] c"%2d %f %f %f %f\0A\00"
@.str.5 = [11 x i8] c"Root = %f\0A\00"
@.str.6 = [23 x i8] c"No of iterations = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
store float 0x3F1A36E2E0000000, float* %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %10, %0
%9 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), float* %2, float* %3)
br label %10
10: ; preds = %8
%11 = load float, float* %2
%12 = call double @func(float %11)
%13 = load float, float* %3
%14 = call double @func(float %13)
%15 = fmul double %12, %14
%16 = fcmp ogt double %15, 0.000000e+00
br i1 %16, label %8, label %17
17: ; preds = %10
%18 = load float, float* %2
%19 = fpext float %18 to double
%20 = load float, float* %3
%21 = fpext float %20 to double
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), double %19, double %21)
%23 = load float, float* %2
%24 = load float, float* %3
%25 = fsub float %23, %24
%26 = call double @fabs(float %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), double %26)
br label %28
28: ; preds = %65, %17
%29 = load float, float* %3
%30 = load float, float* %2
%31 = fsub float %29, %30
%32 = call double @fabs(float %31)
%33 = load float, float* %5
%34 = fpext float %33 to double
%35 = fcmp ogt double %32, %34
br i1 %35, label %36, label %66
36: ; preds = %28
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
%39 = load float, float* %2
%40 = load float, float* %3
%41 = fadd float %39, %40
%42 = fdiv float %41, 2.000000e+00
store float %42, float* %4
%43 = load i32, i32* %6
%44 = load float, float* %2
%45 = call double @func(float %44)
%46 = load float, float* %3
%47 = call double @func(float %46)
%48 = load float, float* %4
%49 = fpext float %48 to double
%50 = load float, float* %3
%51 = load float, float* %2
%52 = fsub float %50, %51
%53 = call double @fabs(float %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %43, double %45, double %47, double %49, double %53)
%55 = load float, float* %2
%56 = call double @func(float %55)
%57 = load float, float* %3
%58 = call double @func(float %57)
%59 = fmul double %56, %58
%60 = fcmp olt double %59, 0.000000e+00
br i1 %60, label %61, label %63
61: ; preds = %36
%62 = load float, float* %4
store float %62, float* %3
br label %65
63: ; preds = %36
%64 = load float, float* %4
store float %64, float* %2
br label %65
65: ; preds = %63, %61
br label %28
66: ; preds = %28
%67 = load float, float* %4
%68 = fpext float %67 to double
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), double %68)
%70 = load i32, i32* %6
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %70)
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Enter values of x1 and x2: \00"
@.str.1 = [6 x i8] c"%f %f\00"
@.str.2 = [21 x i8] c"x1 and x2 are %f %f\0A\00"
@.str.3 = [34 x i8] c"Absolute value of difference :%f\0A\00"
@.str.4 = [17 x i8] c"%2d %f %f %f %f\0A\00"
@.str.5 = [11 x i8] c"Root = %f\0A\00"
@.str.6 = [23 x i8] c"No of iterations = %d\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 ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %6, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), float* %1, float* %2)
%8 = load float, float* %1
%9 = call double @func(float %8)
%10 = load float, float* %2
%11 = call double @func(float %10)
%12 = fmul double %9, %11
%13 = fcmp ogt double %12, 0.000000e+00
br i1 %13, label %6, label %14
14: ; preds = %6
%15 = load float, float* %1
%16 = fpext float %15 to double
%17 = load float, float* %2
%18 = fpext float %17 to double
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), double %16, double %18)
%20 = load float, float* %1
%21 = load float, float* %2
%22 = fsub float %20, %21
%23 = call double @fabs(float %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), double %23)
%25 = load float, float* %2
%26 = load float, float* %1
%27 = fsub float %25, %26
%28 = call double @fabs(float %27)
%29 = fcmp ogt double %28, 0x3F1A36E2E0000000
br label %30
30: ; preds = %14, %56
%31 = phi i32 [ %32, %56 ], [ 0, %14 ]
%32 = add nuw nsw i32 %31, 1
%33 = load float, float* %1
%34 = load float, float* %2
%35 = fadd float %33, %34
%36 = fmul float %35, 5.000000e-01
%37 = call double @func(float %33)
%38 = load float, float* %2
%39 = call double @func(float %38)
%40 = fpext float %36 to double
%41 = load float, float* %2
%42 = load float, float* %1
%43 = fsub float %41, %42
%44 = call double @fabs(float %43)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %32, double %37, double %39, double %40, double %44)
%46 = load float, float* %1
%47 = call double @func(float %46)
%48 = load float, float* %2
%49 = call double @func(float %48)
%50 = fmul double %47, %49
%51 = fcmp olt double %50, 0.000000e+00
br i1 %51, label %52, label %54
52: ; preds = %30
store float %36, float* %2
%53 = load float, float* %1
br label %56
54: ; preds = %30
store float %36, float* %1
%55 = load float, float* %2
br label %56
56: ; preds = %54, %52
%57 = phi float [ %36, %54 ], [ %53, %52 ]
%58 = phi float [ %55, %54 ], [ %36, %52 ]
%59 = fsub float %58, %57
%60 = call double @fabs(float %59)
%61 = fcmp ogt double %60, 0x3F1A36E2E0000000
br i1 %61, label %30, label %62
62: ; preds = %56
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), double %40)
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %32)
ret i32 0
}