#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__ FIND_UNASSIGNED(int **, int *, int *);
int IS_SAFE(int **, int, int, int);
int SOLVE_SUDOKU(int grid[9][9]) {
  int row, col, num;
  if (FIND_UNASSIGNED(grid, &row, &col) == 0)
    return 1;
  for (num = 1; num <= 9; num++) {
    if (IS_SAFE(grid, row, col, num) == 1) {
      grid[row][col] = num;
      if (SOLVE_SUDOKU(grid) == 1)
        return 1;
      grid[row][col] = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<SOLVE_SUDOKU>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <FIND_UNASSIGNED@plt>
cmp    $0x0,%rax
jne    1163 <SOLVE_SUDOKU+0x33>
movl   $0x1,-0x4(%rbp)
jmp    11fa <SOLVE_SUDOKU+0xca>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x9,-0x1c(%rbp)
jg     11f3 <SOLVE_SUDOKU+0xc3>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1050 <IS_SAFE@plt>
cmp    $0x1,%eax
jne    11e0 <SOLVE_SUDOKU+0xb0>
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x24,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rdi
call   1040 <SOLVE_SUDOKU@plt>
cmp    $0x1,%eax
jne    11c6 <SOLVE_SUDOKU+0x96>
movl   $0x1,-0x4(%rbp)
jmp    11fa <SOLVE_SUDOKU+0xca>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x24,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    11e5 <SOLVE_SUDOKU+0xb5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116a <SOLVE_SUDOKU+0x3a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SOLVE_SUDOKU>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1030 <FIND_UNASSIGNED@plt>
test   %rax,%rax
je     11a9 <SOLVE_SUDOKU+0x79>
mov    $0x1,%ebp
jmp    1158 <SOLVE_SUDOKU+0x28>
nop
add    $0x1,%ebp
cmp    $0xa,%ebp
je     11b0 <SOLVE_SUDOKU+0x80>
mov    0x4(%rsp),%esi
mov    (%rsp),%edx
mov    %rbx,%rdi
mov    %ebp,%ecx
call   1050 <IS_SAFE@plt>
cmp    $0x1,%eax
jne    1150 <SOLVE_SUDOKU+0x20>
movslq 0x4(%rsp),%rax
movslq (%rsp),%rcx
lea    (%rax,%rax,8),%rax
lea    (%rbx,%rax,4),%rax
mov    %ebp,(%rax,%rcx,4)
mov    %rbx,%rdi
call   1040 <SOLVE_SUDOKU@plt>
cmp    $0x1,%eax
je     11a9 <SOLVE_SUDOKU+0x79>
movslq 0x4(%rsp),%rax
movslq (%rsp),%rcx
lea    (%rax,%rax,8),%rax
lea    (%rbx,%rax,4),%rax
movl   $0x0,(%rax,%rcx,4)
jmp    1150 <SOLVE_SUDOKU+0x20>
mov    $0x1,%eax
jmp    11b2 <SOLVE_SUDOKU+0x82>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @SOLVE_SUDOKU([9 x i32]* %0) {
%2 = alloca i32
%3 = alloca [9 x i32]*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store [9 x i32]* %0, [9 x i32]** %3
%7 = load [9 x i32]*, [9 x i32]** %3
%8 = bitcast [9 x i32]* %7 to i32**
%9 = call i64 @FIND_UNASSIGNED(i32** %8, i32* %4, i32* %5)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 1, i32* %2
br label %50
12: ; preds = %1
store i32 1, i32* %6
br label %13
13: ; preds = %46, %12
%14 = load i32, i32* %6
%15 = icmp sle i32 %14, 9
br i1 %15, label %16, label %49
16: ; preds = %13
%17 = load [9 x i32]*, [9 x i32]** %3
%18 = bitcast [9 x i32]* %17 to i32**
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = call i32 @IS_SAFE(i32** %18, i32 %19, i32 %20, i32 %21)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %45
24: ; preds = %16
%25 = load i32, i32* %6
%26 = load [9 x i32]*, [9 x i32]** %3
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [9 x i32], [9 x i32]* %26, i64 %28
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [9 x i32], [9 x i32]* %29, i64 0, i64 %31
store i32 %25, i32* %32
%33 = load [9 x i32]*, [9 x i32]** %3
%34 = call i32 @SOLVE_SUDOKU([9 x i32]* %33)
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %37
36: ; preds = %24
store i32 1, i32* %2
br label %50
37: ; preds = %24
%38 = load [9 x i32]*, [9 x i32]** %3
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [9 x i32], [9 x i32]* %38, i64 %40
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [9 x i32], [9 x i32]* %41, i64 0, i64 %43
store i32 0, i32* %44
br label %45
45: ; preds = %37, %16
br label %46
46: ; preds = %45
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %13
49: ; preds = %13
store i32 0, i32* %2
br label %50
50: ; preds = %49, %36, %11
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
define i32 @SOLVE_SUDOKU([9 x i32]* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = bitcast [9 x i32]* %0 to i32**
%7 = call i64 @FIND_UNASSIGNED(i32** %6, i32* %2, i32* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %32, label %9
9: ; preds = %1, %29
%10 = phi i32 [ %30, %29 ], [ 1, %1 ]
%11 = load i32, i32* %2
%12 = load i32, i32* %3
%13 = call i32 @IS_SAFE(i32** %6, i32 %11, i32 %12, i32 %10)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %29
15: ; preds = %9
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %17, i64 %19
store i32 %10, i32* %20
%21 = call i32 @SOLVE_SUDOKU([9 x i32]* %0)
%22 = icmp eq i32 %21, 1
br i1 %22, label %32, label %23
23: ; preds = %15
%24 = load i32, i32* %2
%25 = sext i32 %24 to i64
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %25, i64 %27
store i32 0, i32* %28
br label %29
29: ; preds = %9, %23
%30 = add nuw nsw i32 %10, 1
%31 = icmp eq i32 %30, 10
br i1 %31, label %32, label %9
32: ; preds = %29, %15, %1
%33 = phi i32 [ 1, %1 ], [ 0, %29 ], [ 1, %15 ]
ret i32 %33
}