// File: /workspace/github_c_makefile_star2_O1/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 0xc5ab
xorl %ecx, %ecx
movq (%rax), %rax
movq (%rax,%rcx,8), %r15
cmpq $0x0, 0x18(%r15)
je 0xc596
movq %rcx, 0x18(%rsp)
xorl %eax, %eax
callq 0x307c
movq %rax, %r12
movq 0x18(%r15), %rax
cmpq $0x0, 0x10(%rax)
je 0xc546
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 0xc43b
xorl %r15d, %r15d
movq (%rax), %rax
movq (%rax,%r15,8), %rbp
cmpq $0x0, 0x10(%rbp)
je 0xc423
cmpq $0x0, 0x18(%rbp)
je 0xc423
cmpq $0x0, 0x20(%rbp)
je 0xc423
movl $0x16, %edi
callq 0x8cb0
movq 0x10(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq 0x18(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq %r13, %rdi
movq %rax, %rsi
callq 0x30b6
movq 0x10(%rbp), %rax
movq %rax, 0x18(%rbp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x30b6
incq %r15
movq 0x8(%rbx), %rax
cmpq 0x10(%rax), %r15
jb 0xc3da
movq %r13, 0x8(%rbx)
cmpq $0x0, 0x10(%r13)
je 0xc52b
xorl %ebp, %ebp
movq 0x8(%rsp), %r15
movq (%r13), %rax
movq (%rax,%rbp,8), %rax
movq 0x10(%rax), %rsi
testq %rsi, %rsi
je 0xc46c
cmpl $0x0, 0x10(%rsi)
jne 0xc46c
movl %r14d, 0x10(%rsi)
movq 0x18(%rax), %rcx
testq %rcx, %rcx
je 0xc47f
cmpl %r14d, 0x14(%rcx)
jge 0xc47f
movl %r14d, 0x14(%rcx)
movq 0x20(%rax), %rcx
testq %rcx, %rcx
je 0xc492
cmpl %r14d, 0x14(%rcx)
jge 0xc492
movl %r14d, 0x14(%rcx)
movq 0x50(%rax), %rcx
testq %rcx, %rcx
je 0xc4c4
movq 0x10(%rcx), %rax
testq %rax, %rax
je 0xc4c4
movq (%rcx), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rdi
testq %rdi, %rdi
je 0xc4bc
cmpl %r14d, 0x14(%rdi)
jge 0xc4bc
movl %r14d, 0x14(%rdi)
incq %rdx
cmpq %rdx, %rax
jne 0xc4a9
testq %rsi, %rsi
je 0xc515
movq 0x10(%r12), %rax
testq %rax, %rax
setne %cl
je 0xc509
movq (%r12), %rcx
movl 0x4(%rsi), %edx
movq (%rcx), %rdi
cmpl 0x4(%rdi), %edx
je 0xc515
leaq -0x1(%rax), %r8
xorl %edi, %edi
cmpq %rdi, %r8
je 0xc500
movq 0x8(%rcx,%rdi,8), %r9
incq %rdi
cmpl 0x4(%r9), %edx
jne 0xc4eb
jmp 0xc503
movq %rax, %rdi
cmpq %rax, %rdi
setb %cl
testb %cl, %cl
jne 0xc515
movq %r12, %rdi
callq 0x30b6
incq %rbp
incl %r14d
movq 0x8(%rbx), %r13
cmpq %rbp, 0x10(%r13)
ja 0xc451
jmp 0xc530
movq 0x8(%rsp), %r15
movq 0x20(%rsp), %rcx
incq %rcx
movq 0x18(%r15), %rax
cmpq %rcx, 0x10(%rax)
ja 0xc3b6
movq %r12, %rdi
callq 0xc290
cmpq $0x0, 0x10(%r12)
leaq 0x2e30(%rip), %r14      # 0xf38b
je 0xc583
xorl %ebx, %ebx
movq (%r12), %rax
movq (%rax,%rbx,8), %rdi
callq 0x8d4d
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x21b0
incq %rbx
cmpq %rbx, 0x10(%r12)
ja 0xc55f
leaq 0x2f36(%rip), %rdi      # 0xf4c0
xorl %eax, %eax
callq 0x21b0
movq 0x18(%rsp), %rcx
incq %rcx
movq 0x10(%rsp), %rax
movq (%rax), %rax
cmpq %rcx, 0x10(%rax)
ja 0xc37c
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop