#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 */
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
double matrix_benchmark(int, int);
int /*<<< orphan*/ printf(char *, int, double);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int dim, dim_upper, dim_lower, iterations;
  double time_elapsed;
  FILE *ofp;
  dim_lower = atoi(argv[1]);
  dim_upper = atoi(argv[2]);
  iterations = atoi(argv[3]);
  ofp = fopen("times", "a");
  if (ofp == NULL) {
    fprintf(stderr, "ERROR: could not open file\n");
    exit(0);
  }
  srand(time(NULL));
  for (dim = dim_lower; dim < dim_upper; dim++) {
    time_elapsed = matrix_benchmark(dim, iterations);
    printf("dimension = %d, time = %lfms \n", dim, time_elapsed);
    fprintf(ofp, "%d, %lf; \n ", dim, time_elapsed);
    time_elapsed = 0.0;
  }
  fclose(ofp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x20(%rbp)
lea    0xe23(%rip),%rdi
lea    0xe22(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1217 <main+0x87>
mov    0x2de1(%rip),%rax
movslq (%rax),%rdi
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    128d <main+0xfd>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1030 <matrix_benchmark@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
lea    0xdcc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%edx
movsd  -0x28(%rbp),%xmm0
lea    0xdd3(%rip),%rsi
mov    $0x1,%al
call   1070 <fprintf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    122d <main+0x9d>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r14d
mov    0x18(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r15d
lea    0xe28(%rip),%rdi
lea    0xe27(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     125e <main+0xbe>
mov    %rax,%rbp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
cmp    %r14d,%ebx
jge    1245 <main+0xa5>
lea    0xe1e(%rip),%r12
lea    0xe36(%rip),%r13
nopl   (%rax)
mov    %ebx,%edi
mov    %r15d,%esi
call   1030 <matrix_benchmark@plt>
movsd  %xmm0,(%rsp)
mov    %r12,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1070 <fprintf@plt>
add    $0x1,%ebx
cmp    %ebx,%r14d
jne    1210 <main+0x70>
mov    %rbp,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d7b(%rip),%rax
movslq (%rax),%rcx
lea    0xd99(%rip),%rdi
mov    $0x1b,%esi
mov    $0x1,%edx
call   10c0 <fwrite@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"times\00"
@.str.1 = [2 x i8] c"a\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"ERROR: could not open file\0A\00"
@.str.3 = [31 x i8] c"dimension = %d, time = %lfms \0A\00"
@.str.4 = [12 x i8] c"%d, %lf; \0A \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %8
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %7
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %9
%24 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %11
%25 = load i32*, i32** %11
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %33
27: ; preds = %2
%28 = load i32, i32* @stderr
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i32*
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %2
%34 = call i32 @time(i32* null)
%35 = call i32 @srand(i32 %34)
%36 = load i32, i32* %8
store i32 %36, i32* %6
br label %37
37: ; preds = %52, %33
%38 = load i32, i32* %6
%39 = load i32, i32* %7
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %55
41: ; preds = %37
%42 = load i32, i32* %6
%43 = load i32, i32* %9
%44 = call double @matrix_benchmark(i32 %42, i32 %43)
store double %44, double* %10
%45 = load i32, i32* %6
%46 = load double, double* %10
%47 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %45, double %46)
%48 = load i32*, i32** %11
%49 = load i32, i32* %6
%50 = load double, double* %10
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %49, double %50)
store double 0.000000e+00, double* %10
br label %52
52: ; preds = %41
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %37
55: ; preds = %37
%56 = load i32*, i32** %11
%57 = call i32 @fclose(i32* %56)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"times\00"
@.str.1 = [2 x i8] c"a\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"ERROR: could not open file\0A\00"
@.str.3 = [31 x i8] c"dimension = %d, time = %lfms \0A\00"
@.str.4 = [12 x i8] c"%d, %lf; \0A \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = getelementptr inbounds i8*, i8** %1, i64 3
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 27, i64 1, i32* %17)
%19 = tail call i32 @exit(i32 0)
unreachable
20: ; preds = %2
%21 = tail call i32 @time(i32* null)
%22 = tail call i32 @srand(i32 %21)
%23 = icmp slt i32 %5, %8
br i1 %23, label %24, label %31
24: ; preds = %20, %24
%25 = phi i32 [ %29, %24 ], [ %5, %20 ]
%26 = tail call double @matrix_benchmark(i32 %25, i32 %11)
%27 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %25, double %26)
%28 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %25, double %26)
%29 = add nsw i32 %25, 1
%30 = icmp eq i32 %29, %8
br i1 %30, label %31, label %24
31: ; preds = %24, %20
%32 = tail call i32 @fclose(i32* %12)
ret i32 0
}