#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 M_PI;
scalar_t__ fabs(double);
double n_simpson(double, double, double);
scalar_t__ pow(int, int);
int /*<<< orphan*/ printf(char *, double, ...);
int main() {
  int dois_n = 10000;
  double intervalo_max = M_PI;
  double intervalo_min = -M_PI;
  double h;
  printf("valor de intervalo_max = %e \n", intervalo_max);
  printf("valor de intervalo_min = %e \n", intervalo_min);
  double ultimaSoma, soma;
  do {
    h = (intervalo_max - intervalo_min) / dois_n;
    ultimaSoma = n_simpson(intervalo_min, intervalo_max, h);
    h = (intervalo_max - intervalo_min) / (dois_n + 1000.0);
    soma = n_simpson(intervalo_min, intervalo_max, h);
    printf("soma = %e, ultimaSoma = %e, i = %d\n", soma, ultimaSoma, dois_n);
    printf("dif = %e\n", (soma - ultimaSoma));
    dois_n += 1000;
  } while (fabs(soma - ultimaSoma) > pow(10, -12));
  printf("Resposta: a0 = %e \n", (soma / (2 * M_PI)));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2710,-0x8(%rbp)
mov    0x2e8b(%rip),%rax
cvtsi2sdl (%rax),%xmm0
movsd  %xmm0,-0x10(%rbp)
xor    %eax,%eax
mov    0x2e79(%rip),%rcx
sub    (%rcx),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xe82(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xe8d(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1050 <n_simpson@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
movsd  0xe18(%rip),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1050 <n_simpson@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    -0x8(%rbp),%esi
lea    0xe22(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
lea    0xe2e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x3e8,%eax
mov    %eax,-0x8(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
call   1040 <fabs@plt>
mov    %rax,-0x38(%rbp)
mov    $0xa,%edi
mov    $0xfffffff4,%esi
call   1060 <pow@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jg     11a0 <main+0x60>
movsd  -0x30(%rbp),%xmm0
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
lea    0xdd4(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    0x2e94(%rip),%r13
mov    0x0(%r13),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x20(%rsp)
neg    %eax
cvtsi2sd %eax,%xmm1
movsd  %xmm1,0x10(%rsp)
lea    0xe93(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xea3(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1030 <printf@plt>
movsd  0x20(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x28(%rsp)
mov    $0x2710,%ebx
lea    0xe96(%rip),%r14
lea    0xeb3(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x28(%rsp),%xmm2
divsd  %xmm0,%xmm2
movsd  0x10(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
call   1050 <n_simpson@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  0xe04(%rip),%xmm0
movsd  0x28(%rsp),%xmm2
divsd  %xmm0,%xmm2
movsd  0x10(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
call   1050 <n_simpson@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
movsd  0x18(%rsp),%xmm1
mov    %ebx,%esi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
mov    %r15,%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x3e8,%ebx
movsd  0x18(%rsp),%xmm0
call   1040 <fabs@plt>
mov    %rax,%r12
mov    $0xa,%edi
mov    $0xfffffff4,%esi
call   1060 <pow@plt>
cmp    %rax,%r12
jg     11c0 <main+0x80>
mov    0x0(%r13),%eax
add    %eax,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
lea    0xddd(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@M_PI = global i32 0
@.str = [30 x i8] c"valor de intervalo_max = %e \0A\00"
@.str.1 = [30 x i8] c"valor de intervalo_min = %e \0A\00"
@.str.2 = [36 x i8] c"soma = %e, ultimaSoma = %e, i = %d\0A\00"
@.str.3 = [10 x i8] c"dif = %e\0A\00"
@.str.4 = [20 x i8] c"Resposta: a0 = %e \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i32 0, i32* %1
store i32 10000, i32* %2
%8 = load i32, i32* @M_PI
%9 = sitofp i32 %8 to double
store double %9, double* %3
%10 = load i32, i32* @M_PI
%11 = sub nsw i32 0, %10
%12 = sitofp i32 %11 to double
store double %12, double* %4
%13 = load double, double* %3
%14 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), double %13)
%15 = load double, double* %4
%16 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), double %15)
br label %17
17: ; preds = %49, %0
%18 = load double, double* %3
%19 = load double, double* %4
%20 = fsub double %18, %19
%21 = load i32, i32* %2
%22 = sitofp i32 %21 to double
%23 = fdiv double %20, %22
store double %23, double* %5
%24 = load double, double* %4
%25 = load double, double* %3
%26 = load double, double* %5
%27 = call double @n_simpson(double %24, double %25, double %26)
store double %27, double* %6
%28 = load double, double* %3
%29 = load double, double* %4
%30 = fsub double %28, %29
%31 = load i32, i32* %2
%32 = sitofp i32 %31 to double
%33 = fadd double %32, 1.000000e+03
%34 = fdiv double %30, %33
store double %34, double* %5
%35 = load double, double* %4
%36 = load double, double* %3
%37 = load double, double* %5
%38 = call double @n_simpson(double %35, double %36, double %37)
store double %38, double* %7
%39 = load double, double* %7
%40 = load double, double* %6
%41 = load i32, i32* %2
%42 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), double %39, double %40, i32 %41)
%43 = load double, double* %7
%44 = load double, double* %6
%45 = fsub double %43, %44
%46 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double %45)
%47 = load i32, i32* %2
%48 = add nsw i32 %47, 1000
store i32 %48, i32* %2
br label %49
49: ; preds = %17
%50 = load double, double* %7
%51 = load double, double* %6
%52 = fsub double %50, %51
%53 = call i64 @fabs(double %52)
%54 = call i64 @pow(i32 10, i32 -12)
%55 = icmp sgt i64 %53, %54
br i1 %55, label %17, label %56
56: ; preds = %49
%57 = load double, double* %7
%58 = load i32, i32* @M_PI
%59 = mul nsw i32 2, %58
%60 = sitofp i32 %59 to double
%61 = fdiv double %57, %60
%62 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), double %61)
ret i32 0
}

LLVM IR (-O2):
@M_PI = global i32 0
@.str = [30 x i8] c"valor de intervalo_max = %e \0A\00"
@.str.1 = [30 x i8] c"valor de intervalo_min = %e \0A\00"
@.str.2 = [36 x i8] c"soma = %e, ultimaSoma = %e, i = %d\0A\00"
@.str.3 = [10 x i8] c"dif = %e\0A\00"
@.str.4 = [20 x i8] c"Resposta: a0 = %e \0A\00"
define i32 @main() {
%1 = load i32, i32* @M_PI
%2 = sitofp i32 %1 to double
%3 = sub nsw i32 0, %1
%4 = sitofp i32 %3 to double
%5 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), double %2)
%6 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), double %4)
%7 = fsub double %2, %4
br label %8
8: ; preds = %8, %0
%9 = phi i32 [ 10000, %0 ], [ %19, %8 ]
%10 = sitofp i32 %9 to double
%11 = fdiv double %7, %10
%12 = tail call double @n_simpson(double %4, double %2, double %11)
%13 = fadd double %10, 1.000000e+03
%14 = fdiv double %7, %13
%15 = tail call double @n_simpson(double %4, double %2, double %14)
%16 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), double %15, double %12, i32 %9)
%17 = fsub double %15, %12
%18 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double %17)
%19 = add nuw nsw i32 %9, 1000
%20 = tail call i64 @fabs(double %17)
%21 = tail call i64 @pow(i32 10, i32 -12)
%22 = icmp sgt i64 %20, %21
br i1 %22, label %8, label %23
23: ; preds = %8
%24 = load i32, i32* @M_PI
%25 = shl nsw i32 %24, 1
%26 = sitofp i32 %25 to double
%27 = fdiv double %15, %26
%28 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), double %27)
ret i32 0
}