// File: /workspace/github_cpp_makefile_star2_O2/nicklausw[P]snesasm/snesasm.cpp
// Function: solve_unsolveds()
int solve_unsolveds()
{
  unsigned int label_search = 0;
  int match_num = 0;
  
  for (unsigned int counter = 0; counter < unsolveds.size(); counter++) {
    match_num = 0;
    
    for (label_search = 0; label_search < labels.size(); label_search++) {
      if (labels[label_search].name == unsolveds[counter].name) {
        // a match!
        match_num++;
        if (unsolveds[counter].type == tDB) {
          if (labels[label_search].val > 0xFF) {
            // too big!
            cerr << "error: db requires 8-bit args\n";
            return fail;
          }
          
          org = unsolveds[counter].loc;
          write_byte(labels[label_search].val);
        } else if (unsolveds[counter].type == tDW) {
          if (labels[label_search].val > 0xFFFF) {
            // too big!
            cerr << "error: dw requires 16-bit args\n";
            return fail;
          }
          
          org = unsolveds[counter].loc;
          write_byte(labels[label_search].val >> 8);
          write_byte(labels[label_search].val & 0xFF);
        }
      }
    }
    
    if (!match_num) {
      cerr << "error: no such label " << unsolveds[counter].name << '\n';
      return fail;
    }
  }
  
  return success;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
xorl %eax, %eax
pushq $0x28
popq %r13
movl %eax, %r15d
movq 0x63e5(%rip), %rax      # 0xc2a8
subq 0x63d6(%rip), %rax      # 0xc2a0
cqto
pushq $0x38
popq %rcx
idivq %rcx
movq %rax, %rcx
cmpq %r15, %rax
jbe 0x602b
movq %rcx, (%rsp)
xorl %r12d, %r12d
imulq $0x38, %r15, %r14
xorl %ebp, %ebp
movl %r12d, %r12d
movq 0x6393(%rip), %rax      # 0xc288
movq 0x6384(%rip), %rdi      # 0xc280
subq %rdi, %rax
cqto
idivq %r13
cmpq %r12, %rax
jbe 0x5fc6
imulq $0x28, %r12, %rbx
addq %rbx, %rdi
movq 0x6385(%rip), %rsi      # 0xc2a0
addq %r14, %rsi
callq 0x6a58
testb %al, %al
je 0x5fbe
incl %ebp
movq 0x636c(%rip), %rax      # 0xc2a0
movl 0x28(%rax,%r14), %ecx
addq %r14, %rax
cmpl 0x6376(%rip), %ecx      # 0xc2b8
jne 0x5f6e
movq 0x6335(%rip), %rcx      # 0xc280
cmpq $0x100, 0x20(%rcx,%rbx) # imm = 0x100
jge 0x6004
addq %rbx, %rcx
addq $0x20, %rcx
movq 0x20(%rax), %rax
movq %rax, 0x623c(%rip)      # 0xc1a8
jmp 0x5fb6
cmpl 0x623c(%rip), %ecx      # 0xc1b0
jne 0x5fbe
movq 0x6303(%rip), %rcx      # 0xc280
cmpq $0x10000, 0x20(%rcx,%rbx) # imm = 0x10000
jge 0x6014
addq %rbx, %rcx
addq $0x20, %rcx
movq 0x20(%rax), %rax
movq %rax, 0x620a(%rip)      # 0xc1a8
movzbl 0x1(%rcx), %edi
callq 0x65dd
movq 0x62d2(%rip), %rax      # 0xc280
leaq (%rax,%rbx), %rcx
addq $0x20, %rcx
movzbl (%rcx), %edi
callq 0x65dd
incl %r12d
jmp 0x5eeb
leal 0x1(%r15), %eax
testl %ebp, %ebp
jne 0x5eb9
movq 0x6017(%rip), %rdi      # 0xbff0
leaq 0x283b(%rip), %rsi      # 0x881b
callq 0x2140
addq 0x62b4(%rip), %r14      # 0xc2a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x2120
pushq $0xa
popq %rsi
movq %rax, %rdi
callq 0x2170
jmp 0x6027
movq 0x5fe5(%rip), %rdi      # 0xbff0
leaq 0x27ca(%rip), %rsi      # 0x87dc
jmp 0x6022
movq 0x5fd5(%rip), %rdi      # 0xbff0
leaq 0x27d9(%rip), %rsi      # 0x87fb
callq 0x2140
movq (%rsp), %rcx
xorl %eax, %eax
cmpq %r15, %rcx
seta %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq