#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
void loadBoard(char *fileName, unsigned char *a, unsigned int rows,
               unsigned int cols) {
  printf("start loading the file \n");
  FILE *file = fopen(fileName, "r");
  if (file == NULL) {
    fprintf(stderr, "Error while opening file\n");
    exit(1);
  }
  char line[4];
  while (fgets(line, 40, file) != NULL) {
    printf("reading line \n");
    printf("line readed %s", line);
    int i = line[0] - '0';
    int j = line[2] - '0';
    printf("line pos i  %i \n", i);
    printf("line pos j  %i \n", j);
    a[i * cols + j] = '1';
  }
  printf("end loading the file \n");
  fclose(file);
}


x86 assembly (clang, -O0):
<loadBoard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c2 <loadBoard+0x62>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11c7 <loadBoard+0x67>
lea    -0x24(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x28,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1252 <loadBoard+0xf2>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x24(%rbp),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x24(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x28(%rbp)
movsbl -0x22(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%esi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    -0x2c(%rbp),%ecx
mov    %ecx,%ecx
movb   $0x31,(%rax,%rcx,1)
jmp    11c7 <loadBoard+0x67>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadBoard>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xec2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe69(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1259 <loadBoard+0xe9>
mov    %rax,%r13
nopl   0x0(%rax,%rax,1)
lea    0x4(%rsp),%rdi
mov    $0x28,%esi
mov    %r13,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1236 <loadBoard+0xc6>
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
lea    0xe42(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
movsbl 0x4(%rsp),%r15d
add    $0xffffffd0,%r15d
movsbl 0x6(%rsp),%r14d
mov    %r12d,%ebp
lea    -0x30(%r14),%r12d
lea    0xe27(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe27(%rip),%rdi
mov    %r12d,%esi
mov    %ebp,%r12d
xor    %eax,%eax
call   1050 <printf@plt>
imul   %ebp,%r15d
lea    (%r15,%r14,1),%eax
add    $0xffffffd0,%eax
movb   $0x31,(%rbx,%rax,1)
jmp    11b0 <loadBoard+0x40>
lea    0xe28(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"start loading the file \0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Error while opening file\0A\00"
@.str.3 = [15 x i8] c"reading line \0A\00"
@.str.4 = [15 x i8] c"line readed %s\00"
@.str.5 = [17 x i8] c"line pos i %i \0A\00"
@.str.6 = [17 x i8] c"line pos j %i \0A\00"
@.str.7 = [23 x i8] c"end loading the file \0A\00"
define void @loadBoard(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca [4 x i8]
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %9
%16 = load i32*, i32** %9
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %4
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %4
br label %23
23: ; preds = %28, %22
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%25 = load i32*, i32** %9
%26 = call i32* @fgets(i8* %24, i32 40, i32* %25)
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %52
28: ; preds = %23
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = sub nsw i32 %34, 48
store i32 %35, i32* %11
%36 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 2
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = sub nsw i32 %38, 48
store i32 %39, i32* %12
%40 = load i32, i32* %11
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %12
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %42)
%44 = load i8*, i8** %6
%45 = load i32, i32* %11
%46 = load i32, i32* %8
%47 = mul i32 %45, %46
%48 = load i32, i32* %12
%49 = add i32 %47, %48
%50 = zext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %44, i64 %50
store i8 49, i8* %51
br label %23
52: ; preds = %23
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%54 = load i32*, i32** %9
%55 = call i32 @fclose(i32* %54)
ret void
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"Error while opening file\0A\00"
@.str.4 = [15 x i8] c"line readed %s\00"
@.str.5 = [17 x i8] c"line pos i %i \0A\00"
@.str.6 = [17 x i8] c"line pos j %i \0A\00"
@str = [24 x i8] c"start loading the file \00"
@str.8 = [22 x i8] c"end loading the file \00"
@str.9 = [14 x i8] c"reading line \00"
define void @loadBoard(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = alloca [4 x i8]
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %4
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%15 = call i32* @fgets(i8* %14, i32 40, i32* %7)
%16 = icmp eq i32* %15, null
br i1 %16, label %36, label %17
17: ; preds = %13
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
br label %19
19: ; preds = %17, %19
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.9, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %14)
%22 = load i8, i8* %14
%23 = sext i8 %22 to i32
%24 = add nsw i32 %23, -48
%25 = load i8, i8* %18
%26 = sext i8 %25 to i32
%27 = add nsw i32 %26, -48
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %27)
%30 = mul i32 %24, %3
%31 = add i32 %30, %27
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %1, i64 %32
store i8 49, i8* %33
%34 = call i32* @fgets(i8* %14, i32 40, i32* %7)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %19
36: ; preds = %19, %13
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
%38 = call i32 @fclose(i32* %7)
ret void
}