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


x86 assembly (clang, -O0):
<save_matrix3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe8f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1223 <save_matrix3+0xf3>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1210 <save_matrix3+0xe0>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f0 <save_matrix3+0xc0>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe31(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a7 <save_matrix3+0x77>
mov    -0x28(%rbp),%rdi
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1194 <save_matrix3+0x64>
jmp    1215 <save_matrix3+0xe5>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1181 <save_matrix3+0x51>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_matrix3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8d,%ebx
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,0x28(%rsp)
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xe90(%rip),%rsi
mov    %rax,%rdi
mov    %r12d,%edx
mov    %r15d,(%rsp)
mov    %r15d,%ecx
mov    %ebx,0x4(%rsp)
mov    %ebx,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %r12d,%r12d
jle    126d <save_matrix3+0x12d>
mov    %r12d,%eax
mov    %rax,0x10(%rsp)
mov    (%rsp),%eax
mov    %rax,0x20(%rsp)
mov    0x4(%rsp),%eax
mov    %rax,0x18(%rsp)
xor    %eax,%eax
mov    0x18(%rsp),%rbp
jmp    11d4 <save_matrix3+0x94>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
add    $0x1,%rax
cmp    0x10(%rsp),%rax
je     126d <save_matrix3+0x12d>
mov    %rax,0x8(%rsp)
cmpl   $0x0,(%rsp)
jle    11c0 <save_matrix3+0x80>
xor    %ebx,%ebx
jmp    1208 <save_matrix3+0xc8>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xa,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
add    $0x1,%rbx
cmp    0x20(%rsp),%rbx
je     11c0 <save_matrix3+0x80>
cmpl   $0x0,0x4(%rsp)
lea    0xdf8(%rip),%r13
mov    0x28(%rsp),%rax
mov    0x8(%rsp),%rsi
jle    11f0 <save_matrix3+0xb0>
xor    %r12d,%r12d
mov    %rbx,0x30(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %rax,%r15
mov    (%rax,%rsi,8),%rax
mov    (%rax,%rbx,8),%rax
movsd  (%rax,%r12,8),%xmm0
mov    %r14,%rdi
mov    %r14,%rbx
mov    %rsi,%r14
mov    %r13,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    %r14,%rsi
mov    %r15,%rax
mov    %rbx,%r14
mov    0x30(%rsp),%rbx
add    $0x1,%r12
cmp    %r12,%rbp
jne    1230 <save_matrix3+0xf0>
jmp    11f0 <save_matrix3+0xb0>
mov    %r14,%rdi
add    $0x38,%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 = [10 x i8] c"%d %d %d\0A\00"
@.str.2 = [4 x i8] c"%f \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @save_matrix3(i8* %0, double*** %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca double***
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %6
store double*** %1, double**** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%15 = load i8*, i8** %6
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %11
%17 = load i32*, i32** %11
%18 = load i32, i32* %8
%19 = load i32, i32* %9
%20 = load i32, i32* %10
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %19, i32 %20)
store i32 0, i32* %12
br label %22
22: ; preds = %62, %5
%23 = load i32, i32* %12
%24 = load i32, i32* %8
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %65
26: ; preds = %22
store i32 0, i32* %13
br label %27
27: ; preds = %58, %26
%28 = load i32, i32* %13
%29 = load i32, i32* %9
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %61
31: ; preds = %27
store i32 0, i32* %14
br label %32
32: ; preds = %52, %31
%33 = load i32, i32* %14
%34 = load i32, i32* %10
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %55
36: ; preds = %32
%37 = load i32*, i32** %11
%38 = load double***, double**** %7
%39 = load i32, i32* %12
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double**, double*** %38, i64 %40
%42 = load double**, double*** %41
%43 = load i32, i32* %13
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double*, double** %42, i64 %44
%46 = load double*, double** %45
%47 = load i32, i32* %14
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), double %50)
br label %52
52: ; preds = %36
%53 = load i32, i32* %14
%54 = add nsw i32 %53, 1
store i32 %54, i32* %14
br label %32
55: ; preds = %32
%56 = load i32*, i32** %11
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %58
58: ; preds = %55
%59 = load i32, i32* %13
%60 = add nsw i32 %59, 1
store i32 %60, i32* %13
br label %27
61: ; preds = %27
br label %62
62: ; preds = %61
%63 = load i32, i32* %12
%64 = add nsw i32 %63, 1
store i32 %64, i32* %12
br label %22
65: ; preds = %22
%66 = load i32*, i32** %11
%67 = call i32 @fclose(i32* %66)
ret void
}

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