#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
float add(float *, float, int);
int /*<<< orphan*/ free(float *);
int /*<<< orphan*/ generate(float *, int, int /*<<< orphan*/ *);
int getsize(int /*<<< orphan*/ *);
float getspace(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, float);
int integrate(FILE *fp) {
  int size = getsize(fp);
  float *array = (float *)malloc(size * sizeof(float));
  float delta = getspace(fp);
  float soln;
  generate(array, size, fp);
  float sum = add(array, delta, size);
  printf("Integral: %f\n", sum);
  free(array);
  return 1;
}


x86 assembly (clang, -O0):
<integrate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <getsize@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <getspace@plt>
movss  %xmm0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1090 <generate@plt>
mov    -0x18(%rbp),%rdi
movss  -0x1c(%rbp),%xmm0
mov    -0xc(%rbp),%esi
call   1040 <add@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
lea    0xe25(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<integrate>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1080 <getsize@plt>
mov    %eax,%r14d
lea    0x0(,%r14,4),%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <getspace@plt>
movss  %xmm0,0xc(%rsp)
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1090 <generate@plt>
mov    %r15,%rdi
movss  0xc(%rsp),%xmm0
mov    %r14d,%esi
call   1040 <add@plt>
lea    0xe38(%rip),%rdi
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Integral: %f\0A\00"
define i32 @integrate(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca float*
%5 = alloca float
%6 = alloca float
%7 = alloca float
store i32* %0, i32** %2
%8 = load i32*, i32** %2
%9 = call i32 @getsize(i32* %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to float*
store float* %15, float** %4
%16 = load i32*, i32** %2
%17 = call float @getspace(i32* %16)
store float %17, float* %5
%18 = load float*, float** %4
%19 = load i32, i32* %3
%20 = load i32*, i32** %2
%21 = call i32 @generate(float* %18, i32 %19, i32* %20)
%22 = load float*, float** %4
%23 = load float, float* %5
%24 = load i32, i32* %3
%25 = call float @add(float* %22, float %23, i32 %24)
store float %25, float* %7
%26 = load float, float* %7
%27 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), float %26)
%28 = load float*, float** %4
%29 = call i32 @free(float* %28)
ret i32 1
}

LLVM IR (-O2):
@.str = [14 x i8] c"Integral: %f\0A\00"
define i32 @integrate(i32* %0) {
%2 = tail call i32 @getsize(i32* %0)
%3 = shl i32 %2, 2
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to float*
%6 = tail call float @getspace(i32* %0)
%7 = tail call i32 @generate(float* %5, i32 %2, i32* %0)
%8 = tail call float @add(float* %5, float %6, i32 %2)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), float %8)
%10 = tail call i32 @free(float* %5)
ret i32 1
}