#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 */
scalar_t__ FLT_EPSILON;
scalar_t__ fabs(double);
int /*<<< orphan*/ printf(char *, ...);
double read_number();
double trap(int, double, double);
int main() {
  double a = 0;
  double b = 0;
  double aprox_0 = 0;
  double aprox_1 = 0;
  int i = 1;
  int itermax = 0;
  printf("a = ");
  a = read_number();
  printf("b = ");
  b = read_number();
  printf("itermax = ");
  itermax = (int)read_number();
  do {
    aprox_0 = aprox_1;
    aprox_1 = trap(i, a, b);
    printf("%d %lf\n", i, aprox_1);
    i *= 2;
  } while (fabs(aprox_0 - aprox_1) >= FLT_EPSILON && i < itermax);
  printf("I ≈ %.5e\n", aprox_1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <read_number@plt>
movsd  %xmm0,-0x10(%rbp)
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <read_number@plt>
movsd  %xmm0,-0x18(%rbp)
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <read_number@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x2c(%rbp),%edi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1060 <trap@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
lea    0xe18(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %rax,%rcx
xor    %eax,%eax
mov    0x2db8(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x31(%rbp)
jl     1240 <main+0x100>
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
setl   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11cd <main+0x8d>
movsd  -0x28(%rbp),%xmm0
lea    0xdc6(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <read_number@plt>
movsd  %xmm0,0x18(%rsp)
lea    0xe99(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <read_number@plt>
movsd  %xmm0,0x10(%rsp)
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <read_number@plt>
cvttsd2si %xmm0,%ebp
mov    $0x1,%ebx
xorpd  %xmm0,%xmm0
lea    0xe6c(%rip),%r14
mov    0x2e30(%rip),%r15
movsd  %xmm0,0x20(%rsp)
mov    %ebx,%edi
movsd  0x18(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
call   1060 <trap@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0x20(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
call   1040 <fabs@plt>
movsd  0x8(%rsp),%xmm0
cmp    (%r15),%rax
jl     11fd <main+0xbd>
add    %ebx,%ebx
cmp    %ebp,%ebx
jl     11b0 <main+0x70>
lea    0xe19(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"a = \00"
@.str.1 = [5 x i8] c"b = \00"
@.str.2 = [11 x i8] c"itermax = \00"
@.str.3 = [8 x i8] c"%d %lf\0A\00"
@FLT_EPSILON = global i64 0
@.str.4 = [12 x i8] c"I \E2\89\88 %.5e\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
store i32 1, i32* %6
store i32 0, i32* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = call double (...) @read_number()
store double %9, double* %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = call double (...) @read_number()
store double %11, double* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%13 = call double (...) @read_number()
%14 = fptosi double %13 to i32
store i32 %14, i32* %7
br label %15
15: ; preds = %37, %0
%16 = load double, double* %5
store double %16, double* %4
%17 = load i32, i32* %6
%18 = load double, double* %2
%19 = load double, double* %3
%20 = call double @trap(i32 %17, double %18, double %19)
store double %20, double* %5
%21 = load i32, i32* %6
%22 = load double, double* %5
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %21, double %22)
%24 = load i32, i32* %6
%25 = mul nsw i32 %24, 2
store i32 %25, i32* %6
br label %26
26: ; preds = %15
%27 = load double, double* %4
%28 = load double, double* %5
%29 = fsub double %27, %28
%30 = call i64 @fabs(double %29)
%31 = load i64, i64* @FLT_EPSILON
%32 = icmp sge i64 %30, %31
br i1 %32, label %33, label %37
33: ; preds = %26
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = icmp slt i32 %34, %35
br label %37
37: ; preds = %33, %26
%38 = phi i1 [ false, %26 ], [ %36, %33 ]
br i1 %38, label %15, label %39
39: ; preds = %37
%40 = load double, double* %5
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), double %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"a = \00"
@.str.1 = [5 x i8] c"b = \00"
@.str.2 = [11 x i8] c"itermax = \00"
@.str.3 = [8 x i8] c"%d %lf\0A\00"
@FLT_EPSILON = global i64 0
@.str.4 = [12 x i8] c"I \E2\89\88 %.5e\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = tail call double (...) @read_number()
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call double (...) @read_number()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call double (...) @read_number()
%7 = fptosi double %6 to i32
br label %8
8: ; preds = %8, %0
%9 = phi double [ 0.000000e+00, %0 ], [ %11, %8 ]
%10 = phi i32 [ 1, %0 ], [ %13, %8 ]
%11 = tail call double @trap(i32 %10, double %2, double %4)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %10, double %11)
%13 = shl nsw i32 %10, 1
%14 = fsub double %9, %11
%15 = tail call i64 @fabs(double %14)
%16 = load i64, i64* @FLT_EPSILON
%17 = icmp sge i64 %15, %16
%18 = icmp slt i32 %13, %7
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %8, label %20
20: ; preds = %8
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), double %11)
ret i32 0
}