#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 *, ...);
int /*<<< orphan*/ printf(char *, char *);
void save_fmatrix(char *output_filename, float **data, int nx, int ny) {
  int i, j;
  FILE *output_file;
  output_file = fopen(output_filename, "w");
  if (!output_file)
    printf("I could not open the file %s for writing\n", output_filename);
  for (i = 1; i <= nx; i++) {
    for (j = 1; j <= ny; j++) {
      fprintf(output_file, "%.4f\t", data[i][j]);
    }
    fprintf(output_file, "\n");
  }
  fclose(output_file);
}


x86 assembly (clang, -O0):
<save_fmatrix>:
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    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1185 <save_fmatrix+0x45>
mov    -0x8(%rbp),%rsi
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1204 <save_fmatrix+0xc4>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     11e4 <save_fmatrix+0xa4>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe5d(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119f <save_fmatrix+0x5f>
mov    -0x28(%rbp),%rdi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118c <save_fmatrix+0x4c>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_fmatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x8(%rsp)
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%r13
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     118a <save_fmatrix+0x3a>
test   %r15d,%r15d
jg     119e <save_fmatrix+0x4e>
jmp    1216 <save_fmatrix+0xc6>
lea    0xe71(%rip),%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
test   %r15d,%r15d
jle    1216 <save_fmatrix+0xc6>
mov    0x8(%rsp),%rax
lea    0x1(%rax),%ebp
add    $0x1,%r15d
mov    $0x1,%r14d
lea    0xe75(%rip),%r13
mov    %r15,0x10(%rsp)
jmp    11db <save_fmatrix+0x8b>
xchg   %ax,%ax
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0x1,%r14
mov    0x10(%rsp),%r15
cmp    %r15,%r14
je     1216 <save_fmatrix+0xc6>
cmpl   $0x0,0x8(%rsp)
jle    11c0 <save_fmatrix+0x70>
mov    $0x1,%r15d
nopl   0x0(%rax,%rax,1)
mov    (%r12,%r14,8),%rax
movss  (%rax,%r15,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    11f0 <save_fmatrix+0xa0>
jmp    11c0 <save_fmatrix+0x70>
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 = [42 x i8] c"I could not open the file %s for writing\0A\00"
@.str.2 = [6 x i8] c"%.4f\09\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @save_fmatrix(i8* %0, float** %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca float**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store i8* %0, i8** %5
store float** %1, float*** %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** %11
%14 = load i32*, i32** %11
%15 = icmp ne i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %4
%17 = load i8*, i8** %5
%18 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %4
store i32 1, i32* %9
br label %20
20: ; preds = %48, %19
%21 = load i32, i32* %9
%22 = load i32, i32* %7
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %51
24: ; preds = %20
store i32 1, i32* %10
br label %25
25: ; preds = %42, %24
%26 = load i32, i32* %10
%27 = load i32, i32* %8
%28 = icmp sle i32 %26, %27
br i1 %28, label %29, label %45
29: ; preds = %25
%30 = load i32*, i32** %11
%31 = load float**, float*** %6
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds float*, float** %31, i64 %33
%35 = load float*, float** %34
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds float, float* %35, i64 %37
%39 = load float, float* %38
%40 = fpext float %39 to double
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %40)
br label %42
42: ; preds = %29
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
br label %25
45: ; preds = %25
%46 = load i32*, i32** %11
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %45
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %20
51: ; preds = %20
%52 = load i32*, i32** %11
%53 = call i32 @fclose(i32* %52)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [42 x i8] c"I could not open the file %s for writing\0A\00"
@.str.2 = [6 x i8] c"%.4f\09\00"
define void @save_fmatrix(i8* %0, float** 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 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %4
%10 = icmp slt i32 %2, 1
br i1 %10, label %34, label %11
11: ; preds = %9
%12 = icmp slt i32 %3, 1
%13 = add i32 %3, 1
%14 = add nuw i32 %2, 1
%15 = zext i32 %14 to i64
%16 = zext i32 %13 to i64
br label %17
17: ; preds = %11, %30
%18 = phi i64 [ 1, %11 ], [ %32, %30 ]
br i1 %12, label %30, label %19
19: ; preds = %17
%20 = getelementptr inbounds float*, float** %1, i64 %18
br label %21
21: ; preds = %19, %21
%22 = phi i64 [ 1, %19 ], [ %28, %21 ]
%23 = load float*, float** %20
%24 = getelementptr inbounds float, float* %23, i64 %22
%25 = load float, float* %24
%26 = fpext float %25 to double
%27 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), double %26)
%28 = add nuw nsw i64 %22, 1
%29 = icmp eq i64 %28, %16
br i1 %29, label %30, label %21
30: ; preds = %21, %17
%31 = tail call i32 @fputc(i32 10, i32* %5)
%32 = add nuw nsw i64 %18, 1
%33 = icmp eq i64 %32, %15
br i1 %33, label %34, label %17
34: ; preds = %30, %9
%35 = tail call i32 @fclose(i32* %5)
ret void
}