#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 * n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      data[i * n + j] = (double)rand() / 10000000;
    }
  }
  file = fopen("input.data", "w");
  fwrite(data, sizeof(double), n * n, 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    130a <main+0x17a>
jmp    11be <main+0x2e>
jmp    1230 <main+0xa0>
mov    $0xefe,%edi
call   1040 <srand@plt>
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
movslq -0x1c(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12ca <main+0x13a>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12b7 <main+0x127>
mov    $0x0,%al
call   10b0 <rand@plt>
cvtsi2sd %rax,%xmm0
movsd  0xd71(%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    126f <main+0xdf>
jmp    12bc <main+0x12c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    125c <main+0xcc>
lea    0xd3a(%rip),%rdi
lea    0xd3e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
imul   -0x1c(%rbp),%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,%ebp
cmp    $0x2,%edi
jl     11ea <main+0x5a>
mov    %rsi,%r15
mov    %edi,%ebp
mov    $0x1,%ebx
lea    0xe52(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    (%r15,%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(%r15,%rbx,8),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    $0xefe,%edi
call   1040 <srand@plt>
mov    %ebp,%r15d
imul   %r15d,%r15d
lea    0x0(,%r15,8),%edi
call   1060 <malloc@plt>
mov    %rax,(%rsp)
test   %ebp,%ebp
jle    1276 <main+0xe6>
mov    %ebp,%ebp
lea    0x0(,%rbp,8),%r12
mov    (%rsp),%rbx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   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,%rbp
jne    1240 <main+0xb0>
add    $0x1,%r13
add    %r12,%rbx
cmp    %rbp,%r13
jne    1230 <main+0xa0>
lea    0xd8e(%rip),%rdi
lea    0xd92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbp
mov    (%rsp),%rdi
mov    $0x8,%esi
mov    %r15d,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
mov    %rbp,%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 %88
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 = sext i32 %42 to i64
%44 = mul i64 8, %43
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = mul i64 %44, %46
%48 = trunc i64 %47 to i32
%49 = call double* @malloc(i32 %48)
store double* %49, double** %9
store i32 0, i32* %6
br label %50
50: ; preds = %75, %40
%51 = load i32, i32* %6
%52 = load i32, i32* %8
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %78
54: ; preds = %50
store i32 0, i32* %7
br label %55
55: ; preds = %71, %54
%56 = load i32, i32* %7
%57 = load i32, i32* %8
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %74
59: ; preds = %55
%60 = call i64 (...) @rand()
%61 = sitofp i64 %60 to double
%62 = fdiv double %61, 1.000000e+07
%63 = load double*, double** %9
%64 = load i32, i32* %6
%65 = load i32, i32* %8
%66 = mul nsw i32 %64, %65
%67 = load i32, i32* %7
%68 = add nsw i32 %66, %67
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds double, double* %63, i64 %69
store double %62, double* %70
br label %71
71: ; preds = %59
%72 = load i32, i32* %7
%73 = add nsw i32 %72, 1
store i32 %73, i32* %7
br label %55
74: ; preds = %55
br label %75
75: ; preds = %74
%76 = load i32, i32* %6
%77 = add nsw i32 %76, 1
store i32 %77, i32* %6
br label %50
78: ; preds = %50
%79 = 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* %79, i32** %10
%80 = load double*, double** %9
%81 = load i32, i32* %8
%82 = load i32, i32* %8
%83 = mul nsw i32 %81, %82
%84 = load i32*, i32** %10
%85 = call i32 @fwrite(double* %80, i32 8, i32 %83, i32* %84)
%86 = load i32*, i32** %10
%87 = call i32 @fclose(i32* %86)
store i32 0, i32* %3
br label %88
88: ; preds = %78, %36
%89 = load i32, i32* %3
ret i32 %89
}

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 %52
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 = shl i32 %23, 3
%26 = mul i32 %25, %23
%27 = tail call double* @malloc(i32 %26)
%28 = icmp sgt i32 %23, 0
br i1 %28, label %29, label %47
29: ; preds = %22
%30 = zext i32 %23 to i64
%31 = zext i32 %23 to i64
br label %32
32: ; preds = %44, %29
%33 = phi i64 [ 0, %29 ], [ %45, %44 ]
%34 = mul nsw i64 %33, %30
br label %35
35: ; preds = %32, %35
%36 = phi i64 [ 0, %32 ], [ %42, %35 ]
%37 = tail call i64 (...) @rand()
%38 = sitofp i64 %37 to double
%39 = fdiv double %38, 1.000000e+07
%40 = add nuw nsw i64 %36, %34
%41 = getelementptr inbounds double, double* %27, i64 %40
store double %39, double* %41
%42 = add nuw nsw i64 %36, 1
%43 = icmp eq i64 %42, %31
br i1 %43, label %44, label %35
44: ; preds = %35
%45 = add nuw nsw i64 %33, 1
%46 = icmp eq i64 %45, %31
br i1 %46, label %47, label %32
47: ; preds = %44, %22
%48 = 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))
%49 = mul nsw i32 %23, %23
%50 = tail call i32 @fwrite(double* %27, i32 8, i32 %49, i32* %48)
%51 = tail call i32 @fclose(i32* %48)
br label %52
52: ; preds = %47, %15
ret i32 0
}