#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*/ stderr;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
void print_int_matrix(char *file_name, const int *matrix, const int nrows,
                      const int ncols) {
  int i, j;
  FILE *output;
  if (strcmp(file_name, "stdout") == 0) {
    output = stdout;
  } else {
    output = fopen(file_name, "w");
  }
  if (output == NULL) {
    fprintf(stderr, "Opening of file `%s' failed!\n", file_name);
  }
  for (i = 0; i < nrows; i++) {
    for (j = 0; j < ncols; j++) {
      fprintf(output, "%d ", matrix[j * nrows + i]);
    }
    fprintf(output, "\n");
  }
  if (output != stdout)
    fclose(output);
}


x86 assembly (clang, -O0):
<print_int_matrix>:
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   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1183 <print_int_matrix+0x43>
mov    0x2e61(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1197 <print_int_matrix+0x57>
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11be <print_int_matrix+0x7e>
mov    0x2e37(%rip),%rax
movslq (%rax),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1238 <print_int_matrix+0xf8>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1218 <print_int_matrix+0xd8>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d8 <print_int_matrix+0x98>
mov    -0x28(%rbp),%rdi
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c5 <print_int_matrix+0x85>
mov    -0x28(%rbp),%rax
mov    0x2d95(%rip),%rcx
cmp    (%rcx),%rax
je     1255 <print_int_matrix+0x115>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_int_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,0xc(%rsp)
mov    %edx,%r15d
mov    %rsi,0x10(%rsp)
mov    %rdi,%rbx
lea    0xe8c(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     124e <print_int_matrix+0xfe>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbp
test   %rbp,%rbp
jne    11b4 <print_int_matrix+0x64>
mov    0x2e40(%rip),%rax
movslq (%rax),%rdi
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %r15d,%r15d
jle    122c <print_int_matrix+0xdc>
mov    %r15d,%eax
mov    0xc(%rsp),%ecx
mov    %rcx,0x18(%rsp)
mov    %rax,0x20(%rsp)
lea    0x0(,%rax,4),%r14
lea    0xe4e(%rip),%rbx
xor    %r13d,%r13d
jmp    11fe <print_int_matrix+0xae>
xchg   %ax,%ax
mov    $0xa,%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
add    $0x1,%r13
addq   $0x4,0x10(%rsp)
cmp    0x20(%rsp),%r13
je     122c <print_int_matrix+0xdc>
cmpl   $0x0,0xc(%rsp)
jle    11e0 <print_int_matrix+0x90>
mov    0x18(%rsp),%r15
mov    0x10(%rsp),%r12
nop
mov    (%r12),%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    %r14,%r12
add    $0xffffffffffffffff,%r15
jne    1210 <print_int_matrix+0xc0>
jmp    11e0 <print_int_matrix+0x90>
mov    0x2da5(%rip),%rax
cmp    (%rax),%rbp
je     1266 <print_int_matrix+0x116>
mov    %rbp,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%rbp
test   %rbp,%rbp
jne    11b4 <print_int_matrix+0x64>
jmp    1199 <print_int_matrix+0x49>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"stdout\00"
@stdout = global i32* null
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"Opening of file `%s' failed!\0A\00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\00"
define void @print_int_matrix(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 i64 @strcmp(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = load i32*, i32** @stdout
store i32* %16, i32** %11
br label %20
17: ; preds = %4
%18 = load i8*, i8** %5
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %11
br label %20
20: ; preds = %17, %15
%21 = load i32*, i32** %11
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i32*
%27 = load i8*, i8** %5
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %23, %20
store i32 0, i32* %9
br label %30
30: ; preds = %57, %29
%31 = load i32, i32* %9
%32 = load i32, i32* %7
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %60
34: ; preds = %30
store i32 0, i32* %10
br label %35
35: ; preds = %51, %34
%36 = load i32, i32* %10
%37 = load i32, i32* %8
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %54
39: ; preds = %35
%40 = load i32*, i32** %11
%41 = load i32*, i32** %6
%42 = load i32, i32* %10
%43 = load i32, i32* %7
%44 = mul nsw i32 %42, %43
%45 = load i32, i32* %9
%46 = add nsw i32 %44, %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %41, i64 %47
%49 = load i32, i32* %48
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %39
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
br label %35
54: ; preds = %35
%55 = load i32*, i32** %11
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %57
57: ; preds = %54
%58 = load i32, i32* %9
%59 = add nsw i32 %58, 1
store i32 %59, i32* %9
br label %30
60: ; preds = %30
%61 = load i32*, i32** %11
%62 = load i32*, i32** @stdout
%63 = icmp ne i32* %61, %62
br i1 %63, label %64, label %67
64: ; preds = %60
%65 = load i32*, i32** %11
%66 = call i32 @fclose(i32* %65)
br label %67
67: ; preds = %64, %60
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"stdout\00"
@stdout = global i32* null
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [30 x i8] c"Opening of file `%s' failed!\0A\00"
@.str.3 = [4 x i8] c"%d \00"
define void @print_int_matrix(i8* %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = load i32*, i32** @stdout
br label %11
9: ; preds = %4
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %7
%12 = phi i32* [ %8, %7 ], [ %10, %9 ]
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
%18 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %19
19: ; preds = %14, %11
%20 = icmp sgt i32 %2, 0
br i1 %20, label %21, label %41
21: ; preds = %19
%22 = icmp sgt i32 %3, 0
%23 = zext i32 %2 to i64
%24 = zext i32 %2 to i64
%25 = zext i32 %3 to i64
br label %26
26: ; preds = %21, %37
%27 = phi i64 [ 0, %21 ], [ %39, %37 ]
br i1 %22, label %28, label %37
28: ; preds = %26, %28
%29 = phi i64 [ %35, %28 ], [ 0, %26 ]
%30 = mul nsw i64 %29, %23
%31 = add nuw nsw i64 %30, %27
%32 = getelementptr inbounds i32, i32* %1, i64 %31
%33 = load i32, i32* %32
%34 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = add nuw nsw i64 %29, 1
%36 = icmp eq i64 %35, %25
br i1 %36, label %37, label %28
37: ; preds = %28, %26
%38 = tail call i32 @fputc(i32 10, i32* %12)
%39 = add nuw nsw i64 %27, 1
%40 = icmp eq i64 %39, %24
br i1 %40, label %41, label %26
41: ; preds = %37, %19
%42 = load i32*, i32** @stdout
%43 = icmp eq i32* %12, %42
br i1 %43, label %46, label %44
44: ; preds = %41
%45 = tail call i32 @fclose(i32* %12)
br label %46
46: ; preds = %44, %41
ret void
}