#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 *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ load_line(int **, char *);
bool load_file(char *filepath, const int grid_num, int sudoku[9][9]) {
  FILE *file;
  char data[82];
  int count;
  count = 0;
  file = fopen(filepath, "r");
  while (fread(data, sizeof(char), 82, file)) {
    count++;
    if (grid_num == count) {
      load_line(sudoku, data);
      return true;
    }
  }
  fclose(file);
  return false;
}


x86 assembly (clang, -O0):
<load_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x52,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
je     11d1 <load_file+0x91>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x84(%rbp),%eax
jne    11cc <load_file+0x8c>
mov    -0x20(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1060 <load_line@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e1 <load_file+0xa1>
jmp    1174 <load_file+0x34>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
lea    0xeaa(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x52,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11a1 <load_file+0x61>
add    $0xffffffff,%ebp
jne    1170 <load_file+0x30>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1060 <load_line@plt>
mov    $0x1,%eax
jmp    11ab <load_file+0x6b>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @load_file(i8* %0, i32 %1, [9 x i32]* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [9 x i32]*
%8 = alloca i32*
%9 = alloca [82 x i8]
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store [9 x i32]* %2, [9 x i32]** %7
store i32 0, i32* %10
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
br label %13
13: ; preds = %29, %3
%14 = getelementptr inbounds [82 x i8], [82 x i8]* %9, i64 0, i64 0
%15 = load i32*, i32** %8
%16 = call i64 @fread(i8* %14, i32 1, i32 82, i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %13
%19 = load i32, i32* %10
%20 = add nsw i32 %19, 1
store i32 %20, i32* %10
%21 = load i32, i32* %6
%22 = load i32, i32* %10
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %29
24: ; preds = %18
%25 = load [9 x i32]*, [9 x i32]** %7
%26 = bitcast [9 x i32]* %25 to i32**
%27 = getelementptr inbounds [82 x i8], [82 x i8]* %9, i64 0, i64 0
%28 = call i32 @load_line(i32** %26, i8* %27)
store i32 1, i32* %4
br label %33
29: ; preds = %18
br label %13
30: ; preds = %13
%31 = load i32*, i32** %8
%32 = call i32 @fclose(i32* %31)
store i32 0, i32* %4
br label %33
33: ; preds = %30, %24
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @load_file(i8* nocapture %0, i32 %1, [9 x i32]* %2) {
%4 = alloca [82 x i8]
%5 = getelementptr inbounds [82 x i8], [82 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %11, %3
%8 = phi i32 [ 0, %3 ], [ %12, %11 ]
%9 = call i64 @fread(i8* %5, i32 1, i32 82, i32* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %7
%12 = add nuw nsw i32 %8, 1
%13 = icmp eq i32 %12, %1
br i1 %13, label %14, label %7
14: ; preds = %11
%15 = bitcast [9 x i32]* %2 to i32**
%16 = call i32 @load_line(i32** %15, i8* %5)
br label %19
17: ; preds = %7
%18 = tail call i32 @fclose(i32* %6)
br label %19
19: ; preds = %17, %14
%20 = phi i32 [ 1, %14 ], [ 0, %17 ]
ret i32 %20
}