#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);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ nrerror(char *);
void write_imatrix(int **m, long nrl, long nrh, long ncl, long nch,
                   char *format, char *filename) {
  long i, j;
  FILE *f;
  f = fopen(filename, "wt");
  if (f == NULL) {
    nrerror("Can't open file in write_imatrix");
  }
  for (i = nrl; i <= nrh; i++) {
    for (j = ncl; j <= nch; j++) {
      fprintf(f, format, m[i][j]);
    }
    fputc('\n', f);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<write_imatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    119f <write_imatrix+0x4f>
lea    0xe69(%rip),%rdi
call   1030 <nrerror@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jg     121b <write_imatrix+0xcb>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x28(%rbp),%rax
jg     11fc <write_imatrix+0xac>
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
call   1060 <fprintf@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11bd <write_imatrix+0x6d>
mov    -0x48(%rbp),%rsi
mov    $0xa,%edi
call   1050 <fputc@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11a7 <write_imatrix+0x57>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_imatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r13
mov    %r8,(%rsp)
mov    %rcx,0x8(%rsp)
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    0x50(%rsp),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     1193 <write_imatrix+0x43>
cmp    %r15,%rbp
jg     11a4 <write_imatrix+0x54>
jmp    11ba <write_imatrix+0x6a>
lea    0xe69(%rip),%rdi
call   1030 <nrerror@plt>
cmp    %r15,%rbp
jle    11ba <write_imatrix+0x6a>
mov    %r14,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
mov    (%rsp),%rax
lea    0x1(%rax),%r12
mov    %r15,0x10(%rsp)
jmp    11ee <write_imatrix+0x9e>
nopl   0x0(%rax)
mov    $0xa,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
lea    0x1(%rbp),%rax
mov    0x10(%rsp),%r15
cmp    %r15,%rbp
mov    %rax,%rbp
je     11a4 <write_imatrix+0x54>
mov    0x8(%rsp),%rax
cmp    (%rsp),%rax
jg     11d0 <write_imatrix+0x80>
mov    0x8(%rsp),%r15
xchg   %ax,%ax
mov    (%rbx,%rbp,8),%rax
mov    (%rax,%r15,4),%edx
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <fprintf@plt>
add    $0x1,%r15
cmp    %r15,%r12
jne    1200 <write_imatrix+0xb0>
jmp    11d0 <write_imatrix+0x80>

LLVM IR (-O0):
@.str = [3 x i8] c"wt\00"
@.str.1 = [33 x i8] c"Can't open file in write_imatrix\00"
define void @write_imatrix(i32** %0, i64 %1, i64 %2, i64 %3, i64 %4, i8* %5, i8* %6) {
%8 = alloca i32**
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i64
%17 = alloca i32*
store i32** %0, i32*** %8
store i64 %1, i64* %9
store i64 %2, i64* %10
store i64 %3, i64* %11
store i64 %4, i64* %12
store i8* %5, i8** %13
store i8* %6, i8** %14
%18 = load i8*, i8** %14
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %17
%20 = load i32*, i32** %17
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %7
%23 = call i32 @nrerror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %7
%25 = load i64, i64* %9
store i64 %25, i64* %15
br label %26
26: ; preds = %53, %24
%27 = load i64, i64* %15
%28 = load i64, i64* %10
%29 = icmp sle i64 %27, %28
br i1 %29, label %30, label %56
30: ; preds = %26
%31 = load i64, i64* %11
store i64 %31, i64* %16
br label %32
32: ; preds = %47, %30
%33 = load i64, i64* %16
%34 = load i64, i64* %12
%35 = icmp sle i64 %33, %34
br i1 %35, label %36, label %50
36: ; preds = %32
%37 = load i32*, i32** %17
%38 = load i8*, i8** %13
%39 = load i32**, i32*** %8
%40 = load i64, i64* %15
%41 = getelementptr inbounds i32*, i32** %39, i64 %40
%42 = load i32*, i32** %41
%43 = load i64, i64* %16
%44 = getelementptr inbounds i32, i32* %42, i64 %43
%45 = load i32, i32* %44
%46 = call i32 @fprintf(i32* %37, i8* %38, i32 %45)
br label %47
47: ; preds = %36
%48 = load i64, i64* %16
%49 = add nsw i64 %48, 1
store i64 %49, i64* %16
br label %32
50: ; preds = %32
%51 = load i32*, i32** %17
%52 = call i32 @fputc(i8 signext 10, i32* %51)
br label %53
53: ; preds = %50
%54 = load i64, i64* %15
%55 = add nsw i64 %54, 1
store i64 %55, i64* %15
br label %26
56: ; preds = %26
%57 = load i32*, i32** %17
%58 = call i32 @fclose(i32* %57)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wt\00"
@.str.1 = [33 x i8] c"Can't open file in write_imatrix\00"
define void @write_imatrix(i32** nocapture %0, i64 %1, i64 %2, i64 %3, i64 %4, i8* nocapture %5, i8* nocapture %6) {
%8 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @nrerror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = icmp sgt i64 %1, %2
br i1 %13, label %32, label %14
14: ; preds = %12
%15 = icmp sgt i64 %3, %4
br label %16
16: ; preds = %14, %28
%17 = phi i64 [ %1, %14 ], [ %30, %28 ]
br i1 %15, label %28, label %18
18: ; preds = %16
%19 = getelementptr inbounds i32*, i32** %0, i64 %17
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ %3, %18 ], [ %26, %20 ]
%22 = load i32*, i32** %19
%23 = getelementptr inbounds i32, i32* %22, i64 %21
%24 = load i32, i32* %23
%25 = tail call i32 @fprintf(i32* %8, i8* %5, i32 %24)
%26 = add i64 %21, 1
%27 = icmp eq i64 %21, %4
br i1 %27, label %28, label %20
28: ; preds = %20, %16
%29 = tail call i32 @fputc(i8 signext 10, i32* %8)
%30 = add i64 %17, 1
%31 = icmp eq i64 %17, %2
br i1 %31, label %32, label %16
32: ; preds = %28, %12
%33 = tail call i32 @fclose(i32* %8)
ret void
}