#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 f(float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *, float *);
void main() {
  int i = 0;
  float newmid = 0, mid = 0, a = 0, b = 0;
  do {
    printf("Enter values of interval:");
    scanf("%f %f", &a, &b);
  } while (f(a) * f(b) > 0);
  do {
    mid = (a + b) / 2;
    printf("mid = %f newmid = %f i= %d and f(mid) = %f\n", mid, newmid, i,
           f(mid));
    if (mid == newmid)
      break;
    else if (f(a) * f(mid) < 0)
      b = mid;
    else if (f(mid) * f(b) < 0)
      a = mid;
    newmid = mid;
    i++;
  } while (f(mid) != 0);
  printf("The Interval is [%f, %f]\n", a, b);
  printf("Root of f(x) is : %f\n", mid);
  printf("No of iterations: %d\n", i);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeaa(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <scanf@plt>
movss  -0x10(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x20(%rbp)
movss  -0x14(%rbp),%xmm0
call   1030 <f@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
ja     115f <main+0x2f>
jmp    11b8 <main+0x88>
movss  -0x10(%rbp),%xmm0
addss  -0x14(%rbp),%xmm0
movss  0xe36(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x38(%rbp),%xmm1
mov    -0x2c(%rbp),%esi
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
lea    0xe0e(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
movss  -0xc(%rbp),%xmm0
ucomiss -0x8(%rbp),%xmm0
jne    1237 <main+0x107>
jp     1237 <main+0x107>
jmp    12e8 <main+0x1b8>
movss  -0x10(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x40(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1275 <main+0x145>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    12b3 <main+0x183>
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x48(%rbp)
movss  -0x14(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    12ae <main+0x17e>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    12b3 <main+0x183>
jmp    12b8 <main+0x188>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
movss  -0xc(%rbp),%xmm0
call   1030 <f@plt>
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b8 <main+0x88>
jp     11b8 <main+0x88>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x14(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd4f(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd52(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%esi
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
lea    0xebf(%rip),%r14
lea    0xed2(%rip),%r15
lea    0x4(%rsp),%r12
mov    %rsp,%rbx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <scanf@plt>
movss  0x4(%rsp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,0x8(%rsp)
movss  (%rsp),%xmm0
call   1030 <f@plt>
mulsd  0x8(%rsp),%xmm0
ucomisd 0xe67(%rip),%xmm0
ja     1160 <main+0x30>
xorpd  %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
xor    %ebx,%ebx
lea    0xe7a(%rip),%r14
jmp    11e9 <main+0xb9>
nopl   0x0(%rax,%rax,1)
movss  0x8(%rsp),%xmm0
movss  %xmm0,(%rsp)
add    $0x1,%ebx
movss  0x8(%rsp),%xmm0
call   1030 <f@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11e9 <main+0xb9>
jnp    12c4 <main+0x194>
movss  0x8(%rsp),%xmm1
movss  %xmm1,0x10(%rsp)
movss  0x4(%rsp),%xmm0
addss  (%rsp),%xmm0
mulss  0xdf8(%rip),%xmm0
movss  %xmm0,0x8(%rsp)
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
movsd  %xmm2,0x18(%rsp)
cvtss2sd %xmm1,%xmm1
movsd  %xmm1,0x20(%rsp)
call   1030 <f@plt>
movaps %xmm0,%xmm2
mov    %r14,%rdi
movsd  0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
mov    %ebx,%esi
mov    $0x3,%al
call   1040 <printf@plt>
movss  0x8(%rsp),%xmm0
ucomiss 0x10(%rsp),%xmm0
jne    1254 <main+0x124>
jnp    12c4 <main+0x194>
movss  0x4(%rsp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,0x10(%rsp)
movss  0x8(%rsp),%xmm0
call   1030 <f@plt>
mulsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     11c0 <main+0x90>
movss  0x8(%rsp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,0x10(%rsp)
movss  (%rsp),%xmm0
call   1030 <f@plt>
mulsd  0x10(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    11cb <main+0x9b>
movss  0x8(%rsp),%xmm0
movss  %xmm0,0x4(%rsp)
jmp    11cb <main+0x9b>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  (%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
lea    0xd7e(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
lea    0xd8a(%rip),%rdi
movsd  0x18(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xd8c(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [26 x i8] c"Enter values of interval:\00"
@.str.1 = [6 x i8] c"%f %f\00"
@.str.2 = [44 x i8] c"mid = %f newmid = %f i= %d and f(mid) = %f\0A\00"
@.str.3 = [26 x i8] c"The Interval is [%f, %f]\0A\00"
@.str.4 = [22 x i8] c"Root of f(x) is : %f\0A\00"
@.str.5 = [22 x i8] c"No of iterations: %d\0A\00"
define void @main() {
%1 = alloca float
%2 = alloca float
%3 = bitcast float* %1 to i8*
store float 0.000000e+00, float* %1
%4 = bitcast float* %2 to i8*
store float 0.000000e+00, float* %2
br label %5
5: ; preds = %5, %0
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 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 @f(float %8)
%10 = load float, float* %2
%11 = call double @f(float %10)
%12 = fmul double %9, %11
%13 = fcmp ogt double %12, 0.000000e+00
br i1 %13, label %5, label %14
14: ; preds = %5, %40
%15 = phi i32 [ %41, %40 ], [ 0, %5 ]
%16 = phi float [ %20, %40 ], [ 0.000000e+00, %5 ]
%17 = load float, float* %1
%18 = load float, float* %2
%19 = fadd float %17, %18
%20 = fmul float %19, 5.000000e-01
%21 = fpext float %20 to double
%22 = fpext float %16 to double
%23 = call double @f(float %20)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), double %21, double %22, i32 %15, double %23)
%25 = fcmp oeq float %20, %16
br i1 %25, label %44, label %26
26: ; preds = %14
%27 = load float, float* %1
%28 = call double @f(float %27)
%29 = call double @f(float %20)
%30 = fmul double %28, %29
%31 = fcmp olt double %30, 0.000000e+00
br i1 %31, label %32, label %33
32: ; preds = %26
store float %20, float* %2
br label %40
33: ; preds = %26
%34 = call double @f(float %20)
%35 = load float, float* %2
%36 = call double @f(float %35)
%37 = fmul double %34, %36
%38 = fcmp olt double %37, 0.000000e+00
br i1 %38, label %39, label %40
39: ; preds = %33
store float %20, float* %1
br label %40
40: ; preds = %32, %39, %33
%41 = add nuw nsw i32 %15, 1
%42 = call double @f(float %20)
%43 = fcmp une double %42, 0.000000e+00
br i1 %43, label %14, label %44
44: ; preds = %14, %40
%45 = phi i32 [ %15, %14 ], [ %41, %40 ]
%46 = load float, float* %1
%47 = fpext float %46 to double
%48 = load float, float* %2
%49 = fpext float %48 to double
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), double %47, double %49)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), double %21)
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %45)
ret void
}