#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int);
int /*<<< orphan*/ printf(char *);
void prnt(int *matrix, int nx, int ny) {
  FILE *f = fopen("boolmatrix.dat", "w");
  int i;
  if (f == NULL) {
    printf("Error opening file!\n");
    exit(1);
  }
  for (i = 1; i <= nx * ny; i++) {
    int b_i = (i - 1) / nx, b_j = (i - 1) % nx;
    fprintf(f, "%d\t%d\t%d\n", b_i, b_j,
            (matrix[i - 1] == 2) ? 0 : matrix[i - 1]);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<prnt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119a <prnt+0x4a>
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   -0x10(%rbp),%ecx
cmp    %ecx,%eax
jg     123d <prnt+0xed>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmpl   $0x2,(%rax,%rcx,4)
jne    1202 <prnt+0xb2>
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
jmp    1215 <prnt+0xc5>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%edx
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%r8d
lea    0xdfc(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a1 <prnt+0x51>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prnt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%r12d
mov    %rdi,%r14
lea    0xe96(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e5 <prnt+0x95>
mov    %rax,%r13
imul   %r12d,%ebp
test   %ebp,%ebp
jle    11cf <prnt+0x7f>
mov    %ebp,%ebx
lea    0xe82(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
cltd
idiv   %r12d
mov    %edx,%ecx
mov    (%r14,%rbp,4),%r8d
cmp    $0x2,%r8d
mov    $0x0,%edx
cmove  %edx,%r8d
mov    %r13,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11a0 <prnt+0x50>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"boolmatrix.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [21 x i8] c"Error opening file!\0A\00"
@.str.3 = [10 x i8] c"%d\09%d\09%d\0A\00"
define void @prnt(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %3
store i32 1, i32* %8
br label %18
18: ; preds = %54, %17
%19 = load i32, i32* %8
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = mul nsw i32 %20, %21
%23 = icmp sle i32 %19, %22
br i1 %23, label %24, label %57
24: ; preds = %18
%25 = load i32, i32* %8
%26 = sub nsw i32 %25, 1
%27 = load i32, i32* %5
%28 = sdiv i32 %26, %27
store i32 %28, i32* %9
%29 = load i32, i32* %8
%30 = sub nsw i32 %29, 1
%31 = load i32, i32* %5
%32 = srem i32 %30, %31
store i32 %32, i32* %10
%33 = load i32*, i32** %7
%34 = load i32, i32* %9
%35 = load i32, i32* %10
%36 = load i32*, i32** %4
%37 = load i32, i32* %8
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %36, i64 %39
%41 = load i32, i32* %40
%42 = icmp eq i32 %41, 2
br i1 %42, label %43, label %44
43: ; preds = %24
br label %51
44: ; preds = %24
%45 = load i32*, i32** %4
%46 = load i32, i32* %8
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %45, i64 %48
%50 = load i32, i32* %49
br label %51
51: ; preds = %44, %43
%52 = phi i32 [ 0, %43 ], [ %50, %44 ]
%53 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %35, i32 %52)
br label %54
54: ; preds = %51
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
store i32 %56, i32* %8
br label %18
57: ; preds = %18
%58 = load i32*, i32** %7
%59 = call i32 @fclose(i32* %58)
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"boolmatrix.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [10 x i8] c"%d\09%d\09%d\0A\00"
@str = [20 x i8] c"Error opening file!\00"
define void @prnt(i32* nocapture %0, i32 %1, i32 %2) {
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = mul i32 %2, %1
%8 = icmp slt i32 %7, 1
br i1 %8, label %28, label %9
9: ; preds = %6
%10 = add nuw i32 %7, 1
%11 = zext i32 %10 to i64
br label %15
12: ; preds = %3
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9, %15
%16 = phi i64 [ 1, %9 ], [ %26, %15 ]
%17 = add nsw i64 %16, -1
%18 = trunc i64 %17 to i32
%19 = sdiv i32 %18, %1
%20 = srem i32 %18, %1
%21 = getelementptr inbounds i32, i32* %0, i64 %17
%22 = load i32, i32* %21
%23 = icmp eq i32 %22, 2
%24 = select i1 %23, i32 0, i32 %22
%25 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32 %20, i32 %24)
%26 = add nuw nsw i64 %16, 1
%27 = icmp eq i64 %26, %11
br i1 %27, label %28, label %15
28: ; preds = %15, %6
%29 = tail call i32 @fclose(i32* %4)
ret void
}