#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();
int 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] = rand() % 100 + 1;
    }
  }
  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    0xe23(%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    1308 <main+0x178>
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    12c8 <main+0x138>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12b5 <main+0x125>
mov    $0x0,%al
call   10b0 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
cvtsi2sd %edx,%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    12ba <main+0x12a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    125c <main+0xcc>
lea    0xd34(%rip),%rdi
lea    0xd38(%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    0xe4a(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    12bd <main+0x12d>
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    1289 <main+0xf9>
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>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%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    0xd73(%rip),%rdi
lea    0xd77(%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    12c4 <main+0x134>
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 %89
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 = %76, %40
%51 = load i32, i32* %6
%52 = load i32, i32* %8
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %79
54: ; preds = %50
store i32 0, i32* %7
br label %55
55: ; preds = %72, %54
%56 = load i32, i32* %7
%57 = load i32, i32* %8
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %75
59: ; preds = %55
%60 = call i32 (...) @rand()
%61 = srem i32 %60, 100
%62 = add nsw i32 %61, 1
%63 = sitofp i32 %62 to double
%64 = load double*, double** %9
%65 = load i32, i32* %6
%66 = load i32, i32* %8
%67 = mul nsw i32 %65, %66
%68 = load i32, i32* %7
%69 = add nsw i32 %67, %68
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double, double* %64, i64 %70
store double %63, double* %71
br label %72
72: ; preds = %59
%73 = load i32, i32* %7
%74 = add nsw i32 %73, 1
store i32 %74, i32* %7
br label %55
75: ; preds = %55
br label %76
76: ; preds = %75
%77 = load i32, i32* %6
%78 = add nsw i32 %77, 1
store i32 %78, i32* %6
br label %50
79: ; preds = %50
%80 = 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* %80, i32** %10
%81 = load double*, double** %9
%82 = load i32, i32* %8
%83 = load i32, i32* %8
%84 = mul nsw i32 %82, %83
%85 = load i32*, i32** %10
%86 = call i32 @fwrite(double* %81, i32 8, i32 %84, i32* %85)
%87 = load i32*, i32** %10
%88 = call i32 @fclose(i32* %87)
store i32 0, i32* %3
br label %89
89: ; preds = %79, %36
%90 = load i32, i32* %3
ret i32 %90
}

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