#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int storm_write_output(const char *filename, double **output, int shape[2]) {
  int i, j;
  const int nx = shape[0];
  const int ny = shape[1];
  FILE *fp = NULL;
  fp = fopen(filename, "w");
  if (!fp)
    return 1;
  for (i = 0; i < nx; i++) {
    for (j = 0; j < ny; j++) {
      fprintf(fp, "%10.2e", output[i][j]);
    }
    fprintf(fp, "\n");
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<storm_write_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    118a <storm_write_output+0x5a>
movl   $0x1,-0x4(%rbp)
jmp    1215 <storm_write_output+0xe5>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1205 <storm_write_output+0xd5>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    11e5 <storm_write_output+0xb5>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe32(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a4 <storm_write_output+0x74>
mov    -0x38(%rbp),%rdi
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1191 <storm_write_output+0x61>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<storm_write_output>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    (%rdx),%r12d
mov    0x4(%rdx),%r13d
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11de <storm_write_output+0x9e>
mov    %rax,%rbx
test   %r12d,%r12d
jle    11d2 <storm_write_output+0x92>
xor    %ebp,%ebp
lea    0xe8b(%rip),%r15
mov    %r12,(%rsp)
jmp    119a <storm_write_output+0x5a>
nopl   (%rax)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0x1,%rbp
mov    (%rsp),%r12
cmp    %r12,%rbp
je     11d2 <storm_write_output+0x92>
test   %r13d,%r13d
jle    1180 <storm_write_output+0x40>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14,%rbp,8),%rax
movsd  (%rax,%r12,8),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%r13
jne    11b0 <storm_write_output+0x70>
jmp    1180 <storm_write_output+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11e3 <storm_write_output+0xa3>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [7 x i8] c"%10.2e\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @storm_write_output(i8* %0, double** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca double**
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
store i8* %0, i8** %5
store double** %1, double*** %6
store i32* %2, i32** %7
%13 = load i32*, i32** %7
%14 = getelementptr inbounds i32, i32* %13, i64 0
%15 = load i32, i32* %14
store i32 %15, i32* %10
%16 = load i32*, i32** %7
%17 = getelementptr inbounds i32, i32* %16, i64 1
%18 = load i32, i32* %17
store i32 %18, i32* %11
store i32* null, i32** %12
%19 = load i8*, i8** %5
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %12
%21 = load i32*, i32** %12
%22 = icmp ne i32* %21, null
br i1 %22, label %24, label %23
23: ; preds = %3
store i32 1, i32* %4
br label %58
24: ; preds = %3
store i32 0, i32* %8
br label %25
25: ; preds = %52, %24
%26 = load i32, i32* %8
%27 = load i32, i32* %10
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %55
29: ; preds = %25
store i32 0, i32* %9
br label %30
30: ; preds = %46, %29
%31 = load i32, i32* %9
%32 = load i32, i32* %11
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %49
34: ; preds = %30
%35 = load i32*, i32** %12
%36 = load double**, double*** %6
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double*, double** %36, i64 %38
%40 = load double*, double** %39
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %44)
br label %46
46: ; preds = %34
%47 = load i32, i32* %9
%48 = add nsw i32 %47, 1
store i32 %48, i32* %9
br label %30
49: ; preds = %30
%50 = load i32*, i32** %12
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %49
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
br label %25
55: ; preds = %25
%56 = load i32*, i32** %12
%57 = call i32 @fclose(i32* %56)
store i32 0, i32* %4
br label %58
58: ; preds = %55, %23
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [7 x i8] c"%10.2e\00"
define i32 @storm_write_output(i8* nocapture %0, double** nocapture %1, i32* nocapture %2) {
%4 = load i32, i32* %2
%5 = getelementptr inbounds i32, i32* %2, i64 1
%6 = load i32, i32* %5
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %33, label %9
9: ; preds = %3
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %31
11: ; preds = %9
%12 = icmp sgt i32 %6, 0
%13 = zext i32 %4 to i64
%14 = zext i32 %6 to i64
br label %15
15: ; preds = %11, %27
%16 = phi i64 [ 0, %11 ], [ %29, %27 ]
br i1 %12, label %17, label %27
17: ; preds = %15
%18 = getelementptr inbounds double*, double** %1, i64 %16
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %25, %19 ]
%21 = load double*, double** %18
%22 = getelementptr inbounds double, double* %21, i64 %20
%23 = load double, double* %22
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %23)
%25 = add nuw nsw i64 %20, 1
%26 = icmp eq i64 %25, %14
br i1 %26, label %27, label %19
27: ; preds = %19, %15
%28 = tail call i32 @fputc(i32 10, i32* %7)
%29 = add nuw nsw i64 %16, 1
%30 = icmp eq i64 %29, %13
br i1 %30, label %31, label %15
31: ; preds = %27, %9
%32 = tail call i32 @fclose(i32* %7)
br label %33
33: ; preds = %3, %31
%34 = phi i32 [ 0, %31 ], [ 1, %3 ]
ret i32 %34
}