#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);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *, float *);
float simpson(float, float, int);
int main(void) {
  float a, b, i1, i2 = 0;
  int n = 2;
  printf("Enter the lower and upper bounds of the integration respectively.\n");
  scanf("%f %f", &a, &b);
  do {
    i1 = i2;
    i2 = simpson(a, b, n);
    n *= 2;
  } while (fabs(i2 - i1) >= 0.00005);
  printf("Integration of f(x) = 1/(1+x) from %.2f to %.2f is :\t%f\n", a, b,
         i2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movl   $0x2,-0x18(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed8(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <scanf@plt>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
mov    -0x18(%rbp),%edi
call   1050 <simpson@plt>
movss  %xmm0,-0x14(%rbp)
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
subss  -0x10(%rbp),%xmm0
call   1040 <fabs@plt>
movsd  0xe3f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1180 <main+0x40>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movss  -0x14(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
lea    0xe64(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
lea    0xea0(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1070 <scanf@plt>
mov    $0x2,%ebx
xorps  %xmm0,%xmm0
nopl   (%rax)
movss  %xmm0,0xc(%rsp)
movss  0x4(%rsp),%xmm0
movss  (%rsp),%xmm1
mov    %ebx,%edi
call   1060 <simpson@plt>
movss  %xmm0,0x8(%rsp)
add    %ebx,%ebx
subss  0xc(%rsp),%xmm0
call   1050 <fabs@plt>
movss  0x8(%rsp),%xmm2
ucomisd 0xe47(%rip),%xmm0
movaps %xmm2,%xmm0
jae    1180 <main+0x30>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  (%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
cvtss2sd %xmm2,%xmm2
lea    0xe32(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [67 x i8] c"Enter the lower and upper bounds of the integration respectively.\0A\00"
@.str.1 = [6 x i8] c"%f %f\00"
@.str.2 = [57 x i8] c"Integration of f(x) = 1/(1+x) from %.2f to %.2f is :\09%f\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 float 0.000000e+00, float* %5
store i32 2, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 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* %2, float* %3)
br label %9
9: ; preds = %17, %0
%10 = load float, float* %5
store float %10, float* %4
%11 = load float, float* %2
%12 = load float, float* %3
%13 = load i32, i32* %6
%14 = call float @simpson(float %11, float %12, i32 %13)
store float %14, float* %5
%15 = load i32, i32* %6
%16 = mul nsw i32 %15, 2
store i32 %16, i32* %6
br label %17
17: ; preds = %9
%18 = load float, float* %5
%19 = load float, float* %4
%20 = fsub float %18, %19
%21 = call double @fabs(float %20)
%22 = fcmp oge double %21, 5.000000e-05
br i1 %22, label %9, label %23
23: ; preds = %17
%24 = load float, float* %2
%25 = fpext float %24 to double
%26 = load float, float* %3
%27 = fpext float %26 to double
%28 = load float, float* %5
%29 = fpext float %28 to double
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), double %25, double %27, double %29)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%f %f\00"
@.str.2 = [57 x i8] c"Integration of f(x) = 1/(1+x) from %.2f to %.2f is :\09%f\0A\00"
@str = [66 x i8] c"Enter the lower and upper bounds of the integration respectively.\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 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 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 = %7, %0
%8 = phi float [ 0.000000e+00, %0 ], [ %12, %7 ]
%9 = phi i32 [ 2, %0 ], [ %13, %7 ]
%10 = load float, float* %1
%11 = load float, float* %2
%12 = call float @simpson(float %10, float %11, i32 %9)
%13 = shl nsw i32 %9, 1
%14 = fsub float %12, %8
%15 = call double @fabs(float %14)
%16 = fcmp ult double %15, 5.000000e-05
br i1 %16, label %17, label %7
17: ; preds = %7
%18 = load float, float* %1
%19 = fpext float %18 to double
%20 = load float, float* %2
%21 = fpext float %20 to double
%22 = fpext float %12 to double
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0), double %19, double %21, double %22)
ret i32 0
}