#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 sprintf(char *, char *, int);
void mapload(int *matrix, int Nx, int Ny) {
  int file;
  char FileName[50];
  for (int f = 1; f <= 3; f++) {
    file = sprintf(FileName, "Maps/Contour_VALLE_960_Border_%d.dat", f);
    file++;
    FILE *file = fopen(FileName, "r");
    int x = 0, y = 0;
    for (; fscanf(file, "%d\t%d", &x, &y) && !feof(file);)
      matrix[y * Nx + x] = 2;
    fclose(file);
  }
}


x86 assembly (clang, -O0):
<mapload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x1,-0x54(%rbp)
cmpl   $0x3,-0x54(%rbp)
jg     1236 <mapload+0xe6>
lea    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%edx
lea    0xe7f(%rip),%rsi
call   1070 <sprintf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x60(%rbp),%rdi
lea    0xe68(%rip),%rsi
lea    -0x64(%rbp),%rdx
lea    -0x68(%rbp),%rcx
call   1040 <fscanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x69(%rbp)
je     11f2 <mapload+0xa2>
mov    -0x60(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
test   $0x1,%al
jne    1202 <mapload+0xb2>
jmp    121f <mapload+0xcf>
mov    -0x8(%rbp),%rax
mov    -0x68(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x64(%rbp),%ecx
movslq %ecx,%rcx
movl   $0x2,(%rax,%rcx,4)
jmp    11b4 <mapload+0x64>
mov    -0x60(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1169 <mapload+0x19>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapload>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xe96(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%edx
call   1070 <sprintf@plt>
lea    0xea2(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe82(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rax,%rdi
call   1040 <fscanf@plt>
movslq %ebp,%rbp
test   %rax,%rax
je     120b <mapload+0xbb>
lea    0xe61(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x8(%rsp),%r13
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    120b <mapload+0xbb>
movslq 0x8(%rsp),%rax
imul   %rbp,%rax
movslq 0xc(%rsp),%rcx
add    %rax,%rcx
movl   $0x2,(%r14,%rcx,4)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1040 <fscanf@plt>
test   %rax,%rax
jne    11d0 <mapload+0x80>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xde6(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2,%edx
call   1070 <sprintf@plt>
lea    0xdf2(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xdd2(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rax,%rdi
call   1040 <fscanf@plt>
test   %rax,%rax
je     12bb <mapload+0x16b>
lea    0xdb4(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x8(%rsp),%r13
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    12bb <mapload+0x16b>
movslq 0x8(%rsp),%rax
imul   %rbp,%rax
movslq 0xc(%rsp),%rcx
add    %rax,%rcx
movl   $0x2,(%r14,%rcx,4)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1040 <fscanf@plt>
test   %rax,%rax
jne    1280 <mapload+0x130>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xd36(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1070 <sprintf@plt>
lea    0xd42(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xd22(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rax,%rdi
call   1040 <fscanf@plt>
test   %rax,%rax
je     136b <mapload+0x21b>
lea    0xd04(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x8(%rsp),%r13
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    136b <mapload+0x21b>
movslq 0x8(%rsp),%rax
imul   %rbp,%rax
movslq 0xc(%rsp),%rcx
add    %rax,%rcx
movl   $0x2,(%r14,%rcx,4)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1040 <fscanf@plt>
test   %rax,%rax
jne    1330 <mapload+0x1e0>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Maps/Contour_VALLE_960_Border_%d.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%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 [50 x i8]
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 1, i32* %9
br label %13
13: ; preds = %47, %3
%14 = load i32, i32* %9
%15 = icmp sle i32 %14, 3
br i1 %15, label %16, label %50
16: ; preds = %13
%17 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%18 = load i32, i32* %9
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
store i32 %21, i32* %7
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %24
24: ; preds = %35, %16
%25 = load i32*, i32** %10
%26 = call i64 @fscanf(i32* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %11, i32* %12)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i32*, i32** %10
%30 = call i32 @feof(i32* %29)
%31 = icmp ne i32 %30, 0
%32 = xor i1 %31, true
br label %33
33: ; preds = %28, %24
%34 = phi i1 [ false, %24 ], [ %32, %28 ]
br i1 %34, label %35, label %44
35: ; preds = %33
%36 = load i32*, i32** %4
%37 = load i32, i32* %12
%38 = load i32, i32* %5
%39 = mul nsw i32 %37, %38
%40 = load i32, i32* %11
%41 = add nsw i32 %39, %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %36, i64 %42
store i32 2, i32* %43
br label %24
44: ; preds = %33
%45 = load i32*, i32** %10
%46 = call i32 @fclose(i32* %45)
br label %47
47: ; preds = %44
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
br label %13
50: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"Maps/Contour_VALLE_960_Border_%d.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%d\09%d\00"
define void @mapload(i32* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = alloca [50 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 1)
%11 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
store i32 0, i32* %6
%12 = call i64 @fscanf(i32* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %5, i32* %6)
%13 = icmp eq i64 %12, 0
br i1 %13, label %26, label %14
14: ; preds = %3, %17
%15 = call i32 @feof(i32* %11)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = load i32, i32* %6
%19 = mul nsw i32 %18, %1
%20 = load i32, i32* %5
%21 = add nsw i32 %19, %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %0, i64 %22
store i32 2, i32* %23
%24 = call i64 @fscanf(i32* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %5, i32* %6)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %14
26: ; preds = %14, %17, %3
%27 = call i32 @fclose(i32* %11)
%28 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 2)
%29 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
store i32 0, i32* %6
%30 = call i64 @fscanf(i32* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %5, i32* %6)
%31 = icmp eq i64 %30, 0
br i1 %31, label %44, label %32
32: ; preds = %26, %35
%33 = call i32 @feof(i32* %29)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %32
%36 = load i32, i32* %6
%37 = mul nsw i32 %36, %1
%38 = load i32, i32* %5
%39 = add nsw i32 %37, %38
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %0, i64 %40
store i32 2, i32* %41
%42 = call i64 @fscanf(i32* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %5, i32* %6)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %32
44: ; preds = %32, %35, %26
%45 = call i32 @fclose(i32* %29)
%46 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 3)
%47 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
store i32 0, i32* %6
%48 = call i64 @fscanf(i32* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %5, i32* %6)
%49 = icmp eq i64 %48, 0
br i1 %49, label %62, label %50
50: ; preds = %44, %53
%51 = call i32 @feof(i32* %47)
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %62
53: ; preds = %50
%54 = load i32, i32* %6
%55 = mul nsw i32 %54, %1
%56 = load i32, i32* %5
%57 = add nsw i32 %55, %56
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %0, i64 %58
store i32 2, i32* %59
%60 = call i64 @fscanf(i32* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %5, i32* %6)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %50
62: ; preds = %50, %53, %44
%63 = call i32 @fclose(i32* %47)
ret void
}