#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 */
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free_puzzle(int, int **);
int **next_puzzle(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int **solve(int, int **);
void solve_file(char *name) {
  FILE *file;
  int x, y;
  if (file = fopen(name, "r")) {
    printf("Reading from file: %s\n", name);
    unsigned i = 0;
    for (;;) {
      int **puzzle = next_puzzle(3, file);
      if (feof(file))
        break;
      printf("   Solving puzzle #%u: ", ++i);
      if (puzzle) {
        int **soln;
        if (soln = solve(3, puzzle)) {
          printf("Solved.\n");
          for (y = 0; y < 9; y++) {
            printf("      ");
            for (x = 0; x < 9; x++)
              printf("%x", soln[x][y]);
            printf("\n");
          }
          free_puzzle(3, soln);
        } else {
          printf("No solution.\n");
        }
        free_puzzle(3, puzzle);
      } else {
        printf("Invalid length.\n");
      }
    }
    if (fclose(file))
      printf("Failed to close file: %s\n", name);
  } else {
    printf("Couldn't open file: %s\n", name);
  }
}


x86 assembly (clang, -O0):
<solve_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1315 <solve_file+0x1a5>
mov    -0x8(%rbp),%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x3,%edi
call   1060 <next_puzzle@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     11dd <solve_file+0x6d>
jmp    12eb <solve_file+0x17b>
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     12d8 <solve_file+0x168>
mov    -0x28(%rbp),%rsi
mov    $0x3,%edi
call   1030 <solve@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     12b7 <solve_file+0x147>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x9,-0x18(%rbp)
jge    12a4 <solve_file+0x134>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x9,-0x14(%rbp)
jge    1288 <solve_file+0x118>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    124f <solve_file+0xdf>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1230 <solve_file+0xc0>
mov    -0x30(%rbp),%rsi
mov    $0x3,%edi
call   1090 <free_puzzle@plt>
jmp    12c5 <solve_file+0x155>
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    $0x3,%edi
call   1090 <free_puzzle@plt>
jmp    12e6 <solve_file+0x176>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11b3 <solve_file+0x43>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1310 <solve_file+0x1a0>
mov    -0x8(%rbp),%rsi
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1327 <solve_file+0x1b7>
mov    -0x8(%rbp),%rsi
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xe58(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     120a <solve_file+0x7a>
mov    %rax,%rbp
lea    0xe46(%rip),%rdi
mov    %rbx,0x8(%rsp)
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x3,%edi
mov    %rbp,%rsi
call   1080 <next_puzzle@plt>
mov    %rax,%r13
mov    %rbp,%rdi
call   1090 <feof@plt>
test   %rax,%rax
mov    %rbp,%rbx
je     1229 <solve_file+0x99>
mov    %rbx,%rdi
call   1060 <fclose@plt>
test   %rax,%rax
je     13ae <solve_file+0x21e>
lea    0xe38(%rip),%rdi
mov    0x8(%rsp),%rbx
jmp    1211 <solve_file+0x81>
lea    0xe44(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <printf@plt>
lea    0xe01(%rip),%r12
lea    0xe01(%rip),%rbp
xor    %r14d,%r14d
mov    %rbx,0x10(%rsp)
jmp    127d <solve_file+0xed>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe16(%rip),%rdi
call   1050 <puts@plt>
mov    $0x3,%edi
mov    %rbx,%rsi
call   1080 <next_puzzle@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %rax,%rax
jne    11eb <solve_file+0x5b>
add    $0x1,%r14d
lea    0xd91(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
test   %r13,%r13
je     1250 <solve_file+0xc0>
mov    $0x3,%edi
mov    %r13,%rsi
call   1030 <solve@plt>
test   %rax,%rax
je     1390 <solve_file+0x200>
mov    %rax,%r15
lea    0xdd3(%rip),%rdi
call   1050 <puts@plt>
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r15),%rax
mov    (%rax,%rbx,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%r15),%rax
mov    (%rax,%rbx,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x10(%r15),%rax
mov    (%rax,%rbx,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x18(%r15),%rax
mov    (%rax,%rbx,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x20(%r15),%rax
mov    (%rax,%rbx,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x28(%r15),%rax
mov    (%rax,%rbx,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x30(%r15),%rax
mov    (%rax,%rbx,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x38(%r15),%rax
mov    (%rax,%rbx,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x40(%r15),%rax
mov    (%rax,%rbx,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x4,%rbx
cmp    $0x24,%rbx
jne    12c0 <solve_file+0x130>
mov    $0x3,%edi
mov    %r15,%rsi
call   10b0 <free_puzzle@plt>
mov    0x10(%rsp),%rbx
jmp    139c <solve_file+0x20c>
xchg   %ax,%ax
lea    0xce6(%rip),%rdi
call   1050 <puts@plt>
mov    $0x3,%edi
mov    %r13,%rsi
call   10b0 <free_puzzle@plt>
jmp    125c <solve_file+0xcc>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"Reading from file: %s\0A\00"
@.str.2 = [24 x i8] c" Solving puzzle #%u: \00"
@.str.3 = [9 x i8] c"Solved.\0A\00"
@.str.4 = [7 x i8] c" \00"
@.str.5 = [3 x i8] c"%x\00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [14 x i8] c"No solution.\0A\00"
@.str.8 = [17 x i8] c"Invalid length.\0A\00"
@.str.9 = [26 x i8] c"Failed to close file: %s\0A\00"
@.str.10 = [24 x i8] c"Couldn't open file: %s\0A\00"
define void @solve_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32**
%8 = alloca i32**
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %3
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %80
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 0, i32* %6
br label %15
15: ; preds = %71, %12
%16 = load i32*, i32** %3
%17 = call i32** @next_puzzle(i32 3, i32* %16)
store i32** %17, i32*** %7
%18 = load i32*, i32** %3
%19 = call i64 @feof(i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
br label %72
22: ; preds = %15
%23 = load i32, i32* %6
%24 = add i32 %23, 1
store i32 %24, i32* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32**, i32*** %7
%27 = icmp ne i32** %26, null
br i1 %27, label %28, label %69
28: ; preds = %22
%29 = load i32**, i32*** %7
%30 = call i32** @solve(i32 3, i32** %29)
store i32** %30, i32*** %8
%31 = icmp ne i32** %30, null
br i1 %31, label %32, label %64
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %34
34: ; preds = %58, %32
%35 = load i32, i32* %5
%36 = icmp slt i32 %35, 9
br i1 %36, label %37, label %61
37: ; preds = %34
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %39
39: ; preds = %53, %37
%40 = load i32, i32* %4
%41 = icmp slt i32 %40, 9
br i1 %41, label %42, label %56
42: ; preds = %39
%43 = load i32**, i32*** %8
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32*, i32** %43, i64 %45
%47 = load i32*, i32** %46
%48 = load i32, i32* %5
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %42
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
store i32 %55, i32* %4
br label %39
56: ; preds = %39
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %58
58: ; preds = %56
%59 = load i32, i32* %5
%60 = add nsw i32 %59, 1
store i32 %60, i32* %5
br label %34
61: ; preds = %34
%62 = load i32**, i32*** %8
%63 = call i32 @free_puzzle(i32 3, i32** %62)
br label %66
64: ; preds = %28
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %66
66: ; preds = %64, %61
%67 = load i32**, i32*** %7
%68 = call i32 @free_puzzle(i32 3, i32** %67)
br label %71
69: ; preds = %22
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
br label %71
71: ; preds = %69, %66
br label %15
72: ; preds = %21
%73 = load i32*, i32** %3
%74 = call i64 @fclose(i32* %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %72
%77 = load i8*, i8** %2
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* %77)
br label %79
79: ; preds = %76, %72
br label %83
80: ; preds = %1
%81 = load i8*, i8** %2
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), i8* %81)
br label %83
83: ; preds = %80, %79
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"Reading from file: %s\0A\00"
@.str.2 = [24 x i8] c" Solving puzzle #%u: \00"
@.str.4 = [7 x i8] c" \00"
@.str.5 = [3 x i8] c"%x\00"
@.str.9 = [26 x i8] c"Failed to close file: %s\0A\00"
@.str.10 = [24 x i8] c"Couldn't open file: %s\0A\00"
@str = [16 x i8] c"Invalid length.\00"
@str.11 = [13 x i8] c"No solution.\00"
@str.12 = [8 x i8] c"Solved.\00"
define void @solve_file(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %85, label %4
4: ; preds = %1
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%6 = tail call i32** @next_puzzle(i32 3, i32* %2)
%7 = tail call i64 @feof(i32* %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %82
9: ; preds = %4, %78
%10 = phi i32** [ %79, %78 ], [ %6, %4 ]
%11 = phi i32 [ %12, %78 ], [ 0, %4 ]
%12 = add i32 %11, 1
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = icmp eq i32** %10, null
br i1 %14, label %76, label %15
15: ; preds = %9
%16 = tail call i32** @solve(i32 3, i32** %10)
%17 = icmp eq i32** %16, null
br i1 %17, label %72, label %18
18: ; preds = %15
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.12, i64 0, i64 0))
%20 = getelementptr inbounds i32*, i32** %16, i64 1
%21 = getelementptr inbounds i32*, i32** %16, i64 2
%22 = getelementptr inbounds i32*, i32** %16, i64 3
%23 = getelementptr inbounds i32*, i32** %16, i64 4
%24 = getelementptr inbounds i32*, i32** %16, i64 5
%25 = getelementptr inbounds i32*, i32** %16, i64 6
%26 = getelementptr inbounds i32*, i32** %16, i64 7
%27 = getelementptr inbounds i32*, i32** %16, i64 8
br label %28
28: ; preds = %18, %28
%29 = phi i64 [ 0, %18 ], [ %68, %28 ]
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32*, i32** %16
%32 = getelementptr inbounds i32, i32* %31, i64 %29
%33 = load i32, i32* %32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %33)
%35 = load i32*, i32** %20
%36 = getelementptr inbounds i32, i32* %35, i64 %29
%37 = load i32, i32* %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %37)
%39 = load i32*, i32** %21
%40 = getelementptr inbounds i32, i32* %39, i64 %29
%41 = load i32, i32* %40
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = load i32*, i32** %22
%44 = getelementptr inbounds i32, i32* %43, i64 %29
%45 = load i32, i32* %44
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %45)
%47 = load i32*, i32** %23
%48 = getelementptr inbounds i32, i32* %47, i64 %29
%49 = load i32, i32* %48
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %49)
%51 = load i32*, i32** %24
%52 = getelementptr inbounds i32, i32* %51, i64 %29
%53 = load i32, i32* %52
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %53)
%55 = load i32*, i32** %25
%56 = getelementptr inbounds i32, i32* %55, i64 %29
%57 = load i32, i32* %56
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %57)
%59 = load i32*, i32** %26
%60 = getelementptr inbounds i32, i32* %59, i64 %29
%61 = load i32, i32* %60
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %61)
%63 = load i32*, i32** %27
%64 = getelementptr inbounds i32, i32* %63, i64 %29
%65 = load i32, i32* %64
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %65)
%67 = tail call i32 @putchar(i32 10)
%68 = add nuw nsw i64 %29, 1
%69 = icmp eq i64 %68, 9
br i1 %69, label %70, label %28
70: ; preds = %28
%71 = tail call i32 @free_puzzle(i32 3, i32** %16)
br label %74
72: ; preds = %15
%73 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.11, i64 0, i64 0))
br label %74
74: ; preds = %72, %70
%75 = tail call i32 @free_puzzle(i32 3, i32** %10)
br label %78
76: ; preds = %9
%77 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %78
78: ; preds = %74, %76
%79 = tail call i32** @next_puzzle(i32 3, i32* %2)
%80 = tail call i64 @feof(i32* %2)
%81 = icmp eq i64 %80, 0
br i1 %81, label %9, label %82
82: ; preds = %78, %4
%83 = tail call i64 @fclose(i32* %2)
%84 = icmp eq i64 %83, 0
br i1 %84, label %88, label %85
85: ; preds = %1, %82
%86 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), %82 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), %1 ]
%87 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %86, i8* %0)
br label %88
88: ; preds = %85, %82
ret void
}