#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(double *, int, int, int /*<<< orphan*/ *);
double *malloc(int);
int /*<<< orphan*/ print_usage();
scalar_t__ rand();
int /*<<< orphan*/ srand(int);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int i, j;
  int n;
  double *data;
  FILE *file;
  n = 1024;
  if (argc > 1) {
    for (i = 1; i < argc;) {
      if (strcmp(argv[i], "-s") == 0) {
        n = atoi(argv[i + 1]);
        i += 2;
      } else {
        print_usage();
        return 0;
      }
    }
  }
  srand(3838);
  data = malloc(sizeof(double) * (n + 2) * (n + 2));
  for (i = 0; i <= (n + 1); i++) {
    for (j = 0; j <= (n + 1); j++) {
      data[i * n + j] = (double)rand() / 10000000;
    }
  }
  file = fopen("input.data", "w");
  fwrite(data, sizeof(double), (n + 2) * (n + 2), file);
  fclose(file);
  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)
movl   $0x400,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1230 <main+0xa0>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122b <main+0x9b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe2b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1213 <main+0x83>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1226 <main+0x96>
mov    $0x0,%al
call   10a0 <print_usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1325 <main+0x195>
jmp    11be <main+0x2e>
jmp    1230 <main+0xa0>
mov    $0xefe,%edi
call   1040 <srand@plt>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x3,%rax
mov    -0x1c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jg     12dd <main+0x14d>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jg     12ca <main+0x13a>
mov    $0x0,%al
call   10b0 <rand@plt>
cvtsi2sd %rax,%xmm0
movsd  0xd5e(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    127d <main+0xed>
jmp    12cf <main+0x13f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1265 <main+0xd5>
lea    0xd27(%rip),%rdi
lea    0xd2b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
add    $0x2,%edx
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
imul   %eax,%edx
mov    -0x30(%rbp),%rcx
mov    $0x8,%esi
call   1090 <fwrite@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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    $0x400,%r15d
cmp    $0x2,%edi
jl     11eb <main+0x5b>
mov    %rsi,%r12
mov    %edi,%ebp
mov    $0x1,%ebx
lea    0xe51(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    (%r12,%rbx,8),%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    12aa <main+0x11a>
add    $0x2,%rbx
cmp    %rbp,%rbx
jb     11c0 <main+0x30>
mov    -0x8(%r12,%rbx,8),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    $0xefe,%edi
call   1040 <srand@plt>
lea    0x2(%r15),%ebx
mov    %ebx,%r12d
imul   %r12d,%r12d
lea    0x0(,%r12,8),%edi
call   1060 <malloc@plt>
mov    %rax,(%rsp)
cmp    $0xffffffff,%r15d
jl     1276 <main+0xe6>
movslq %r15d,%r15
mov    %ebx,%r13d
shl    $0x3,%r15
mov    (%rsp),%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   10b0 <rand@plt>
movsd  0xdb1(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%r14,8)
add    $0x1,%r14
cmp    %r14,%r13
jne    1240 <main+0xb0>
add    $0x1,%rbp
add    %r15,%rbx
cmp    %r13,%rbp
jne    1230 <main+0xa0>
lea    0xd8e(%rip),%rdi
lea    0xd92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    (%rsp),%rdi
mov    $0x8,%esi
mov    %r12d,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    12b1 <main+0x121>
xor    %eax,%eax
call   10a0 <print_usage@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-s\00"
@.str.1 = [11 x i8] c"input.data\00"
@.str.2 = [2 x i8] c"w\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 double*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1024, i32* %8
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %40
13: ; preds = %2
store i32 1, i32* %6
br label %14
14: ; preds = %38, %13
%15 = load i32, i32* %6
%16 = load i32, i32* %4
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %39
18: ; preds = %14
%19 = load i8**, i8*** %5
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %18
%27 = load i8**, i8*** %5
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %27, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %8
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 2
store i32 %35, i32* %6
br label %38
36: ; preds = %18
%37 = call i32 (...) @print_usage()
store i32 0, i32* %3
br label %94
38: ; preds = %26
br label %14
39: ; preds = %14
br label %40
40: ; preds = %39, %2
%41 = call i32 @srand(i32 3838)
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 2
%44 = sext i32 %43 to i64
%45 = mul i64 8, %44
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 2
%48 = sext i32 %47 to i64
%49 = mul i64 %45, %48
%50 = trunc i64 %49 to i32
%51 = call double* @malloc(i32 %50)
store double* %51, double** %9
store i32 0, i32* %6
br label %52
52: ; preds = %79, %40
%53 = load i32, i32* %6
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
%56 = icmp sle i32 %53, %55
br i1 %56, label %57, label %82
57: ; preds = %52
store i32 0, i32* %7
br label %58
58: ; preds = %75, %57
%59 = load i32, i32* %7
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
%62 = icmp sle i32 %59, %61
br i1 %62, label %63, label %78
63: ; preds = %58
%64 = call i64 (...) @rand()
%65 = sitofp i64 %64 to double
%66 = fdiv double %65, 1.000000e+07
%67 = load double*, double** %9
%68 = load i32, i32* %6
%69 = load i32, i32* %8
%70 = mul nsw i32 %68, %69
%71 = load i32, i32* %7
%72 = add nsw i32 %70, %71
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %67, i64 %73
store double %66, double* %74
br label %75
75: ; preds = %63
%76 = load i32, i32* %7
%77 = add nsw i32 %76, 1
store i32 %77, i32* %7
br label %58
78: ; preds = %58
br label %79
79: ; preds = %78
%80 = load i32, i32* %6
%81 = add nsw i32 %80, 1
store i32 %81, i32* %6
br label %52
82: ; preds = %52
%83 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %83, i32** %10
%84 = load double*, double** %9
%85 = load i32, i32* %8
%86 = add nsw i32 %85, 2
%87 = load i32, i32* %8
%88 = add nsw i32 %87, 2
%89 = mul nsw i32 %86, %88
%90 = load i32*, i32** %10
%91 = call i32 @fwrite(double* %84, i32 8, i32 %89, i32* %90)
%92 = load i32*, i32** %10
%93 = call i32 @fclose(i32* %92)
store i32 0, i32* %3
br label %94
94: ; preds = %82, %36
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
@.str = [3 x i8] c"-s\00"
@.str.1 = [11 x i8] c"input.data\00"
@.str.2 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %22
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %12
%7 = phi i64 [ 1, %4 ], [ %13, %12 ]
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = add nuw nsw i64 %7, 2
%14 = icmp ult i64 %13, %5
br i1 %14, label %6, label %17
15: ; preds = %6
%16 = tail call i32 (...) @print_usage()
br label %53
17: ; preds = %12
%18 = add nuw nsw i64 %7, 1
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
br label %22
22: ; preds = %17, %2
%23 = phi i32 [ 1024, %2 ], [ %21, %17 ]
%24 = tail call i32 @srand(i32 3838)
%25 = add i32 %23, 2
%26 = shl i32 %25, 3
%27 = mul i32 %26, %25
%28 = tail call double* @malloc(i32 %27)
%29 = icmp slt i32 %23, -1
br i1 %29, label %48, label %30
30: ; preds = %22
%31 = sext i32 %23 to i64
%32 = zext i32 %25 to i64
br label %33
33: ; preds = %45, %30
%34 = phi i64 [ 0, %30 ], [ %46, %45 ]
%35 = mul nsw i64 %34, %31
br label %36
36: ; preds = %33, %36
%37 = phi i64 [ 0, %33 ], [ %43, %36 ]
%38 = tail call i64 (...) @rand()
%39 = sitofp i64 %38 to double
%40 = fdiv double %39, 1.000000e+07
%41 = add nsw i64 %37, %35
%42 = getelementptr inbounds double, double* %28, i64 %41
store double %40, double* %42
%43 = add nuw nsw i64 %37, 1
%44 = icmp eq i64 %43, %32
br i1 %44, label %45, label %36
45: ; preds = %36
%46 = add nuw nsw i64 %34, 1
%47 = icmp eq i64 %46, %32
br i1 %47, label %48, label %33
48: ; preds = %45, %22
%49 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%50 = mul nsw i32 %25, %25
%51 = tail call i32 @fwrite(double* %28, i32 8, i32 %50, i32* %49)
%52 = tail call i32 @fclose(i32* %49)
br label %53
53: ; preds = %48, %15
ret i32 0
}