#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);
float fabs(float);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  float e = 0.0001, r1, r2, x;
  int i, n;
  printf("Enter approximation ranges");
  scanf("%f%f", &r1, &r2);
  while (f(++r1) < 0)
    ;
  float a, b;
  a = r1;
  b = r1 + 1;
  printf("Enter n\n");
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    x = (b * f(a) - a * f(b)) / (f(a) - f(b));
    if (f(b) * f(x) < 0)
      a = x;
    else
      b = x;
    printf("%f ------ %f\n", x, f(x));
    if (fabs(a - b) <= e)
      break;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movss  0xea9(%rip),%xmm0
movss  %xmm0,-0x8(%rbp)
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb2(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
movss  0xe7c(%rip),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
call   1030 <f@plt>
movaps %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11ac <main+0x6c>
jmp    1180 <main+0x40>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  0xe46(%rip),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe54(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    134f <main+0x20f>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movss  -0x20(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x50(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movss  -0x24(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x58(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movss  -0x20(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x40(%rbp)
movss  -0x24(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x24(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x30(%rbp)
movss  -0x14(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    12df <main+0x19f>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
jmp    12e9 <main+0x1a9>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movss  -0x14(%rbp),%xmm0
call   1030 <f@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
lea    0xd24(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movss  -0x20(%rbp),%xmm0
subss  -0x24(%rbp),%xmm0
call   1050 <fabs@plt>
movaps %xmm0,%xmm1
movss  -0x8(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     133c <main+0x1fc>
jmp    134f <main+0x20f>
jmp    1341 <main+0x201>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ef <main+0xaf>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0xeda(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xee7(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x34(%rsp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
nopl   (%rax)
movss  0x14(%rsp),%xmm0
addss  0xe82(%rip),%xmm0
movss  %xmm0,0x14(%rsp)
call   1040 <f@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1170 <main+0x30>
movss  0x14(%rsp),%xmm0
movss  %xmm0,(%rsp)
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
lea    0xe97(%rip),%rdi
lea    0x24(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0x24(%rsp)
jle    1326 <main+0x1e6>
movss  0xe30(%rip),%xmm0
addss  (%rsp),%xmm0
mov    $0x1,%ebx
lea    0xe6a(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  %xmm0,0x4(%rsp)
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movss  (%rsp),%xmm0
call   1040 <f@plt>
movsd  %xmm0,0x18(%rsp)
movss  (%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x28(%rsp)
movss  0x4(%rsp),%xmm0
call   1040 <f@plt>
mulsd  0x28(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movss  (%rsp),%xmm0
call   1040 <f@plt>
movsd  %xmm0,0x8(%rsp)
movss  0x4(%rsp),%xmm0
call   1040 <f@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x18(%rsp)
movss  0x4(%rsp),%xmm0
call   1040 <f@plt>
movsd  %xmm0,0x8(%rsp)
movss  0x18(%rsp),%xmm0
call   1040 <f@plt>
mulsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
movss  0x18(%rsp),%xmm0
movaps %xmm0,%xmm1
ja     12bf <main+0x17f>
movss  (%rsp),%xmm1
movss  %xmm0,0x4(%rsp)
movss  %xmm1,(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
call   1040 <f@plt>
movaps %xmm0,%xmm1
mov    %r14,%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x2,%al
call   1050 <printf@plt>
movss  (%rsp),%xmm3
movaps %xmm3,%xmm0
movss  0x4(%rsp),%xmm2
subss  %xmm2,%xmm0
andps  0xd0e(%rip),%xmm0
movss  0xcfa(%rip),%xmm1
ucomiss %xmm0,%xmm1
jae    1326 <main+0x1e6>
movaps %xmm2,%xmm0
lea    0x1(%rbx),%eax
movss  %xmm3,(%rsp)
cmp    0x24(%rsp),%ebx
mov    %eax,%ebx
jl     11f0 <main+0xb0>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [27 x i8] c"Enter approximation ranges\00"
@.str.1 = [5 x i8] c"%f%f\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [14 x i8] c"%f ------ %f\0A\00"
@str = [8 x i8] c"Enter n\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = alloca i32
%4 = bitcast float* %1 to i8*
%5 = bitcast float* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), float* %1, float* %2)
br label %9
9: ; preds = %9, %0
%10 = load float, float* %1
%11 = fadd float %10, 1.000000e+00
store float %11, float* %1
%12 = call double @f(float %11)
%13 = fcmp olt double %12, 0.000000e+00
br i1 %13, label %9, label %14
14: ; preds = %9
%15 = load float, float* %1
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %54
20: ; preds = %14
%21 = fadd float %15, 1.000000e+00
br label %22
22: ; preds = %22, %20
%23 = phi float [ %21, %20 ], [ %43, %22 ]
%24 = phi float [ %15, %20 ], [ %42, %22 ]
%25 = phi i32 [ 0, %20 ], [ %50, %22 ]
%26 = fpext float %23 to double
%27 = call double @f(float %24)
%28 = fpext float %24 to double
%29 = call double @f(float %23)
%30 = fneg double %29
%31 = fmul double %28, %30
%32 = call double @llvm.fmuladd.f64(double %26, double %27, double %31)
%33 = call double @f(float %24)
%34 = call double @f(float %23)
%35 = fsub double %33, %34
%36 = fdiv double %32, %35
%37 = fptrunc double %36 to float
%38 = call double @f(float %23)
%39 = call double @f(float %37)
%40 = fmul double %38, %39
%41 = fcmp olt double %40, 0.000000e+00
%42 = select i1 %41, float %37, float %24
%43 = select i1 %41, float %23, float %37
%44 = fpext float %37 to double
%45 = call double @f(float %37)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), double %44, double %45)
%47 = fsub float %42, %43
%48 = call float @llvm.fabs.f32(float %47)
%49 = fcmp ugt float %48, 0x3F1A36E2E0000000
%50 = add nuw nsw i32 %25, 1
%51 = load i32, i32* %3
%52 = icmp slt i32 %50, %51
%53 = select i1 %49, i1 %52, i1 false
br i1 %53, label %22, label %54
54: ; preds = %22, %14
ret i32 0
}