#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 integrateSimpson(float *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int n, count;
  printf("Insira a quantidade de intervalos>>");
  scanf("%d", &n);
  float x[n];
  for (count = 0; count <= n; count++) {
    printf("Insira um x%d>>", count);
    scanf("%f", &x[count]);
  }
  printf("A integração no intervalo [%f, %f]>> %f\n", x[0], x[n],
         integrateSimpson(x, n));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x29(%rbp)
call   1030 <printf@plt>
mov    -0x29(%rbp),%al
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11d9 <main+0xa9>
mov    -0xc(%rbp),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1191 <main+0x61>
mov    -0x28(%rbp),%rdi
movss  (%rdi),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movslq -0x8(%rbp),%rax
movss  (%rdi,%rax,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%esi
call   1040 <integrateSimpson@plt>
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
lea    0xe22(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
lea    -0x2c(%rbp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %rsp,%rbx
mov    -0x2c(%rbp),%eax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x2c(%rbp),%eax
test   %eax,%eax
js     11de <main+0xae>
mov    %rbx,-0x38(%rbp)
mov    $0xffffffffffffffff,%rbx
lea    0xe92(%rip),%r15
lea    0xe9b(%rip),%r12
mov    %r14,%r13
nop
add    $0x1,%rbx
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movslq -0x2c(%rbp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11a0 <main+0x70>
movss  (%r14),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x38(%rbp),%rbx
jmp    11de <main+0xae>
movslq %eax,%rsi
movss  (%r14,%rsi,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    %r14,%rdi
call   1040 <integrateSimpson@plt>
movaps %xmm0,%xmm2
lea    0xe38(%rip),%rdi
movsd  -0x40(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mov    $0x3,%al
call   1030 <printf@plt>
mov    %rbx,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Insira a quantidade de intervalos>>\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"Insira um x%d>>\00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [43 x i8] c"A integra\C3\A7\C3\A3o no intervalo [%f, %f]>> %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca float, i64 %9
store i64 %9, i64* %5
store i32 0, i32* %3
br label %12
12: ; preds = %23, %0
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = load i32, i32* %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds float, float* %11, i64 %20
%22 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %21)
br label %23
23: ; preds = %16
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %12
26: ; preds = %12
%27 = getelementptr inbounds float, float* %11, i64 0
%28 = load float, float* %27
%29 = fpext float %28 to double
%30 = load i32, i32* %2
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds float, float* %11, i64 %31
%33 = load float, float* %32
%34 = fpext float %33 to double
%35 = load i32, i32* %2
%36 = call double @integrateSimpson(float* %11, i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), double %29, double %34, double %36)
store i32 0, i32* %1
%38 = load i8*, i8** %4
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str = [36 x i8] c"Insira a quantidade de intervalos>>\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"Insira um x%d>>\00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [43 x i8] c"A integra\C3\A7\C3\A3o no intervalo [%f, %f]>> %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
%8 = alloca float, i64 %6
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %0, %11
%12 = phi i64 [ %17, %11 ], [ 0, %0 ]
%13 = trunc i64 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds float, float* %8, i64 %12
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %15)
%17 = add nuw nsw i64 %12, 1
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %12, %19
br i1 %20, label %11, label %21
21: ; preds = %11
%22 = load float, float* %8
%23 = fpext float %22 to double
br label %24
24: ; preds = %0, %21
%25 = phi double [ %23, %21 ], [ undef, %0 ]
%26 = phi i32 [ %18, %21 ], [ %9, %0 ]
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds float, float* %8, i64 %27
%29 = load float, float* %28
%30 = fpext float %29 to double
%31 = call double @integrateSimpson(float* %8, i32 %26)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), double %25, double %30, double %31)
ret i32 0
}