#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*/ cal_prod(char **, char **, unsigned long long **);
unsigned long long get_time();
int /*<<< orphan*/ init_mat(char **);
void *malloc(int);
int /*<<< orphan*/ printf(char *, unsigned long long);
int main(int argc, char *argv[]) {
  char **mat_1;
  char **mat_2;
  unsigned long long **prod;
  unsigned long long start_time = get_time();
  printf("Starting app at time: %llu\n", start_time);
  mat_1 = malloc(sizeof(char *) * (1024 * 2));
  mat_2 = malloc(sizeof(char *) * (1024 * 2));
  prod = malloc(sizeof(unsigned long long *) * (1024 * 2));
  unsigned long long atime = get_time();
  printf("Time spent in allocation: %llu\n", atime - start_time);
  int i;
  for (i = 0; i < (1024 * 2); i++) {
    mat_1[i] = malloc(sizeof(char) * (1024 * 2));
    mat_2[i] = malloc(sizeof(char) * (1024 * 2));
    prod[i] = malloc(sizeof(unsigned long long) * (1024 * 2));
  }
  init_mat(mat_1);
  init_mat(mat_2);
  unsigned long long itime = get_time();
  printf("Time spent in initialization: %llu\n", itime - atime);
  cal_prod(mat_1, mat_2, prod);
  unsigned long long ptime = get_time();
  printf("Time spent in multiplication: %llu\n", ptime - itime);
  printf("Total time spent in application: %llu\n", ptime - start_time);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <get_time@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
mov    $0x4000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x4000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x4000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <get_time@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
sub    -0x30(%rbp),%rsi
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x800,-0x3c(%rbp)
jge    1237 <main+0xe7>
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    $0x4000,%edi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d1 <main+0x81>
mov    -0x18(%rbp),%rdi
call   1040 <init_mat@plt>
mov    -0x20(%rbp),%rdi
call   1040 <init_mat@plt>
mov    $0x0,%al
call   1050 <get_time@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
sub    -0x38(%rbp),%rsi
lea    0xdd9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <cal_prod@plt>
mov    $0x0,%al
call   1050 <get_time@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rsi
sub    -0x48(%rbp),%rsi
lea    0xdcd(%rip),%rdi
call   1030 <printf@plt>
mov    -0x50(%rbp),%rsi
sub    -0x30(%rbp),%rsi
lea    0xddd(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <get_time@plt>
mov    %rax,%r14
lea    0xe92(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0x4000,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x4000,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    $0x4000,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <get_time@plt>
mov    %rax,%r13
mov    %rax,%rsi
sub    %r14,%rsi
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
nopl   0x0(%rax)
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,(%r15,%rbp,8)
mov    $0x800,%edi
call   1060 <malloc@plt>
mov    %rax,(%r12,%rbp,8)
mov    $0x4000,%edi
call   1060 <malloc@plt>
mov    %rax,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    $0x800,%rbp
jne    11c0 <main+0x70>
mov    %r15,%rdi
call   1040 <init_mat@plt>
mov    %r12,%rdi
call   1040 <init_mat@plt>
xor    %eax,%eax
call   1050 <get_time@plt>
mov    %rax,%rbp
mov    %rax,%rsi
sub    %r13,%rsi
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1070 <cal_prod@plt>
xor    %eax,%eax
call   1050 <get_time@plt>
mov    %rax,%rbx
mov    %rax,%rsi
sub    %rbp,%rsi
lea    0xe18(%rip),%rdi
call   1030 <printf@plt>
sub    %r14,%rbx
lea    0xe2d(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Starting app at time: %llu\0A\00"
@.str.1 = [32 x i8] c"Time spent in allocation: %llu\0A\00"
@.str.2 = [36 x i8] c"Time spent in initialization: %llu\0A\00"
@.str.3 = [36 x i8] c"Time spent in multiplication: %llu\0A\00"
@.str.4 = [39 x i8] c"Total time spent in application: %llu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i64**
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i64 (...) @get_time()
store i64 %14, i64* %9
%15 = load i64, i64* %9
%16 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 %15)
%17 = call i8* @malloc(i32 16384)
%18 = bitcast i8* %17 to i8**
store i8** %18, i8*** %6
%19 = call i8* @malloc(i32 16384)
%20 = bitcast i8* %19 to i8**
store i8** %20, i8*** %7
%21 = call i8* @malloc(i32 16384)
%22 = bitcast i8* %21 to i64**
store i64** %22, i64*** %8
%23 = call i64 (...) @get_time()
store i64 %23, i64* %10
%24 = load i64, i64* %10
%25 = load i64, i64* %9
%26 = sub i64 %24, %25
%27 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i64 %26)
store i32 0, i32* %11
br label %28
28: ; preds = %48, %2
%29 = load i32, i32* %11
%30 = icmp slt i32 %29, 2048
br i1 %30, label %31, label %51
31: ; preds = %28
%32 = call i8* @malloc(i32 2048)
%33 = load i8**, i8*** %6
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
store i8* %32, i8** %36
%37 = call i8* @malloc(i32 2048)
%38 = load i8**, i8*** %7
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
store i8* %37, i8** %41
%42 = call i8* @malloc(i32 16384)
%43 = bitcast i8* %42 to i64*
%44 = load i64**, i64*** %8
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i64*, i64** %44, i64 %46
store i64* %43, i64** %47
br label %48
48: ; preds = %31
%49 = load i32, i32* %11
%50 = add nsw i32 %49, 1
store i32 %50, i32* %11
br label %28
51: ; preds = %28
%52 = load i8**, i8*** %6
%53 = call i32 @init_mat(i8** %52)
%54 = load i8**, i8*** %7
%55 = call i32 @init_mat(i8** %54)
%56 = call i64 (...) @get_time()
store i64 %56, i64* %12
%57 = load i64, i64* %12
%58 = load i64, i64* %10
%59 = sub i64 %57, %58
%60 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i64 %59)
%61 = load i8**, i8*** %6
%62 = load i8**, i8*** %7
%63 = load i64**, i64*** %8
%64 = call i32 @cal_prod(i8** %61, i8** %62, i64** %63)
%65 = call i64 (...) @get_time()
store i64 %65, i64* %13
%66 = load i64, i64* %13
%67 = load i64, i64* %12
%68 = sub i64 %66, %67
%69 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i64 %68)
%70 = load i64, i64* %13
%71 = load i64, i64* %9
%72 = sub i64 %70, %71
%73 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i64 %72)
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Starting app at time: %llu\0A\00"
@.str.1 = [32 x i8] c"Time spent in allocation: %llu\0A\00"
@.str.2 = [36 x i8] c"Time spent in initialization: %llu\0A\00"
@.str.3 = [36 x i8] c"Time spent in multiplication: %llu\0A\00"
@.str.4 = [39 x i8] c"Total time spent in application: %llu\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @get_time()
%4 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 %3)
%5 = tail call dereferenceable_or_null(16384) i8* @malloc(i32 16384)
%6 = bitcast i8* %5 to i8**
%7 = tail call dereferenceable_or_null(16384) i8* @malloc(i32 16384)
%8 = bitcast i8* %7 to i8**
%9 = tail call dereferenceable_or_null(16384) i8* @malloc(i32 16384)
%10 = bitcast i8* %9 to i64**
%11 = tail call i64 (...) @get_time()
%12 = sub i64 %11, %3
%13 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i64 %12)
br label %14
14: ; preds = %2, %14
%15 = phi i64 [ 0, %2 ], [ %23, %14 ]
%16 = tail call dereferenceable_or_null(2048) i8* @malloc(i32 2048)
%17 = getelementptr inbounds i8*, i8** %6, i64 %15
store i8* %16, i8** %17
%18 = tail call dereferenceable_or_null(2048) i8* @malloc(i32 2048)
%19 = getelementptr inbounds i8*, i8** %8, i64 %15
store i8* %18, i8** %19
%20 = tail call dereferenceable_or_null(16384) i8* @malloc(i32 16384)
%21 = getelementptr inbounds i64*, i64** %10, i64 %15
%22 = bitcast i64** %21 to i8**
store i8* %20, i8** %22
%23 = add nuw nsw i64 %15, 1
%24 = icmp eq i64 %23, 2048
br i1 %24, label %25, label %14
25: ; preds = %14
%26 = tail call i32 @init_mat(i8** %6)
%27 = tail call i32 @init_mat(i8** %8)
%28 = tail call i64 (...) @get_time()
%29 = sub i64 %28, %11
%30 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i64 %29)
%31 = tail call i32 @cal_prod(i8** %6, i8** %8, i64** %10)
%32 = tail call i64 (...) @get_time()
%33 = sub i64 %32, %28
%34 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i64 %33)
%35 = sub i64 %32, %3
%36 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i64 %35)
ret i32 0
}