#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*/ chrono(int, float *);
int /*<<< orphan*/ compare(float *, float *, int);
int /*<<< orphan*/ cpu_convol(float *, float *, int);
int /*<<< orphan*/ free(float *);
int /*<<< orphan*/ gpu_convol(float *, float *, int);
int /*<<< orphan*/ init(float *, int);
float *malloc(int);
int /*<<< orphan*/ printf(char *, float);
int main() {
  float *a, *b, *c, time;
  int n = 3000;
  a = malloc(n * n * sizeof(float));
  b = malloc(n * n * sizeof(float));
  c = malloc(n * n * sizeof(float));
  init(a, n);
  gpu_convol(a, c, n);
  chrono(1, &time);
  cpu_convol(a, b, n);
  chrono(0, &time);
  printf("Convolution took  %f sec. on CPU\n", time);
  compare(b, c, n);
  free(a);
  free(b);
  free(c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xbb8,-0x20(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x20(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x20(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
imul   -0x20(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1060 <init@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   10a0 <gpu_convol@plt>
mov    $0x1,%edi
lea    -0x1c(%rbp),%rsi
call   1080 <chrono@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1050 <cpu_convol@plt>
xor    %edi,%edi
lea    -0x1c(%rbp),%rsi
call   1080 <chrono@plt>
movss  -0x1c(%rbp),%xmm0
lea    0xdd8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1090 <compare@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x2255100,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    $0x2255100,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0x2255100,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0xbb8,%esi
call   1060 <init@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xbb8,%edx
call   10a0 <gpu_convol@plt>
lea    0x4(%rsp),%r12
mov    $0x1,%edi
mov    %r12,%rsi
call   1080 <chrono@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xbb8,%edx
call   1050 <cpu_convol@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   1080 <chrono@plt>
movss  0x4(%rsp),%xmm0
lea    0xdfb(%rip),%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0xbb8,%edx
call   1090 <compare@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Convolution took %f sec. on CPU\0A\00"
define i32 @main() {
%1 = alloca float*
%2 = alloca float*
%3 = alloca float*
%4 = alloca float
%5 = alloca i32
store i32 3000, i32* %5
%6 = load i32, i32* %5
%7 = load i32, i32* %5
%8 = mul nsw i32 %6, %7
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 4
%11 = trunc i64 %10 to i32
%12 = call float* @malloc(i32 %11)
store float* %12, float** %1
%13 = load i32, i32* %5
%14 = load i32, i32* %5
%15 = mul nsw i32 %13, %14
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 4
%18 = trunc i64 %17 to i32
%19 = call float* @malloc(i32 %18)
store float* %19, float** %2
%20 = load i32, i32* %5
%21 = load i32, i32* %5
%22 = mul nsw i32 %20, %21
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 4
%25 = trunc i64 %24 to i32
%26 = call float* @malloc(i32 %25)
store float* %26, float** %3
%27 = load float*, float** %1
%28 = load i32, i32* %5
%29 = call i32 @init(float* %27, i32 %28)
%30 = load float*, float** %1
%31 = load float*, float** %3
%32 = load i32, i32* %5
%33 = call i32 @gpu_convol(float* %30, float* %31, i32 %32)
%34 = call i32 @chrono(i32 1, float* %4)
%35 = load float*, float** %1
%36 = load float*, float** %2
%37 = load i32, i32* %5
%38 = call i32 @cpu_convol(float* %35, float* %36, i32 %37)
%39 = call i32 @chrono(i32 0, float* %4)
%40 = load float, float* %4
%41 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), float %40)
%42 = load float*, float** %2
%43 = load float*, float** %3
%44 = load i32, i32* %5
%45 = call i32 @compare(float* %42, float* %43, i32 %44)
%46 = load float*, float** %1
%47 = call i32 @free(float* %46)
%48 = load float*, float** %2
%49 = call i32 @free(float* %48)
%50 = load float*, float** %3
%51 = call i32 @free(float* %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"Convolution took %f sec. on CPU\0A\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
%3 = tail call float* @malloc(i32 36000000)
%4 = tail call float* @malloc(i32 36000000)
%5 = tail call float* @malloc(i32 36000000)
%6 = tail call i32 @init(float* %3, i32 3000)
%7 = tail call i32 @gpu_convol(float* %3, float* %5, i32 3000)
%8 = call i32 @chrono(i32 1, float* %1)
%9 = call i32 @cpu_convol(float* %3, float* %4, i32 3000)
%10 = call i32 @chrono(i32 0, float* %1)
%11 = load float, float* %1
%12 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), float %11)
%13 = call i32 @compare(float* %4, float* %5, i32 3000)
%14 = call i32 @free(float* %3)
%15 = call i32 @free(float* %4)
%16 = call i32 @free(float* %5)
ret i32 0
}