#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 *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void save_dmat(char name[], char digit[], int nrow, int ncol, double **dmat) {
  FILE *fnam = fopen(name, "w");
  for (int i = 0; i < nrow; ++i) {
    for (int j = 0; j < ncol; ++j)
      fprintf(fnam, digit, dmat[i][j]);
    fprintf(fnam, "\n");
  }
  fclose(fnam);
}


x86 assembly (clang, -O0):
<save_dmat>:
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    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d6 <save_dmat+0xa6>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11b6 <save_dmat+0x86>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1178 <save_dmat+0x48>
mov    -0x28(%rbp),%rdi
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1165 <save_dmat+0x35>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_dmat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r15
mov    %ecx,0xc(%rsp)
mov    %edx,%r12d
mov    %rsi,%r13
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %r12d,%r12d
jle    11d2 <save_dmat+0x92>
mov    %r12d,%eax
mov    %rax,0x10(%rsp)
mov    0xc(%rsp),%ebp
xor    %r14d,%r14d
jmp    1198 <save_dmat+0x58>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0x1,%r14
cmp    0x10(%rsp),%r14
je     11d2 <save_dmat+0x92>
cmpl   $0x0,0xc(%rsp)
jle    1180 <save_dmat+0x40>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15,%r14,8),%rax
movsd  (%rax,%r12,8),%xmm0
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%rbp
jne    11b0 <save_dmat+0x70>
jmp    1180 <save_dmat+0x40>
mov    %rbx,%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 = [2 x i8] c"\0A\00"
define void @save_dmat(i8* %0, i8* %1, i32 %2, i32 %3, double** %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca double**
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store double** %4, double*** %10
%14 = load i8*, i8** %6
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %11
store i32 0, i32* %12
br label %16
16: ; preds = %44, %5
%17 = load i32, i32* %12
%18 = load i32, i32* %8
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %47
20: ; preds = %16
store i32 0, i32* %13
br label %21
21: ; preds = %38, %20
%22 = load i32, i32* %13
%23 = load i32, i32* %9
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %41
25: ; preds = %21
%26 = load i32*, i32** %11
%27 = load i8*, i8** %7
%28 = load double**, double*** %10
%29 = load i32, i32* %12
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double*, double** %28, i64 %30
%32 = load double*, double** %31
%33 = load i32, i32* %13
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* %27, double %36)
br label %38
38: ; preds = %25
%39 = load i32, i32* %13
%40 = add nsw i32 %39, 1
store i32 %40, i32* %13
br label %21
41: ; preds = %21
%42 = load i32*, i32** %11
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %41
%45 = load i32, i32* %12
%46 = add nsw i32 %45, 1
store i32 %46, i32* %12
br label %16
47: ; preds = %16
%48 = load i32*, i32** %11
%49 = call i32 @fclose(i32* %48)
ret void
}

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