#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *, int *, int *);
void mapload(int *B, int Nx, int Ny) {
  FILE *file = fopen("boolmatrix.dat", "r");
  int x = 0, y = 0, b = 0;
  for (; fscanf(file, "%d\t%d\t%d", &y, &x, &b) && !feof(file);)
    B[y * Nx + x] = b;
  fclose(file);
}


x86 assembly (clang, -O0):
<mapload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xea7(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe88(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x24(%rbp),%r8
call   1040 <fscanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x25(%rbp)
je     11c0 <mapload+0x80>
mov    -0x18(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11d0 <mapload+0x90>
jmp    11ec <mapload+0xac>
mov    -0x24(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    117e <mapload+0x3e>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapload>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xea6(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xe89(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x14(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %rax,%rdi
call   1040 <fscanf@plt>
test   %rax,%rax
je     1202 <mapload+0xc2>
movslq %ebp,%r15
lea    0x10(%rsp),%r12
lea    0x14(%rsp),%r13
lea    0xc(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    1202 <mapload+0xc2>
mov    0xc(%rsp),%eax
movslq 0x10(%rsp),%rcx
imul   %r15,%rcx
movslq 0x14(%rsp),%rdx
add    %rcx,%rdx
mov    %eax,(%r14,%rdx,4)
mov    %rbx,%rdi
lea    0xe22(%rip),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   1040 <fscanf@plt>
test   %rax,%rax
jne    11c0 <mapload+0x80>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"boolmatrix.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"%d\09%d\09%d\00"
define void @mapload(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
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %12
12: ; preds = %23, %3
%13 = load i32*, i32** %7
%14 = call i64 @fscanf(i32* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %9, i32* %8, i32* %10)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i32*, i32** %7
%18 = call i32 @feof(i32* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br label %21
21: ; preds = %16, %12
%22 = phi i1 [ false, %12 ], [ %20, %16 ]
br i1 %22, label %23, label %33
23: ; preds = %21
%24 = load i32, i32* %10
%25 = load i32*, i32** %4
%26 = load i32, i32* %9
%27 = load i32, i32* %5
%28 = mul nsw i32 %26, %27
%29 = load i32, i32* %8
%30 = add nsw i32 %28, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %25, i64 %31
store i32 %24, i32* %32
br label %12
33: ; preds = %21
%34 = load i32*, i32** %7
%35 = call i32 @fclose(i32* %34)
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"boolmatrix.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"%d\09%d\09%d\00"
define void @mapload(i32* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = 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))
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%10 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%11 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %5, i32* %4, i32* %6)
%12 = icmp eq i64 %11, 0
br i1 %12, label %26, label %13
13: ; preds = %3, %16
%14 = call i32 @feof(i32* %7)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = mul nsw i32 %18, %1
%20 = load i32, i32* %4
%21 = add nsw i32 %19, %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %0, i64 %22
store i32 %17, i32* %23
%24 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %5, i32* %4, i32* %6)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %13
26: ; preds = %13, %16, %3
%27 = call i32 @fclose(i32* %7)
ret void
}