#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 */
int check_all(int **, int, int, int);
int free_grid_and_return(int **, int);
int /*<<< orphan*/ free_grid_mem(int **);
int **make_backup(int **);
int /*<<< orphan*/ restore_grid(int **, int **);
int rec_solver(int **grid, int x, int y, int c) {
  int i;
  int stop;
  int **grid_backup;
  c++;
  grid_backup = make_backup(grid);
  if (x > 8)
    return (free_grid_and_return(grid_backup, 1));
  if (grid[x][y] == 0) {
    i = 0;
    stop = 0;
    while (++i < 10 && !stop) {
      restore_grid(grid, grid_backup);
      stop = check_all(grid, x, y, i);
      grid[x][y] = i;
      stop = stop && rec_solver(grid, c / 9, c % 9, c);
    }
    return (free_grid_and_return(grid_backup, stop));
  }
  free_grid_mem(grid_backup);
  return (rec_solver(grid, c / 9, c % 9, c));
}


x86 assembly (clang, -O0):
<rec_solver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <make_backup@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x8,-0x14(%rbp)
jle    11ab <rec_solver+0x4b>
mov    -0x30(%rbp),%rdi
mov    $0x1,%esi
call   1050 <free_grid_and_return@plt>
mov    %eax,-0x4(%rbp)
jmp    12ce <rec_solver+0x16e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    129e <rec_solver+0x13e>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x20(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x31(%rbp)
jge    11f6 <rec_solver+0x96>
cmpl   $0x0,-0x24(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1206 <rec_solver+0xa6>
jmp    128a <rec_solver+0x12a>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1080 <restore_grid@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1040 <check_all@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
xor    %eax,%eax
cmpl   $0x0,-0x24(%rbp)
mov    %al,-0x32(%rbp)
je     127a <rec_solver+0x11a>
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    -0x1c(%rbp),%ecx
call   1060 <rec_solver@plt>
cmp    $0x0,%eax
setne  %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
jmp    11d3 <rec_solver+0x73>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <free_grid_and_return@plt>
mov    %eax,-0x4(%rbp)
jmp    12ce <rec_solver+0x16e>
mov    -0x30(%rbp),%rdi
call   1030 <free_grid_mem@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
mov    -0x1c(%rbp),%ecx
call   1060 <rec_solver@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rec_solver>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r12
call   1070 <make_backup@plt>
cmp    $0x8,%ebx
jg     11f7 <rec_solver+0x97>
cmp    $0x51,%r15d
mov    $0x50,%ecx
cmovge %r15d,%ecx
neg    %ecx
mov    %rcx,0x8(%rsp)
add    $0x1,%r15d
nopw   0x0(%rax,%rax,1)
movslq %ebx,%rdx
mov    (%r12,%rdx,8),%rcx
movslq %ebp,%r13
cmpl   $0x0,(%rcx,%r13,4)
movslq %r15d,%r14
je     1204 <rec_solver+0xa4>
mov    %rax,%rdi
call   1030 <free_grid_mem@plt>
imul   $0x38e38e39,%r14,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x21,%rbx
add    %eax,%ebx
lea    (%rbx,%rbx,8),%eax
mov    %r14d,%ebp
sub    %eax,%ebp
mov    %r12,%rdi
call   1070 <make_backup@plt>
mov    %r14d,%r15d
add    $0x1,%r15d
mov    0x8(%rsp),%rcx
add    %r14d,%ecx
add    $0x1,%ecx
cmp    $0x2,%ecx
jne    11a0 <rec_solver+0x40>
mov    %rax,%rdi
mov    $0x1,%esi
jmp    12a9 <rec_solver+0x149>
imul   $0x38e38e39,%r14,%rsi
mov    %rsi,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rsi
add    %ecx,%esi
mov    %rsi,0x8(%rsp)
lea    (%rsi,%rsi,8),%ecx
sub    %ecx,%r14d
mov    $0x1,%ebx
mov    %r12,%rbp
mov    %rdx,%r12
mov    %rax,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    %rax,%rsi
call   1080 <restore_grid@plt>
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
mov    %ebx,%ecx
call   1040 <check_all@plt>
mov    0x0(%rbp,%r12,8),%rcx
mov    %ebx,(%rcx,%r13,4)
test   %eax,%eax
je     1290 <rec_solver+0x130>
mov    %rbp,%rdi
mov    0x8(%rsp),%rsi
mov    %r14d,%edx
mov    %r15d,%ecx
call   1060 <rec_solver@plt>
test   %eax,%eax
setne  %cl
jmp    1292 <rec_solver+0x132>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %ecx,%ecx
cmp    $0x8,%ebx
mov    0x10(%rsp),%rax
ja     12a3 <rec_solver+0x143>
add    $0x1,%ebx
test   %cl,%cl
je     1240 <rec_solver+0xe0>
movzbl %cl,%esi
mov    %rax,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <free_grid_and_return@plt>

LLVM IR (-O0):
define i32 @rec_solver(i32** %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32**
store i32** %0, i32*** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = load i32, i32* %9
%14 = add nsw i32 %13, 1
store i32 %14, i32* %9
%15 = load i32**, i32*** %6
%16 = call i32** @make_backup(i32** %15)
store i32** %16, i32*** %12
%17 = load i32, i32* %7
%18 = icmp sgt i32 %17, 8
br i1 %18, label %19, label %22
19: ; preds = %4
%20 = load i32**, i32*** %12
%21 = call i32 @free_grid_and_return(i32** %20, i32 1)
store i32 %21, i32* %5
br label %90
22: ; preds = %4
%23 = load i32**, i32*** %6
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32*, i32** %23, i64 %25
%27 = load i32*, i32** %26
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %80
33: ; preds = %22
store i32 0, i32* %10
store i32 0, i32* %11
br label %34
34: ; preds = %73, %33
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
%37 = icmp slt i32 %36, 10
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* %11
%40 = icmp ne i32 %39, 0
%41 = xor i1 %40, true
br label %42
42: ; preds = %38, %34
%43 = phi i1 [ false, %34 ], [ %41, %38 ]
br i1 %43, label %44, label %76
44: ; preds = %42
%45 = load i32**, i32*** %6
%46 = load i32**, i32*** %12
%47 = call i32 @restore_grid(i32** %45, i32** %46)
%48 = load i32**, i32*** %6
%49 = load i32, i32* %7
%50 = load i32, i32* %8
%51 = load i32, i32* %10
%52 = call i32 @check_all(i32** %48, i32 %49, i32 %50, i32 %51)
store i32 %52, i32* %11
%53 = load i32, i32* %10
%54 = load i32**, i32*** %6
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32*, i32** %54, i64 %56
%58 = load i32*, i32** %57
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %58, i64 %60
store i32 %53, i32* %61
%62 = load i32, i32* %11
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %73
64: ; preds = %44
%65 = load i32**, i32*** %6
%66 = load i32, i32* %9
%67 = sdiv i32 %66, 9
%68 = load i32, i32* %9
%69 = srem i32 %68, 9
%70 = load i32, i32* %9
%71 = call i32 @rec_solver(i32** %65, i32 %67, i32 %69, i32 %70)
%72 = icmp ne i32 %71, 0
br label %73
73: ; preds = %64, %44
%74 = phi i1 [ false, %44 ], [ %72, %64 ]
%75 = zext i1 %74 to i32
store i32 %75, i32* %11
br label %34
76: ; preds = %42
%77 = load i32**, i32*** %12
%78 = load i32, i32* %11
%79 = call i32 @free_grid_and_return(i32** %77, i32 %78)
store i32 %79, i32* %5
br label %90
80: ; preds = %22
%81 = load i32**, i32*** %12
%82 = call i32 @free_grid_mem(i32** %81)
%83 = load i32**, i32*** %6
%84 = load i32, i32* %9
%85 = sdiv i32 %84, 9
%86 = load i32, i32* %9
%87 = srem i32 %86, 9
%88 = load i32, i32* %9
%89 = call i32 @rec_solver(i32** %83, i32 %85, i32 %87, i32 %88)
store i32 %89, i32* %5
br label %90
90: ; preds = %80, %76, %19
%91 = load i32, i32* %5
ret i32 %91
}

LLVM IR (-O2):
define i32 @rec_solver(i32** %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32** @make_backup(i32** %0)
%6 = icmp sgt i32 %1, 8
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = call i32 @llvm.smax.i32(i32 %3, i32 80)
br label %12
9: ; preds = %48, %4
%10 = phi i32** [ %5, %4 ], [ %52, %48 ]
%11 = tail call i32 @free_grid_and_return(i32** %10, i32 1)
br label %54
12: ; preds = %7, %48
%13 = phi i32** [ %52, %48 ], [ %5, %7 ]
%14 = phi i32 [ %17, %48 ], [ %3, %7 ]
%15 = phi i32 [ %51, %48 ], [ %2, %7 ]
%16 = phi i32 [ %50, %48 ], [ %1, %7 ]
%17 = add i32 %14, 1
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds i32*, i32** %0, i64 %18
%20 = load i32*, i32** %19
%21 = sext i32 %15 to i64
%22 = getelementptr inbounds i32, i32* %20, i64 %21
%23 = load i32, i32* %22
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %48
25: ; preds = %12
%26 = getelementptr inbounds i32*, i32** %0, i64 %18
%27 = sdiv i32 %17, 9
%28 = srem i32 %17, 9
br label %29
29: ; preds = %25, %39
%30 = phi i32 [ 1, %25 ], [ %41, %39 ]
%31 = tail call i32 @restore_grid(i32** %0, i32** %13)
%32 = tail call i32 @check_all(i32** %0, i32 %16, i32 %15, i32 %30)
%33 = load i32*, i32** %26
%34 = getelementptr inbounds i32, i32* %33, i64 %21
store i32 %30, i32* %34
%35 = icmp eq i32 %32, 0
br i1 %35, label %39, label %36
36: ; preds = %29
%37 = tail call i32 @rec_solver(i32** %0, i32 %27, i32 %28, i32 %17)
%38 = icmp ne i32 %37, 0
br label %39
39: ; preds = %36, %29
%40 = phi i1 [ false, %29 ], [ %38, %36 ]
%41 = add nuw nsw i32 %30, 1
%42 = icmp ult i32 %30, 9
%43 = xor i1 %40, true
%44 = select i1 %42, i1 %43, i1 false
br i1 %44, label %29, label %45
45: ; preds = %39
%46 = zext i1 %40 to i32
%47 = tail call i32 @free_grid_and_return(i32** %13, i32 %46)
br label %54
48: ; preds = %12
%49 = tail call i32 @free_grid_mem(i32** %13)
%50 = sdiv i32 %17, 9
%51 = srem i32 %17, 9
%52 = tail call i32** @make_backup(i32** %0)
%53 = icmp eq i32 %14, %8
br i1 %53, label %9, label %12
54: ; preds = %45, %9
%55 = phi i32 [ %11, %9 ], [ %47, %45 ]
ret i32 %55
}