#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 *, int, float);
int /*<<< orphan*/ free(float *);
int /*<<< orphan*/ generate(int /*<<< orphan*/ *, float *, int);
float getdelta(int /*<<< orphan*/ *);
int getsize(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, float);
int integrate(FILE *fp) {
  int size = getsize(fp);
  float *array = (float *)malloc(size * size * sizeof(float));
  float delta = getdelta(fp);
  generate(fp, array, size);
  float sum = add(array, size, delta);
  printf("Integral: %f\n", sum);
  free(array);
  return 1;
}


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

x86 assembly (clang, -O2):
<integrate>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1080 <getsize@plt>
mov    %eax,%ebp
mov    %eax,%edi
imul   %eax,%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <getdelta@plt>
movss  %xmm0,0xc(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1090 <generate@plt>
mov    %r14,%rdi
mov    %ebp,%esi
movss  0xc(%rsp),%xmm0
call   1040 <add@plt>
lea    0xe3c(%rip),%rdi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
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
store i32* %0, i32** %2
%7 = load i32*, i32** %2
%8 = call i32 @getsize(i32* %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = load i32, i32* %3
%11 = mul nsw i32 %9, %10
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 4
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to float*
store float* %16, float** %4
%17 = load i32*, i32** %2
%18 = call float @getdelta(i32* %17)
store float %18, float* %5
%19 = load i32*, i32** %2
%20 = load float*, float** %4
%21 = load i32, i32* %3
%22 = call i32 @generate(i32* %19, float* %20, i32 %21)
%23 = load float*, float** %4
%24 = load i32, i32* %3
%25 = load float, float* %5
%26 = call float @add(float* %23, i32 %24, float %25)
store float %26, float* %6
%27 = load float, float* %6
%28 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), float %27)
%29 = load float*, float** %4
%30 = call i32 @free(float* %29)
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 = mul i32 %3, %2
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to float*
%7 = tail call float @getdelta(i32* %0)
%8 = tail call i32 @generate(i32* %0, float* %6, i32 %2)
%9 = tail call float @add(float* %6, i32 %2, float %7)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), float %9)
%11 = tail call i32 @free(float* %6)
ret i32 1
}