// File: /workspace/github_c_makefile_star2_O3/takoeight0821[P]hoc_nyan/src/regalloc.c
// Function: alloc_regs
void alloc_regs(IProgram* prog) {
  for (int i = 0; i < prog->ifuncs->length; i++) {
    IFunc* func = prog->ifuncs->ptr[i];
    if (func->blocks) {
      Vector* regs = collect_regs(func);
      scan(regs);

      for (int i = 0; i < regs->length; i++) {
        eprintf("%s ", show_ireg(regs->ptr[i]));
      }
      eprintf("\n");
    } 

    // TODO: Reserve stack area to spilled register

    // TODO: Convert accesses to spilled registers to load and stores
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, 0x10(%rsp)
movq (%rdi), %rax
cmpq $0x0, 0x10(%rax)
je 0xc417
xorl %edx, %edx
movq (%rax), %rcx
movq (%rcx,%rdx,8), %r15
cmpq $0x0, 0x18(%r15)
je 0xc40a
movq %rdx, 0x18(%rsp)
xorl %eax, %eax
callq 0x307c
movq %rax, %r12
movq 0x18(%r15), %rax
cmpq $0x0, 0x10(%rax)
je 0xc3b2
xorl %ecx, %ecx
xorl %r14d, %r14d
movq %r15, 0x8(%rsp)
movq (%rax), %rax
movq %rcx, 0x20(%rsp)
movq (%rax,%rcx,8), %rbx
xorl %eax, %eax
callq 0x307c
movq %rax, %r13
movq 0x8(%rbx), %rax
cmpq $0x0, 0x10(%rax)
je 0xc2b3
xorl %r15d, %r15d
movq (%rax), %rax
movq (%rax,%r15,8), %rbp
cmpq $0x0, 0x10(%rbp)
je 0xc29b
cmpq $0x0, 0x18(%rbp)
je 0xc29b
cmpq $0x0, 0x20(%rbp)
je 0xc29b
movl $0x16, %edi
callq 0x8c14
movups 0x10(%rbp), %xmm0
movups %xmm0, 0x10(%rax)
movq %r13, %rdi
movq %rax, %rsi
callq 0x30ae
movq 0x10(%rbp), %rax
movq %rax, 0x18(%rbp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x30ae
incq %r15
movq 0x8(%rbx), %rax
cmpq 0x10(%rax), %r15
jb 0xc25a
movq %r13, 0x8(%rbx)
cmpq $0x0, 0x10(%r13)
je 0xc397
xorl %ebp, %ebp
movq 0x8(%rsp), %r15
movq (%r13), %rax
movq (%rax,%rbp,8), %rax
movq 0x10(%rax), %rsi
testq %rsi, %rsi
je 0xc2e4
cmpl $0x0, 0x10(%rsi)
jne 0xc2e4
movl %r14d, 0x10(%rsi)
movq 0x18(%rax), %rcx
testq %rcx, %rcx
je 0xc2f7
cmpl %r14d, 0x14(%rcx)
jge 0xc2f7
movl %r14d, 0x14(%rcx)
movq 0x20(%rax), %rcx
testq %rcx, %rcx
je 0xc30a
cmpl %r14d, 0x14(%rcx)
jge 0xc30a
movl %r14d, 0x14(%rcx)
movq 0x50(%rax), %rcx
testq %rcx, %rcx
je 0xc33c
movq 0x10(%rcx), %rax
testq %rax, %rax
je 0xc33c
movq (%rcx), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rdi
testq %rdi, %rdi
je 0xc334
cmpl %r14d, 0x14(%rdi)
jge 0xc334
movl %r14d, 0x14(%rdi)
incq %rdx
cmpq %rdx, %rax
jne 0xc321
testq %rsi, %rsi
je 0xc385
movq 0x10(%r12), %rax
testq %rax, %rax
je 0xc379
movq (%r12), %rcx
movl 0x4(%rsi), %edx
movq (%rcx), %rdi
cmpl 0x4(%rdi), %edx
je 0xc385
leaq -0x1(%rax), %rdi
xorl %r8d, %r8d
cmpq %r8, %rdi
je 0xc379
movq 0x8(%rcx,%r8,8), %r9
incq %r8
cmpl 0x4(%r9), %edx
jne 0xc361
cmpq %rax, %r8
jb 0xc385
movq %r12, %rdi
callq 0x30ae
movq 0x8(%rbx), %r13
incq %rbp
incl %r14d
cmpq %rbp, 0x10(%r13)
ja 0xc2c9
jmp 0xc39c
movq 0x8(%rsp), %r15
movq 0x20(%rsp), %rcx
incq %rcx
movq 0x18(%r15), %rax
cmpq %rcx, 0x10(%rax)
ja 0xc236
movq %r12, %rdi
callq 0xc114
cmpq $0x0, 0x10(%r12)
leaq 0x2f9e(%rip), %r14      # 0xf365
je 0xc3ef
xorl %ebx, %ebx
movq (%r12), %rax
movq (%rax,%rbx,8), %rdi
callq 0x8cb1
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x21b0
incq %rbx
cmpq %rbx, 0x10(%r12)
ja 0xc3cb
leaq 0x30a6(%rip), %rdi      # 0xf49c
xorl %eax, %eax
callq 0x21b0
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rsp), %rdx
incq %rdx
cmpq %rdx, 0x10(%rax)
ja 0xc1fc
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop