#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 /*<<< orphan*/ fill(int *, int, int);
int findEmptyIndex(int *);
scalar_t__ isPossible(int *, int, int);
int /*<<< orphan*/ shuffle(int *, int);
int sudoku_generate(int *grid) {
  int index = findEmptyIndex(grid);
  int values[9], i, value;
  if (index == -1) {
    return 1;
  }
  fill(values, 9, 1);
  shuffle(values, 9);
  for (i = 0; i < 9; i++) {
    value = *(values + i);
    if (isPossible(grid, index, value)) {
      grid[index] = value;
      if (sudoku_generate(grid)) {
        return 1;
      }
      grid[index] = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<sudoku_generate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <findEmptyIndex@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    117e <sudoku_generate+0x2e>
movl   $0x1,-0x4(%rbp)
jmp    1229 <sudoku_generate+0xd9>
lea    -0x40(%rbp),%rdi
mov    $0x9,%esi
mov    $0x1,%edx
call   1040 <fill@plt>
lea    -0x40(%rbp),%rdi
mov    $0x9,%esi
call   1030 <shuffle@plt>
movl   $0x0,-0x44(%rbp)
cmpl   $0x9,-0x44(%rbp)
jge    1222 <sudoku_generate+0xd2>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x48(%rbp),%edx
call   1060 <isPossible@plt>
cmp    $0x0,%rax
je     120f <sudoku_generate+0xbf>
mov    -0x48(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rdi
call   1050 <sudoku_generate@plt>
cmp    $0x0,%eax
je     1200 <sudoku_generate+0xb0>
movl   $0x1,-0x4(%rbp)
jmp    1229 <sudoku_generate+0xd9>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    1214 <sudoku_generate+0xc4>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11a6 <sudoku_generate+0x56>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sudoku_generate>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%r12
call   1070 <findEmptyIndex@plt>
cmp    $0xffffffff,%eax
je     11d9 <sudoku_generate+0x89>
mov    %eax,%r14d
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x9,%esi
mov    $0x1,%edx
call   1040 <fill@plt>
mov    %rbp,%rdi
mov    $0x9,%esi
call   1030 <shuffle@plt>
movslq %r14d,%r15
xor    %ebx,%ebx
jmp    11aa <sudoku_generate+0x5a>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    $0x9,%rbx
je     11e0 <sudoku_generate+0x90>
mov    (%rsp,%rbx,4),%ebp
mov    %r12,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1060 <isPossible@plt>
test   %rax,%rax
je     11a0 <sudoku_generate+0x50>
mov    %ebp,(%r12,%r15,4)
mov    %r12,%rdi
call   1050 <sudoku_generate@plt>
test   %eax,%eax
jne    11d9 <sudoku_generate+0x89>
movl   $0x0,(%r12,%r15,4)
jmp    11a0 <sudoku_generate+0x50>
mov    $0x1,%eax
jmp    11e2 <sudoku_generate+0x92>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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