#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ perror(char *);
void readInputFile(int puzzle[][9]) {
  FILE *fp;
  fp = fopen("/home/shankz/workspace/sudoku_proj/src/puzzle.txt", "r");
  if (fp == NULL) {
    perror("Error while reading the file");
    exit(EXIT_FAILURE);
  }
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      fscanf(fp, "%1d", &puzzle[i][j]);
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<readInputFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rdi
lea    0xec8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1198 <readInputFile+0x48>
lea    0xeaf(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jge    1205 <readInputFile+0xb5>
movl   $0x0,-0x18(%rbp)
cmpl   $0x9,-0x18(%rbp)
jge    11f2 <readInputFile+0xa2>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
movslq -0x14(%rbp),%rax
imul   $0x24,%rax,%rax
add    %rax,%rdx
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe72(%rip),%rsi
call   1040 <fscanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b0 <readInputFile+0x60>
jmp    11f7 <readInputFile+0xa7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119f <readInputFile+0x4f>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readInputFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe9e(%rip),%rdi
lea    0xec9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     125b <readInputFile+0x10b>
mov    %rax,%r12
xor    %ebx,%ebx
lea    0xece(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r14,%rbx,1),%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fscanf@plt>
lea    (%r14,%rbx,1),%rdx
add    $0x4,%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fscanf@plt>
lea    (%r14,%rbx,1),%rdx
add    $0x8,%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fscanf@plt>
lea    (%r14,%rbx,1),%rdx
add    $0xc,%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fscanf@plt>
lea    (%r14,%rbx,1),%rdx
add    $0x10,%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fscanf@plt>
lea    (%r14,%rbx,1),%rdx
add    $0x14,%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fscanf@plt>
lea    (%r14,%rbx,1),%rdx
add    $0x18,%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fscanf@plt>
lea    (%r14,%rbx,1),%rdx
add    $0x1c,%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fscanf@plt>
lea    (%r14,%rbx,1),%rdx
add    $0x20,%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <fscanf@plt>
add    $0x24,%rbx
cmp    $0x144,%rbx
jne    1190 <readInputFile+0x40>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
lea    0xdd2(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [50 x i8] c"/home/shankz/workspace/sudoku_proj/src/puzzle.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"Error while reading the file\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%1d\00"
define void @readInputFile([9 x i32]* %0) {
%2 = alloca [9 x i32]*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store [9 x i32]* %0, [9 x i32]** %2
%6 = call i32* @fopen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
store i32 0, i32* %4
br label %14
14: ; preds = %35, %13
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 9
br i1 %16, label %17, label %38
17: ; preds = %14
store i32 0, i32* %5
br label %18
18: ; preds = %31, %17
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 9
br i1 %20, label %21, label %34
21: ; preds = %18
%22 = load i32*, i32** %3
%23 = load [9 x i32]*, [9 x i32]** %2
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [9 x i32], [9 x i32]* %23, i64 %25
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [9 x i32], [9 x i32]* %26, i64 0, i64 %28
%30 = call i32 @fscanf(i32* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %29)
br label %31
31: ; preds = %21
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %18
34: ; preds = %18
br label %35
35: ; preds = %34
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %14
38: ; preds = %14
%39 = load i32*, i32** %3
%40 = call i32 @fclose(i32* %39)
ret void
}

LLVM IR (-O2):
@.str = [50 x i8] c"/home/shankz/workspace/sudoku_proj/src/puzzle.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [29 x i8] c"Error while reading the file\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%1d\00"
define void @readInputFile([9 x i32]* %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %1, %8
%9 = phi i64 [ %28, %8 ], [ 0, %1 ]
%10 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %9, i64 0
%11 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %10)
%12 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %9, i64 1
%13 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %12)
%14 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %9, i64 2
%15 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %14)
%16 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %9, i64 3
%17 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %16)
%18 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %9, i64 4
%19 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %18)
%20 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %9, i64 5
%21 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %20)
%22 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %9, i64 6
%23 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %22)
%24 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %9, i64 7
%25 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %24)
%26 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %9, i64 8
%27 = tail call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %26)
%28 = add nuw nsw i64 %9, 1
%29 = icmp eq i64 %28, 9
br i1 %29, label %30, label %8
30: ; preds = %8
%31 = tail call i32 @fclose(i32* %2)
ret void
}