#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 */
struct sudoku {
  int dummy;
};

/* Variables and functions */
scalar_t__ all_fixed(struct sudoku *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ is_valid(struct sudoku *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
struct sudoku *sudoku_alloc();
int /*<<< orphan*/ sudoku_free(struct sudoku *);
int /*<<< orphan*/ sudoku_print(struct sudoku *);
int /*<<< orphan*/ sudoku_read(char *, struct sudoku *);
int /*<<< orphan*/ sudoku_solve(struct sudoku *);
int main(int argc, char *argv[]) {
  struct sudoku *s;
  int i;
  s = sudoku_alloc();
  for (i = 1; i < argc; i++) {
    sudoku_read(argv[i], s);
    if (all_fixed(s)) {
      if (is_valid(s))
        fprintf(stderr, "%s: sudoku already solved\n", argv[i]);
      else
        fprintf(stderr, "%s: sudoku has no free field\n", argv[i]);
      continue;
    }
    puts("sudoku read:");
    sudoku_print(s);
    if (!sudoku_solve(s)) {
      fprintf(stderr, "%s: sudoku could not be solved\n", argv[i]);
      continue;
    }
    puts("sudoku solved:");
    sudoku_print(s);
  }
  sudoku_free(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <sudoku_alloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12bb <main+0x12b>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <sudoku_read@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <all_fixed@plt>
cmp    $0x0,%rax
je     124b <main+0xbb>
mov    -0x18(%rbp),%rdi
call   1070 <is_valid@plt>
cmp    $0x0,%rax
je     1225 <main+0x95>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xde5(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1246 <main+0xb6>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdda(%rip),%rsi
call   1040 <fprintf@plt>
jmp    12ad <main+0x11d>
lea    0xde7(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1060 <sudoku_print@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <sudoku_solve@plt>
cmp    $0x0,%eax
jne    1298 <main+0x108>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdb8(%rip),%rsi
call   1040 <fprintf@plt>
jmp    12ad <main+0x11d>
lea    0xdc7(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1060 <sudoku_print@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b8 <main+0x28>
mov    -0x18(%rbp),%rdi
call   1050 <sudoku_free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
xor    %eax,%eax
call   1080 <sudoku_alloc@plt>
mov    %rax,%rbx
cmp    $0x2,%ebp
jl     1269 <main+0xd9>
mov    %ebp,%r13d
mov    $0x1,%ebp
mov    0x2e1e(%rip),%r15
lea    0xe37(%rip),%r12
jmp    11e5 <main+0x55>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rsi
call   1040 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     1269 <main+0xd9>
mov    (%r14,%rbp,8),%rdi
mov    %rbx,%rsi
call   1090 <sudoku_read@plt>
mov    %rbx,%rdi
call   10b0 <all_fixed@plt>
test   %rax,%rax
je     1220 <main+0x90>
mov    %rbx,%rdi
call   1070 <is_valid@plt>
mov    (%r15),%edi
mov    (%r14,%rbp,8),%rdx
test   %rax,%rax
jne    11d0 <main+0x40>
lea    0xe02(%rip),%rsi
jmp    11d3 <main+0x43>
nopl   0x0(%rax,%rax,1)
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1060 <sudoku_print@plt>
mov    %rbx,%rdi
call   10a0 <sudoku_solve@plt>
test   %eax,%eax
je     1256 <main+0xc6>
lea    0xe1f(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1060 <sudoku_print@plt>
jmp    11d8 <main+0x48>
mov    (%r15),%edi
mov    (%r14,%rbp,8),%rdx
lea    0xde2(%rip),%rsi
jmp    11d3 <main+0x43>
mov    %rbx,%rdi
call   1050 <sudoku_free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sudoku = type { i32 }
@stderr = global i32 0
@.str = [27 x i8] c"%s: sudoku already solved\0A\00"
@.str.1 = [30 x i8] c"%s: sudoku has no free field\0A\00"
@.str.2 = [13 x i8] c"sudoku read:\00"
@.str.3 = [32 x i8] c"%s: sudoku could not be solved\0A\00"
@.str.4 = [15 x i8] c"sudoku solved:\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sudoku*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call %struct.sudoku* (...) @sudoku_alloc()
store %struct.sudoku* %8, %struct.sudoku** %6
store i32 1, i32* %7
br label %9
9: ; preds = %64, %2
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %67
13: ; preds = %9
%14 = load i8**, i8*** %5
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = load %struct.sudoku*, %struct.sudoku** %6
%20 = call i32 @sudoku_read(i8* %18, %struct.sudoku* %19)
%21 = load %struct.sudoku*, %struct.sudoku** %6
%22 = call i64 @all_fixed(%struct.sudoku* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %45
24: ; preds = %13
%25 = load %struct.sudoku*, %struct.sudoku** %6
%26 = call i64 @is_valid(%struct.sudoku* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %34)
br label %44
36: ; preds = %24
%37 = load i32, i32* @stderr
%38 = load i8**, i8*** %5
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %36, %28
br label %64
45: ; preds = %13
%46 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%47 = load %struct.sudoku*, %struct.sudoku** %6
%48 = call i32 @sudoku_print(%struct.sudoku* %47)
%49 = load %struct.sudoku*, %struct.sudoku** %6
%50 = call i32 @sudoku_solve(%struct.sudoku* %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %60, label %52
52: ; preds = %45
%53 = load i32, i32* @stderr
%54 = load i8**, i8*** %5
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
%58 = load i8*, i8** %57
%59 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %58)
br label %64
60: ; preds = %45
%61 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%62 = load %struct.sudoku*, %struct.sudoku** %6
%63 = call i32 @sudoku_print(%struct.sudoku* %62)
br label %64
64: ; preds = %60, %52, %44
%65 = load i32, i32* %7
%66 = add nsw i32 %65, 1
store i32 %66, i32* %7
br label %9
67: ; preds = %9
%68 = load %struct.sudoku*, %struct.sudoku** %6
%69 = call i32 @sudoku_free(%struct.sudoku* %68)
ret i32 0
}

LLVM IR (-O2):
%struct.sudoku = type { i32 }
@stderr = global i32 0
@.str = [27 x i8] c"%s: sudoku already solved\0A\00"
@.str.1 = [30 x i8] c"%s: sudoku has no free field\0A\00"
@.str.2 = [13 x i8] c"sudoku read:\00"
@.str.3 = [32 x i8] c"%s: sudoku could not be solved\0A\00"
@.str.4 = [15 x i8] c"sudoku solved:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call %struct.sudoku* (...) @sudoku_alloc()
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %38
5: ; preds = %2
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %35
%8 = phi i64 [ 1, %5 ], [ %36, %35 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %8
%10 = load i8*, i8** %9
%11 = tail call i32 @sudoku_read(i8* %10, %struct.sudoku* %3)
%12 = tail call i64 @all_fixed(%struct.sudoku* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %7
%15 = tail call i64 @is_valid(%struct.sudoku* %3)
%16 = icmp eq i64 %15, 0
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %9
br i1 %16, label %21, label %19
19: ; preds = %14
%20 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %35
21: ; preds = %14
%22 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %35
23: ; preds = %7
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%25 = tail call i32 @sudoku_print(%struct.sudoku* %3)
%26 = tail call i32 @sudoku_solve(%struct.sudoku* %3)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %9
%31 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %30)
br label %35
32: ; preds = %23
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%34 = tail call i32 @sudoku_print(%struct.sudoku* %3)
br label %35
35: ; preds = %19, %21, %32, %28
%36 = add nuw nsw i64 %8, 1
%37 = icmp eq i64 %36, %6
br i1 %37, label %38, label %7
38: ; preds = %35, %2
%39 = tail call i32 @sudoku_free(%struct.sudoku* %3)
ret i32 0
}