#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
void write_array(double **data, int nrows, int ncols, char *outfile) {
  int k, l;
  FILE *fp_out = fopen(outfile, "w");
  for (l = 0; l < ncols - 1; l++) {
    for (k = 0; k < nrows - 1; k++) {
      fprintf(fp_out, "%le ", data[k][l]);
    }
    fprintf(fp_out, "%le\n", data[nrows - 1][l]);
  }
  for (k = 0; k < nrows - 1; k++) {
    fprintf(fp_out, "%le ", data[k][ncols - 1]);
  }
  fprintf(fp_out, "%le", data[nrows - 1][ncols - 1]);
}


x86 assembly (clang, -O0):
<write_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xebf(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11e5 <write_array+0xc5>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ad <write_array+0x8d>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe68(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1169 <write_array+0x49>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe35(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1151 <write_array+0x31>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1235 <write_array+0x115>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xde0(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ec <write_array+0xcc>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xdad(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r12d
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xec3(%rip),%rsi
mov    %rcx,%rdi
call   1040 <fopen@plt>
mov    %rax,%rbx
lea    -0x1(%r12),%eax
mov    %eax,0xc(%rsp)
mov    %rbp,%rax
mov    %rbp,0x10(%rsp)
lea    -0x1(%rbp),%eax
movslq %eax,%rcx
mov    %rcx,%rax
mov    %rcx,0x18(%rsp)
mov    %ecx,%r13d
cmp    $0x2,%r12d
jl     11f0 <write_array+0xd0>
mov    0xc(%rsp),%eax
mov    %rax,0x20(%rsp)
xor    %r15d,%r15d
lea    0xe7b(%rip),%r12
jmp    11b9 <write_array+0x99>
nopl   0x0(%rax)
mov    0x18(%rsp),%rax
mov    (%r14,%rax,8),%rax
movsd  (%rax,%r15,8),%xmm0
mov    %rbx,%rdi
lea    0xe5e(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x1,%r15
cmp    0x20(%rsp),%r15
je     11f0 <write_array+0xd0>
cmpl   $0x2,0x10(%rsp)
jl     1190 <write_array+0x70>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14,%rbp,8),%rax
movsd  (%rax,%r15,8),%xmm0
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    11d0 <write_array+0xb0>
jmp    1190 <write_array+0x70>
movslq 0xc(%rsp),%r12
cmpl   $0x2,0x10(%rsp)
jl     122e <write_array+0x10e>
xor    %ebp,%ebp
lea    0xdfd(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14,%rbp,8),%rax
movsd  (%rax,%r12,8),%xmm0
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1210 <write_array+0xf0>
mov    0x18(%rsp),%rax
mov    (%r14,%rax,8),%rax
movsd  (%rax,%r12,8),%xmm0
lea    0xdc8(%rip),%rsi
mov    %rbx,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [5 x i8] c"%le \00"
@.str.2 = [5 x i8] c"%le\0A\00"
@.str.3 = [4 x i8] c"%le\00"
define void @write_array(double** %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca double**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store double** %0, double*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%12 = load i8*, i8** %8
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %11
store i32 0, i32* %10
br label %14
14: ; preds = %53, %4
%15 = load i32, i32* %10
%16 = load i32, i32* %7
%17 = sub nsw i32 %16, 1
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %56
19: ; preds = %14
store i32 0, i32* %9
br label %20
20: ; preds = %37, %19
%21 = load i32, i32* %9
%22 = load i32, i32* %6
%23 = sub nsw i32 %22, 1
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %40
25: ; preds = %20
%26 = load i32*, i32** %11
%27 = load double**, double*** %5
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double*, double** %27, i64 %29
%31 = load double*, double** %30
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %35)
br label %37
37: ; preds = %25
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %20
40: ; preds = %20
%41 = load i32*, i32** %11
%42 = load double**, double*** %5
%43 = load i32, i32* %6
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double*, double** %42, i64 %45
%47 = load double*, double** %46
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = call i32 @fprintf(i32* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %51)
br label %53
53: ; preds = %40
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %14
56: ; preds = %14
store i32 0, i32* %9
br label %57
57: ; preds = %75, %56
%58 = load i32, i32* %9
%59 = load i32, i32* %6
%60 = sub nsw i32 %59, 1
%61 = icmp slt i32 %58, %60
br i1 %61, label %62, label %78
62: ; preds = %57
%63 = load i32*, i32** %11
%64 = load double**, double*** %5
%65 = load i32, i32* %9
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double*, double** %64, i64 %66
%68 = load double*, double** %67
%69 = load i32, i32* %7
%70 = sub nsw i32 %69, 1
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %68, i64 %71
%73 = load double, double* %72
%74 = call i32 @fprintf(i32* %63, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %73)
br label %75
75: ; preds = %62
%76 = load i32, i32* %9
%77 = add nsw i32 %76, 1
store i32 %77, i32* %9
br label %57
78: ; preds = %57
%79 = load i32*, i32** %11
%80 = load double**, double*** %5
%81 = load i32, i32* %6
%82 = sub nsw i32 %81, 1
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds double*, double** %80, i64 %83
%85 = load double*, double** %84
%86 = load i32, i32* %7
%87 = sub nsw i32 %86, 1
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds double, double* %85, i64 %88
%90 = load double, double* %89
%91 = call i32 @fprintf(i32* %79, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %90)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [5 x i8] c"%le \00"
@.str.2 = [5 x i8] c"%le\0A\00"
@.str.3 = [4 x i8] c"%le\00"
define void @write_array(double** nocapture %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = add i32 %2, -1
%7 = icmp sgt i32 %2, 1
%8 = add i32 %1, -1
br i1 %7, label %9, label %17
9: ; preds = %4
%10 = icmp sgt i32 %1, 1
%11 = sext i32 %8 to i64
%12 = getelementptr inbounds double*, double** %0, i64 %11
%13 = zext i32 %6 to i64
%14 = zext i32 %8 to i64
br label %15
15: ; preds = %9, %31
%16 = phi i64 [ 0, %9 ], [ %36, %31 ]
br i1 %10, label %22, label %31
17: ; preds = %31, %4
%18 = icmp sgt i32 %1, 1
%19 = sext i32 %6 to i64
br i1 %18, label %20, label %47
20: ; preds = %17
%21 = zext i32 %8 to i64
br label %38
22: ; preds = %15, %22
%23 = phi i64 [ %29, %22 ], [ 0, %15 ]
%24 = getelementptr inbounds double*, double** %0, i64 %23
%25 = load double*, double** %24
%26 = getelementptr inbounds double, double* %25, i64 %16
%27 = load double, double* %26
%28 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %27)
%29 = add nuw nsw i64 %23, 1
%30 = icmp eq i64 %29, %14
br i1 %30, label %31, label %22
31: ; preds = %22, %15
%32 = load double*, double** %12
%33 = getelementptr inbounds double, double* %32, i64 %16
%34 = load double, double* %33
%35 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %34)
%36 = add nuw nsw i64 %16, 1
%37 = icmp eq i64 %36, %13
br i1 %37, label %17, label %15
38: ; preds = %20, %38
%39 = phi i64 [ 0, %20 ], [ %45, %38 ]
%40 = getelementptr inbounds double*, double** %0, i64 %39
%41 = load double*, double** %40
%42 = getelementptr inbounds double, double* %41, i64 %19
%43 = load double, double* %42
%44 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), double %43)
%45 = add nuw nsw i64 %39, 1
%46 = icmp eq i64 %45, %21
br i1 %46, label %47, label %38
47: ; preds = %38, %17
%48 = sext i32 %8 to i64
%49 = getelementptr inbounds double*, double** %0, i64 %48
%50 = load double*, double** %49
%51 = getelementptr inbounds double, double* %50, i64 %19
%52 = load double, double* %51
%53 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %52)
ret void
}