// File: /workspace/github_c_makefile_star2_O0/kobolt[P]curses-collection/sudoku/sudoku.c
// Function: find_only_solution
static int find_only_solution(int y, int x)
{
  int i, ny, nx, solution;
  char possible[9] = {1,1,1,1,1,1,1,1,1}; /* Tracks possible solutions. */

  if (sudoku[y][x] != 0)
    return -1; /* Already has a number, abort. */

  /* Find numbers on horizontal line, and remove them as solutions. */
  for (nx = 0; nx < 9; nx++) {
    if (sudoku[y][nx] == 0)
      continue;
    possible[sudoku[y][nx] - 1] = 0;
  }

  /* Find numbers on vertical line. */
  for (ny = 0; ny < 9; ny++) {
    if (sudoku[ny][x] == 0)
      continue;
    possible[sudoku[ny][x] - 1] = 0;
  }

  /* Find numbers in same 3x3 box. */
  for (ny = (y / 3) * 3; ny < ((y / 3) + 1) * 3; ny++) {
    for (nx = (x / 3) * 3; nx < ((x / 3) + 1) * 3; nx++) {
      if (sudoku[ny][nx] == 0)
        continue;
      possible[sudoku[ny][nx] - 1] = 0;
    }
  }

  solution = -1; /* Initial "unset" value. */
  for (i = 0; i < 9; i++) {
    if (possible[i]) {
      if (solution == -1)
        solution = i + 1;
      else 
        solution = 0; /* Found more than one solution. */
    }
  }

  if (solution == -1) {
    /* No solutions at all for cell, possibly walked down the wrong road. */
    return -2;
  }

  return solution; /* Will be 0 if multiple solutions are possible. */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq 0x103b(%rip), %rax      # 0x301c
movq %rax, -0x25(%rbp)
movb 0x1039(%rip), %al       # 0x3024
movb %al, -0x1d(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x30e7(%rip), %rax      # 0x50e0
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movslq -0xc(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x2016
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x21e5
movl $0x0, -0x18(%rbp)
cmpl $0x9, -0x18(%rbp)
jge 0x206f
movslq -0x8(%rbp), %rcx
leaq 0x30b2(%rip), %rax      # 0x50e0
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x2041
jmp 0x2064
movslq -0x8(%rbp), %rcx
leaq 0x3094(%rip), %rax      # 0x50e0
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x25(%rbp,%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x201d
movl $0x0, -0x14(%rbp)
cmpl $0x9, -0x14(%rbp)
jge 0x20c8
movslq -0x14(%rbp), %rcx
leaq 0x3059(%rip), %rax      # 0x50e0
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movslq -0xc(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x209a
jmp 0x20bd
movslq -0x14(%rbp), %rcx
leaq 0x303b(%rip), %rax      # 0x50e0
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x25(%rbp,%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2076
movl -0x8(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
imull $0x3, %eax, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x8(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x2c(%rbp), %eax
addl $0x1, %ecx
imull $0x3, %ecx, %ecx
cmpl %ecx, %eax
jge 0x218a
movl -0xc(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
imull $0x3, %eax, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0xc(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x30(%rbp), %eax
addl $0x1, %ecx
imull $0x3, %ecx, %ecx
cmpl %ecx, %eax
jge 0x217a
movslq -0x14(%rbp), %rcx
leaq 0x2fa7(%rip), %rax      # 0x50e0
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x214c
jmp 0x216f
movslq -0x14(%rbp), %rcx
leaq 0x2f89(%rip), %rax      # 0x50e0
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x25(%rbp,%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x210e
jmp 0x217c
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x20d9
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x10(%rbp)
cmpl $0x9, -0x10(%rbp)
jge 0x21d0
movslq -0x10(%rbp), %rax
cmpb $0x0, -0x25(%rbp,%rax)
je 0x21c3
cmpl $-0x1, -0x1c(%rbp)
jne 0x21ba
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x21c1
movl $0x0, -0x1c(%rbp)
jmp 0x21c3
jmp 0x21c5
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x2198
cmpl $-0x1, -0x1c(%rbp)
jne 0x21df
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x21e5
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw (%rax,%rax)