#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 /*<<< orphan*/ free(float *);
int /*<<< orphan*/ gen_coeffs(float *, int);
int /*<<< orphan*/ gen_grid(float *, float *, float *, int, int);
float *malloc(int);
int /*<<< orphan*/ save_grid(char *, float *, int);
int main() {
  int height, width;
  height = 100;
  width = 100;
  float *sin_data = malloc(sizeof(float) * width * height);
  float *cos_data = malloc(sizeof(float) * width * height);
  float *grid_data = malloc(sizeof(float) * width * height);
  gen_coeffs(sin_data, height * width);
  gen_coeffs(cos_data, height * width);
  gen_grid(grid_data, sin_data, cos_data, height, width);
  free(sin_data);
  free(cos_data);
  save_grid("testgrid2.dat", grid_data, height * width);
  free(grid_data);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x8(%rbp)
movl   $0x64,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
movslq -0x8(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
movslq -0x8(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
movslq -0x8(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
imul   -0xc(%rbp),%esi
call   1040 <gen_coeffs@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
imul   -0xc(%rbp),%esi
call   1040 <gen_coeffs@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
call   1060 <gen_grid@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edx
imul   -0xc(%rbp),%edx
lea    0xde6(%rip),%rdi
call   1050 <save_grid@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x9c40,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    $0x9c40,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    $0x9c40,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    $0x2710,%esi
call   1040 <gen_coeffs@plt>
mov    %rbx,%rdi
mov    $0x2710,%esi
call   1040 <gen_coeffs@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    $0x64,%ecx
mov    $0x64,%r8d
call   1060 <gen_grid@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe3a(%rip),%rdi
mov    %r14,%rsi
mov    $0x2710,%edx
call   1050 <save_grid@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"testgrid2.dat\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca float*
%5 = alloca float*
%6 = alloca float*
store i32 0, i32* %1
store i32 100, i32* %2
store i32 100, i32* %3
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = mul i64 4, %8
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = mul i64 %9, %11
%13 = trunc i64 %12 to i32
%14 = call float* @malloc(i32 %13)
store float* %14, float** %4
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = mul i64 4, %16
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = mul i64 %17, %19
%21 = trunc i64 %20 to i32
%22 = call float* @malloc(i32 %21)
store float* %22, float** %5
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = mul i64 4, %24
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = mul i64 %25, %27
%29 = trunc i64 %28 to i32
%30 = call float* @malloc(i32 %29)
store float* %30, float** %6
%31 = load float*, float** %4
%32 = load i32, i32* %2
%33 = load i32, i32* %3
%34 = mul nsw i32 %32, %33
%35 = call i32 @gen_coeffs(float* %31, i32 %34)
%36 = load float*, float** %5
%37 = load i32, i32* %2
%38 = load i32, i32* %3
%39 = mul nsw i32 %37, %38
%40 = call i32 @gen_coeffs(float* %36, i32 %39)
%41 = load float*, float** %6
%42 = load float*, float** %4
%43 = load float*, float** %5
%44 = load i32, i32* %2
%45 = load i32, i32* %3
%46 = call i32 @gen_grid(float* %41, float* %42, float* %43, i32 %44, i32 %45)
%47 = load float*, float** %4
%48 = call i32 @free(float* %47)
%49 = load float*, float** %5
%50 = call i32 @free(float* %49)
%51 = load float*, float** %6
%52 = load i32, i32* %2
%53 = load i32, i32* %3
%54 = mul nsw i32 %52, %53
%55 = call i32 @save_grid(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), float* %51, i32 %54)
%56 = load float*, float** %6
%57 = call i32 @free(float* %56)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"testgrid2.dat\00"
define i32 @main() {
%1 = tail call float* @malloc(i32 40000)
%2 = tail call float* @malloc(i32 40000)
%3 = tail call float* @malloc(i32 40000)
%4 = tail call i32 @gen_coeffs(float* %1, i32 10000)
%5 = tail call i32 @gen_coeffs(float* %2, i32 10000)
%6 = tail call i32 @gen_grid(float* %3, float* %1, float* %2, i32 100, i32 100)
%7 = tail call i32 @free(float* %1)
%8 = tail call i32 @free(float* %2)
%9 = tail call i32 @save_grid(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), float* %3, i32 10000)
%10 = tail call i32 @free(float* %3)
ret i32 0
}