#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 */
int fabs(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stdout;
double Integration(double (*f)(double),
                   double (*method)(double (*f)(double), double, double, int),
                   double a, double b) {
  int i = 2;
  double integral1 = 0.0, integral2 = 0.0;
  integral1 = method(f, a, b, 1);
  while ((fabs(integral1 - integral2) > 1e-9) && (i < 200)) {
    i++;
    integral1 = integral2;
    integral2 = method(f, a, b, i);
  }
  fprintf(stdout, "Approximation to integral %f\n", integral2);
  if (i >= 200)
    fprintf(stdout, "Desired accuracy not achieved\n");
  return integral2;
}


x86 assembly (clang, -O0):
<Integration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movl   $0x2,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    $0x1,%esi
call   *%rax
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm0
xor    %eax,%eax
movsd  0xe74(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x39(%rbp)
jbe    11a6 <Integration+0x86>
cmpl   $0xc8,-0x24(%rbp)
setl   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11b6 <Integration+0x96>
jmp    11ea <Integration+0xca>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    -0x24(%rbp),%esi
call   *%rax
movsd  %xmm0,-0x38(%rbp)
jmp    116f <Integration+0x4f>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
movsd  -0x38(%rbp),%xmm0
lea    0xe09(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
cmpl   $0xc8,-0x24(%rbp)
jl     122a <Integration+0x10a>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movsd  -0x38(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Integration>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x1,%ebp
movsd  %xmm0,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
mov    $0x1,%esi
call   *%r14
call   1030 <fabs@plt>
test   %eax,%eax
jle    11df <Integration+0xbf>
xorps  %xmm0,%xmm0
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x18(%rsp)
mov    %ebp,%esi
lea    0x1(%rsi),%ebp
add    $0x2,%esi
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
call   *%r14
movapd %xmm0,%xmm1
movsd  %xmm0,(%rsp)
movsd  0x18(%rsp),%xmm0
subsd  %xmm1,%xmm0
call   1030 <fabs@plt>
movsd  (%rsp),%xmm0
cmp    $0xc6,%ebp
ja     11a9 <Integration+0x89>
test   %eax,%eax
jg     1160 <Integration+0x40>
mov    0x2e30(%rip),%rbx
mov    (%rbx),%edi
lea    0xe47(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
cmp    $0xc7,%ebp
jb     11d8 <Integration+0xb8>
mov    (%rbx),%edi
lea    0xe4d(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
movsd  (%rsp),%xmm0
jmp    11fc <Integration+0xdc>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
xorps  %xmm0,%xmm0
mov    $0x1,%al
call   1040 <fprintf@plt>
xorps  %xmm0,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [30 x i8] c"Approximation to integral %f\0A\00"
@.str.1 = [31 x i8] c"Desired accuracy not achieved\0A\00"
define double @Integration(double (double)* %0, double (double (double)*, double, double, i32)* %1, double %2, double %3) {
%5 = alloca double (double)*
%6 = alloca double (double (double)*, double, double, i32)*
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca double
%11 = alloca double
store double (double)* %0, double (double)** %5
store double (double (double)*, double, double, i32)* %1, double (double (double)*, double, double, i32)** %6
store double %2, double* %7
store double %3, double* %8
store i32 2, i32* %9
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %11
%12 = load double (double (double)*, double, double, i32)*, double (double (double)*, double, double, i32)** %6
%13 = load double (double)*, double (double)** %5
%14 = load double, double* %7
%15 = load double, double* %8
%16 = call double %12(double (double)* %13, double %14, double %15, i32 1)
store double %16, double* %10
br label %17
17: ; preds = %29, %4
%18 = load double, double* %10
%19 = load double, double* %11
%20 = fsub double %18, %19
%21 = call i32 @fabs(double %20)
%22 = sitofp i32 %21 to double
%23 = fcmp ogt double %22, 1.000000e-09
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i32, i32* %9
%26 = icmp slt i32 %25, 200
br label %27
27: ; preds = %24, %17
%28 = phi i1 [ false, %17 ], [ %26, %24 ]
br i1 %28, label %29, label %39
29: ; preds = %27
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
store i32 %31, i32* %9
%32 = load double, double* %11
store double %32, double* %10
%33 = load double (double (double)*, double, double, i32)*, double (double (double)*, double, double, i32)** %6
%34 = load double (double)*, double (double)** %5
%35 = load double, double* %7
%36 = load double, double* %8
%37 = load i32, i32* %9
%38 = call double %33(double (double)* %34, double %35, double %36, i32 %37)
store double %38, double* %11
br label %17
39: ; preds = %27
%40 = load i32, i32* @stdout
%41 = load double, double* %11
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), double %41)
%43 = load i32, i32* %9
%44 = icmp sge i32 %43, 200
br i1 %44, label %45, label %48
45: ; preds = %39
%46 = load i32, i32* @stdout
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %48
48: ; preds = %45, %39
%49 = load double, double* %11
ret double %49
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [30 x i8] c"Approximation to integral %f\0A\00"
@.str.1 = [31 x i8] c"Desired accuracy not achieved\0A\00"
define double @Integration(double (double)* %0, double (double (double)*, double, double, i32)* nocapture %1, double %2, double %3) {
%5 = tail call double %1(double (double)* %0, double %2, double %3, i32 1)
%6 = tail call i32 @fabs(double %5)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = load i32, i32* @stdout
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), double 0.000000e+00)
br label %28
11: ; preds = %4, %11
%12 = phi double [ %15, %11 ], [ 0.000000e+00, %4 ]
%13 = phi i32 [ %14, %11 ], [ 2, %4 ]
%14 = add nuw nsw i32 %13, 1
%15 = tail call double %1(double (double)* %0, double %2, double %3, i32 %14)
%16 = fsub double %12, %15
%17 = tail call i32 @fabs(double %16)
%18 = icmp sgt i32 %17, 0
%19 = icmp ult i32 %13, 199
%20 = and i1 %19, %18
br i1 %20, label %11, label %21
21: ; preds = %11
%22 = icmp ugt i32 %13, 198
%23 = load i32, i32* @stdout
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), double %15)
br i1 %22, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* @stdout
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %8, %25, %21
%29 = phi double [ 0.000000e+00, %8 ], [ %15, %25 ], [ %15, %21 ]
ret double %29
}