#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 puzzle {
  int dummy;
};

/* Variables and functions */
int getNextFree(struct puzzle *);
int puzzle_is_complete(struct puzzle *);
scalar_t__ puzzle_is_valid(struct puzzle *);
scalar_t__ puzzle_move_is_valid(struct puzzle *, int, int);
int /*<<< orphan*/ puzzle_set(struct puzzle *, int, int, int);
int solve(struct puzzle *p, int x, int y) {
  int nextFree;
  if (x == -1 || y == -1) {
    if (puzzle_is_valid(p) == 0) {
      return (0);
    }
  } else {
    if (puzzle_move_is_valid(p, x, y) == 0) {
      return (0);
    }
  }
  if (puzzle_is_complete(p) == 1) {
    return (1);
  }
  nextFree = getNextFree(p);
  if (nextFree < 0) {
    return (0);
  }
  for (int i = 1; i <= 9; i++) {
    puzzle_set(p, nextFree / 9, nextFree % 9, i);
    if (solve(p, nextFree / 9, nextFree % 9) == 1) {
      return (1);
    }
    puzzle_set(p, nextFree / 9, nextFree % 9, 0);
  }
  return (0);
}


x86 assembly (clang, -O0):
<solve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     1186 <solve+0x26>
cmpl   $0xffffffff,-0x18(%rbp)
jne    11aa <solve+0x4a>
mov    -0x10(%rbp),%rdi
call   1080 <puzzle_is_valid@plt>
cmp    $0x0,%rax
jne    11a5 <solve+0x45>
movl   $0x0,-0x4(%rbp)
jmp    12b7 <solve+0x157>
jmp    11d4 <solve+0x74>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <puzzle_move_is_valid@plt>
cmp    $0x0,%rax
jne    11cf <solve+0x6f>
movl   $0x0,-0x4(%rbp)
jmp    12b7 <solve+0x157>
jmp    11d4 <solve+0x74>
mov    -0x10(%rbp),%rdi
call   1040 <puzzle_is_complete@plt>
cmp    $0x1,%eax
jne    11f2 <solve+0x92>
movl   $0x1,-0x4(%rbp)
jmp    12b7 <solve+0x157>
mov    -0x10(%rbp),%rdi
call   1070 <getNextFree@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1214 <solve+0xb4>
movl   $0x0,-0x4(%rbp)
jmp    12b7 <solve+0x157>
movl   $0x1,-0x20(%rbp)
cmpl   $0x9,-0x20(%rbp)
jg     12b0 <solve+0x150>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x1c(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%ecx
call   1060 <puzzle_set@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x1c(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
call   1030 <solve@plt>
cmp    $0x1,%eax
jne    127f <solve+0x11f>
movl   $0x1,-0x4(%rbp)
jmp    12b7 <solve+0x157>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x1c(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
xor    %ecx,%ecx
call   1060 <puzzle_set@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    121b <solve+0xbb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
cmp    $0xffffffff,%esi
je     1187 <solve+0x27>
cmp    $0xffffffff,%edx
je     1187 <solve+0x27>
mov    %r14,%rdi
call   1050 <puzzle_move_is_valid@plt>
test   %rax,%rax
jne    1198 <solve+0x38>
jmp    1259 <solve+0xf9>
mov    %r14,%rdi
call   1080 <puzzle_is_valid@plt>
test   %rax,%rax
je     1259 <solve+0xf9>
mov    %r14,%rdi
call   1040 <puzzle_is_complete@plt>
mov    $0x1,%r15d
cmp    $0x1,%eax
je     125c <solve+0xfc>
mov    %r14,%rdi
call   1070 <getNextFree@plt>
test   %eax,%eax
js     1259 <solve+0xf9>
mov    %eax,%ebp
mov    %eax,%eax
imul   $0x38e38e39,%rax,%r12
shr    $0x21,%r12
lea    (%r12,%r12,8),%eax
sub    %eax,%ebp
mov    $0x1,%r15d
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
mov    $0x1,%ecx
call   1060 <puzzle_set@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
call   1030 <solve@plt>
cmp    $0x1,%eax
je     125c <solve+0xfc>
mov    $0x2,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ecx,%ebx
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1060 <puzzle_set@plt>
cmp    $0xa,%ebx
je     124a <solve+0xea>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1060 <puzzle_set@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
call   1030 <solve@plt>
lea    0x1(%rbx),%ecx
cmp    $0x1,%eax
jne    1210 <solve+0xb0>
add    $0xffffffff,%ebx
xor    %r15d,%r15d
cmp    $0x9,%ebx
setb   %r15b
jmp    125c <solve+0xfc>
xor    %r15d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.puzzle = type { i32 }
define i32 @solve(%struct.puzzle* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.puzzle*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.puzzle* %0, %struct.puzzle** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %12, %3
%16 = load %struct.puzzle*, %struct.puzzle** %5
%17 = call i64 @puzzle_is_valid(%struct.puzzle* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 0, i32* %4
br label %71
20: ; preds = %15
br label %29
21: ; preds = %12
%22 = load %struct.puzzle*, %struct.puzzle** %5
%23 = load i32, i32* %6
%24 = load i32, i32* %7
%25 = call i64 @puzzle_move_is_valid(%struct.puzzle* %22, i32 %23, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 0, i32* %4
br label %71
28: ; preds = %21
br label %29
29: ; preds = %28, %20
%30 = load %struct.puzzle*, %struct.puzzle** %5
%31 = call i32 @puzzle_is_complete(%struct.puzzle* %30)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 1, i32* %4
br label %71
34: ; preds = %29
%35 = load %struct.puzzle*, %struct.puzzle** %5
%36 = call i32 @getNextFree(%struct.puzzle* %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %34
store i32 0, i32* %4
br label %71
40: ; preds = %34
store i32 1, i32* %9
br label %41
41: ; preds = %67, %40
%42 = load i32, i32* %9
%43 = icmp sle i32 %42, 9
br i1 %43, label %44, label %70
44: ; preds = %41
%45 = load %struct.puzzle*, %struct.puzzle** %5
%46 = load i32, i32* %8
%47 = sdiv i32 %46, 9
%48 = load i32, i32* %8
%49 = srem i32 %48, 9
%50 = load i32, i32* %9
%51 = call i32 @puzzle_set(%struct.puzzle* %45, i32 %47, i32 %49, i32 %50)
%52 = load %struct.puzzle*, %struct.puzzle** %5
%53 = load i32, i32* %8
%54 = sdiv i32 %53, 9
%55 = load i32, i32* %8
%56 = srem i32 %55, 9
%57 = call i32 @solve(%struct.puzzle* %52, i32 %54, i32 %56)
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %60
59: ; preds = %44
store i32 1, i32* %4
br label %71
60: ; preds = %44
%61 = load %struct.puzzle*, %struct.puzzle** %5
%62 = load i32, i32* %8
%63 = sdiv i32 %62, 9
%64 = load i32, i32* %8
%65 = srem i32 %64, 9
%66 = call i32 @puzzle_set(%struct.puzzle* %61, i32 %63, i32 %65, i32 0)
br label %67
67: ; preds = %60
%68 = load i32, i32* %9
%69 = add nsw i32 %68, 1
store i32 %69, i32* %9
br label %41
70: ; preds = %41
store i32 0, i32* %4
br label %71
71: ; preds = %70, %59, %39, %33, %27, %19
%72 = load i32, i32* %4
ret i32 %72
}

LLVM IR (-O2):
%struct.puzzle = type { i32 }
define i32 @solve(%struct.puzzle* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, -1
%5 = icmp eq i32 %2, -1
%6 = or i1 %4, %5
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i64 @puzzle_is_valid(%struct.puzzle* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %37, label %13
10: ; preds = %3
%11 = tail call i64 @puzzle_move_is_valid(%struct.puzzle* %0, i32 %1, i32 %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %37, label %13
13: ; preds = %10, %7
%14 = tail call i32 @puzzle_is_complete(%struct.puzzle* %0)
%15 = icmp eq i32 %14, 1
br i1 %15, label %37, label %16
16: ; preds = %13
%17 = tail call i32 @getNextFree(%struct.puzzle* %0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %37, label %19
19: ; preds = %16
%20 = udiv i32 %17, 9
%21 = urem i32 %17, 9
%22 = tail call i32 @puzzle_set(%struct.puzzle* %0, i32 %20, i32 %21, i32 1)
%23 = tail call i32 @solve(%struct.puzzle* %0, i32 %20, i32 %21)
%24 = icmp eq i32 %23, 1
br i1 %24, label %37, label %29
25: ; preds = %29
%26 = tail call i32 @puzzle_set(%struct.puzzle* %0, i32 %20, i32 %21, i32 %32)
%27 = tail call i32 @solve(%struct.puzzle* %0, i32 %20, i32 %21)
%28 = icmp eq i32 %27, 1
br i1 %28, label %34, label %29
29: ; preds = %19, %25
%30 = phi i32 [ %32, %25 ], [ 1, %19 ]
%31 = tail call i32 @puzzle_set(%struct.puzzle* %0, i32 %20, i32 %21, i32 0)
%32 = add nuw nsw i32 %30, 1
%33 = icmp eq i32 %32, 10
br i1 %33, label %34, label %25
34: ; preds = %25, %29
%35 = icmp ult i32 %30, 9
%36 = zext i1 %35 to i32
br label %37
37: ; preds = %19, %34, %16, %13, %10, %7
%38 = phi i32 [ 0, %7 ], [ 0, %10 ], [ 1, %13 ], [ 0, %16 ], [ 1, %19 ], [ %36, %34 ]
ret i32 %38
}