#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_imatrix(char *output_filename, int **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, "%d\t", data[i][j]);
    }
    fprintf(output_file, "\n");
  }
  fclose(output_file);
}


x86 assembly (clang, -O0):
<save_imatrix>:
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_imatrix+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     11fe <save_imatrix+0xbe>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     11de <save_imatrix+0x9e>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe63(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119f <save_imatrix+0x5f>
mov    -0x28(%rbp),%rdi
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118c <save_imatrix+0x4c>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_imatrix>:
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_imatrix+0x3a>
test   %r15d,%r15d
jg     119e <save_imatrix+0x4e>
jmp    1210 <save_imatrix+0xc0>
lea    0xe71(%rip),%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
test   %r15d,%r15d
jle    1210 <save_imatrix+0xc0>
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_imatrix+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     1210 <save_imatrix+0xc0>
cmpl   $0x0,0x8(%rsp)
jle    11c0 <save_imatrix+0x70>
mov    $0x1,%r15d
nopl   0x0(%rax,%rax,1)
mov    (%r12,%r14,8),%rax
mov    (%rax,%r15,4),%edx
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    11f0 <save_imatrix+0xa0>
jmp    11c0 <save_imatrix+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 = [4 x i8] c"%d\09\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @save_imatrix(i8* %0, i32** %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store i8* %0, i8** %5
store i32** %1, i32*** %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 = %47, %19
%21 = load i32, i32* %9
%22 = load i32, i32* %7
%23 = icmp sle i32 %21, %22
br i1 %23, label %24, label %50
24: ; preds = %20
store i32 1, i32* %10
br label %25
25: ; preds = %41, %24
%26 = load i32, i32* %10
%27 = load i32, i32* %8
%28 = icmp sle i32 %26, %27
br i1 %28, label %29, label %44
29: ; preds = %25
%30 = load i32*, i32** %11
%31 = load i32**, i32*** %6
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32*, i32** %31, i64 %33
%35 = load i32*, i32** %34
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %29
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %25
44: ; preds = %25
%45 = load i32*, i32** %11
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %44
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
br label %20
50: ; preds = %20
%51 = load i32*, i32** %11
%52 = call i32 @fclose(i32* %51)
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 = [4 x i8] c"%d\09\00"
define void @save_imatrix(i8* %0, i32** 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 %33, 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, %29
%18 = phi i64 [ 1, %11 ], [ %31, %29 ]
br i1 %12, label %29, label %19
19: ; preds = %17
%20 = getelementptr inbounds i32*, i32** %1, i64 %18
br label %21
21: ; preds = %19, %21
%22 = phi i64 [ 1, %19 ], [ %27, %21 ]
%23 = load i32*, i32** %20
%24 = getelementptr inbounds i32, i32* %23, i64 %22
%25 = load i32, i32* %24
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = add nuw nsw i64 %22, 1
%28 = icmp eq i64 %27, %16
br i1 %28, label %29, label %21
29: ; preds = %21, %17
%30 = tail call i32 @fputc(i32 10, i32* %5)
%31 = add nuw nsw i64 %18, 1
%32 = icmp eq i64 %31, %15
br i1 %32, label %33, label %17
33: ; preds = %29, %9
%34 = tail call i32 @fclose(i32* %5)
ret void
}