#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 *, ...);
void save_matrix(const char *fout, double **X, int n, int m) {
  FILE *f = fopen(fout, "w");
  int i, j;
  fprintf(f, "%d %d\n", n, m);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++)
      fprintf(f, "%f ", X[i][j]);
    fprintf(f, "\n");
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<save_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ed <save_matrix+0xbd>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11cd <save_matrix+0x9d>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe51(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    118c <save_matrix+0x5c>
mov    -0x20(%rbp),%rdi
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1179 <save_matrix+0x49>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebx
mov    %edx,%r15d
mov    %rsi,%r13
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
lea    0xe96(%rip),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
mov    %ebx,0xc(%rsp)
mov    %ebx,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %r15d,%r15d
jle    11f3 <save_matrix+0xb3>
mov    %r15d,%eax
mov    %rax,0x10(%rsp)
mov    0xc(%rsp),%ebx
xor    %r14d,%r14d
lea    0xe6f(%rip),%r15
jmp    11b8 <save_matrix+0x78>
nopl   0x0(%rax)
mov    $0xa,%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
add    $0x1,%r14
cmp    0x10(%rsp),%r14
je     11f3 <save_matrix+0xb3>
cmpl   $0x0,0xc(%rsp)
jle    11a0 <save_matrix+0x60>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13,%r14,8),%rax
movsd  (%rax,%r12,8),%xmm0
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%rbx
jne    11d0 <save_matrix+0x90>
jmp    11a0 <save_matrix+0x60>
mov    %rbp,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

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

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