#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 */

/* Variables and functions */
scalar_t__ check_all(int *);
int /*<<< orphan*/ file_2_sudoku(int *, char *);
int /*<<< orphan*/ print_sudoku(int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ solve_sudoku(int *);
int main(int argc, char *argv[]) {
  int sudoku[81];
  int *ptr;
  int i;
  i = 0;
  if (argc != 2) {
    printf("USAGE: ./sudoku_solver FILENAME\n");
    printf("FILENAME is the file where the sudoku is stored. It has to be a "
           "string of 81 integers from 0 to 9, without spaces\n");
    printf("The 0's represent the blank cells\n");
    return 1;
  }
  if (!(file_2_sudoku(sudoku, argv[1])))
    printf("[FILE 2 SUDOKU] File format not valid");
  if (check_all(sudoku)) {
    printf("Error. Invalid Sudoku.\n");
    return 1;
  }
  printf("Problem\n");
  print_sudoku(sudoku);
  printf("Solving... Be patient!\n");
  solve_sudoku(sudoku);
  printf("Solution\n");
  print_sudoku(sudoku);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x16c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ad <main+0x5d>
lea    0xe7c(%rip),%rdi
call   1050 <printf@plt>
lea    0xe91(%rip),%rdi
call   1050 <printf@plt>
lea    0xef8(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1253 <main+0x103>
lea    -0x160(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1070 <file_2_sudoku@plt>
cmp    $0x0,%eax
jne    11d6 <main+0x86>
lea    0xee6(%rip),%rdi
call   1050 <printf@plt>
lea    -0x160(%rbp),%rdi
call   1060 <check_all@plt>
cmp    $0x0,%rax
je     1204 <main+0xb4>
lea    0xeea(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1253 <main+0x103>
lea    0xeea(%rip),%rdi
call   1050 <printf@plt>
lea    -0x160(%rbp),%rdi
call   1030 <print_sudoku@plt>
lea    0xedb(%rip),%rdi
call   1050 <printf@plt>
lea    -0x160(%rbp),%rdi
call   1040 <solve_sudoku@plt>
lea    0xedb(%rip),%rdi
call   1050 <printf@plt>
lea    -0x160(%rbp),%rdi
call   1030 <print_sudoku@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x150,%rsp
cmp    $0x2,%edi
jne    119f <main+0x3f>
mov    0x8(%rsi),%rsi
mov    %rsp,%rdi
call   1080 <file_2_sudoku@plt>
test   %eax,%eax
jne    1189 <main+0x29>
lea    0xe7c(%rip),%rdi
call   1060 <printf@plt>
mov    %rsp,%rdi
call   1070 <check_all@plt>
test   %rax,%rax
je     11ca <main+0x6a>
lea    0xeb1(%rip),%rdi
jmp    11be <main+0x5e>
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
lea    0xf39(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    120b <main+0xab>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <print_sudoku@plt>
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <solve_sudoku@plt>
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <print_sudoku@plt>
xor    %eax,%eax
add    $0x150,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [33 x i8] c"USAGE: ./sudoku_solver FILENAME\0A\00"
@.str.1 = [115 x i8] c"FILENAME is the file where the sudoku is stored. It has to be a string of 81 integers from 0 to 9, without spaces\0A\00"
@.str.2 = [35 x i8] c"The 0's represent the blank cells\0A\00"
@.str.3 = [38 x i8] c"[FILE 2 SUDOKU] File format not valid\00"
@.str.4 = [24 x i8] c"Error. Invalid Sudoku.\0A\00"
@.str.5 = [9 x i8] c"Problem\0A\00"
@.str.6 = [24 x i8] c"Solving... Be patient!\0A\00"
@.str.7 = [10 x i8] c"Solution\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [81 x i32]
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([115 x i8], [115 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %40
15: ; preds = %2
%16 = getelementptr inbounds [81 x i32], [81 x i32]* %6, i64 0, i64 0
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @file_2_sudoku(i32* %16, i8* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %15
%23 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %15
%25 = getelementptr inbounds [81 x i32], [81 x i32]* %6, i64 0, i64 0
%26 = call i64 @check_all(i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %40
30: ; preds = %24
%31 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%32 = getelementptr inbounds [81 x i32], [81 x i32]* %6, i64 0, i64 0
%33 = call i32 @print_sudoku(i32* %32)
%34 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%35 = getelementptr inbounds [81 x i32], [81 x i32]* %6, i64 0, i64 0
%36 = call i32 @solve_sudoku(i32* %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%38 = getelementptr inbounds [81 x i32], [81 x i32]* %6, i64 0, i64 0
%39 = call i32 @print_sudoku(i32* %38)
store i32 0, i32* %3
br label %40
40: ; preds = %30, %28, %11
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str.3 = [38 x i8] c"[FILE 2 SUDOKU] File format not valid\00"
@str = [8 x i8] c"Problem\00"
@str.8 = [23 x i8] c"Solving... Be patient!\00"
@str.9 = [9 x i8] c"Solution\00"
@str.10 = [23 x i8] c"Error. Invalid Sudoku.\00"
@str.11 = [32 x i8] c"USAGE: ./sudoku_solver FILENAME\00"
@str.12 = [114 x i8] c"FILENAME is the file where the sudoku is stored. It has to be a string of 81 integers from 0 to 9, without spaces\00"
@str.13 = [34 x i8] c"The 0's represent the blank cells\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [81 x i32]
%4 = bitcast [81 x i32]* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.11, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([114 x i8], [114 x i8]* @str.12, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.13, i64 0, i64 0))
br label %30
10: ; preds = %2
%11 = getelementptr inbounds [81 x i32], [81 x i32]* %3, i64 0, i64 0
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @file_2_sudoku(i32* %11, i8* %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = call i64 @check_all(i32* %11)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0))
br label %30
23: ; preds = %18
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%25 = call i32 @print_sudoku(i32* %11)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.8, i64 0, i64 0))
%27 = call i32 @solve_sudoku(i32* %11)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.9, i64 0, i64 0))
%29 = call i32 @print_sudoku(i32* %11)
br label %30
30: ; preds = %23, %21, %6
%31 = phi i32 [ 1, %6 ], [ 1, %21 ], [ 0, %23 ]
ret i32 %31
}