// File: /workspace/github_c_makefile_star2_O1/Mithreindeir[P]ewcc/src/debug.c
// Function: bb_debug
void bb_debug(struct bb *bb)
{
	if (!bb) return;
	if (bb->visited) return;
	bb->visited = 1;
	printf("Basic Block:\n");
	printf("------------------------------------\n");
	struct ir_stmt *stmt = bb->blk;
	int ln = 0;
	while (stmt && ln < bb->len) {
		printf("%2d: ", ++ln);
		ir_stmt_debug(stmt);
		printf("\n");
		stmt = stmt->next;
	}
	printf("Local Register Allocation:\n");
	color_graph(bb->graph, bb->nvert, 4);
	for (int i = 0; i < bb->nvert; i++)
		printf("Temp R%d = Machine Reg %d\n", bb->graph[i]->ocolor, bb->graph[i]->color);
	printf("------------------------------------\n");
	stmt = bb->blk;
	ln = 0;
	while (stmt && ln < bb->len) {
		if (stmt->result && stmt->result->type == oper_reg) {
			for (int i = 0; i < bb->nvert; i++) {
				if (bb->graph[i]->ocolor == stmt->result->val.virt_reg) {
					stmt->result->val.virt_reg = bb->graph[i]->color;
				}
			}
		}
		if (stmt->arg1 && stmt->arg1->type == oper_reg) {
			for (int i = 0; i < bb->nvert; i++) {
				if (bb->graph[i]->ocolor == stmt->arg1->val.virt_reg) {
					stmt->arg1->val.virt_reg = bb->graph[i]->color;
				}
			}
		}
		if (stmt->arg2 && stmt->arg2->type == oper_reg) {
			for (int i = 0; i < bb->nvert; i++) {
				if (bb->graph[i]->ocolor == stmt->arg2->val.virt_reg) {
					stmt->arg2->val.virt_reg = bb->graph[i]->color;
				}
			}
		}
		stmt = stmt->next;
		ln++;
	}
	printf("\n");
	for (int i = 0; i < bb->nsucc; i++) {
		bb_debug(bb->succ[i]);
	}
}

// Assembly:
testq %rdi, %rdi
je 0x2439
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
cmpl $0x0, 0x9c(%rdi)
jne 0x2431
movl $0x1, 0x9c(%rbx)
leaq 0x6f6d(%rip), %rdi      # 0x91db
callq 0x2060
leaq 0x6f89(%rip), %rdi      # 0x9203
callq 0x2060
movq (%rbx), %r14
testq %r14, %r14
je 0x22cc
leaq 0x6ec2(%rip), %r15      # 0x9150
leaq 0xbe1b(%rip), %r12      # 0xe0b0
xorl %ebp, %ebp
cmpl 0x10(%rbx), %ebp
jge 0x22cc
incl %ebp
movq %r15, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x2080
movl (%r14), %eax
movq (%r12,%rax,8), %rdi
movq %r14, %rsi
callq 0x244f
movl $0xa, %edi
callq 0x2040
movq 0x28(%r14), %r14
testq %r14, %r14
jne 0x2297
leaq 0x6f15(%rip), %rdi      # 0x91e8
callq 0x2060
movq 0x70(%rbx), %rdi
movl 0x78(%rbx), %esi
movl $0x4, %edx
callq 0x3fb7
cmpl $0x0, 0x78(%rbx)
jle 0x231c
leaq 0x6e60(%rip), %r14      # 0x9156
xorl %r15d, %r15d
movq 0x70(%rbx), %rax
movq (%rax,%r15,8), %rax
movl (%rax), %esi
movl 0x4(%rax), %edx
movq %r14, %rdi
xorl %eax, %eax
callq 0x2080
incq %r15
movslq 0x78(%rbx), %rax
cmpq %rax, %r15
jl 0x22f9
leaq 0x6ee0(%rip), %rdi      # 0x9203
callq 0x2060
movq (%rbx), %rax
testq %rax, %rax
je 0x2405
xorl %ecx, %ecx
cmpl 0x10(%rbx), %ecx
jge 0x2405
movq 0x8(%rax), %rdx
testq %rdx, %rdx
je 0x237c
cmpl $0x0, (%rdx)
jne 0x237c
cmpl $0x0, 0x78(%rbx)
jle 0x237c
xorl %edx, %edx
movq 0x70(%rbx), %rsi
movq (%rsi,%rdx,8), %rsi
movl (%rsi), %r8d
movq 0x8(%rax), %rdi
cmpl 0x8(%rdi), %r8d
jne 0x2370
movl 0x4(%rsi), %esi
movl %esi, 0x8(%rdi)
incq %rdx
movslq 0x78(%rbx), %rsi
cmpq %rsi, %rdx
jl 0x2355
movq 0x10(%rax), %rdx
testq %rdx, %rdx
je 0x23b9
cmpl $0x0, (%rdx)
jne 0x23b9
cmpl $0x0, 0x78(%rbx)
jle 0x23b9
xorl %edx, %edx
movq 0x70(%rbx), %rsi
movq (%rsi,%rdx,8), %rsi
movl (%rsi), %r8d
movq 0x10(%rax), %rdi
cmpl 0x8(%rdi), %r8d
jne 0x23ad
movl 0x4(%rsi), %esi
movl %esi, 0x8(%rdi)
incq %rdx
movslq 0x78(%rbx), %rsi
cmpq %rsi, %rdx
jl 0x2392
movq 0x18(%rax), %rdx
testq %rdx, %rdx
je 0x23f6
cmpl $0x0, (%rdx)
jne 0x23f6
cmpl $0x0, 0x78(%rbx)
jle 0x23f6
xorl %edx, %edx
movq 0x70(%rbx), %rsi
movq (%rsi,%rdx,8), %rsi
movl (%rsi), %r8d
movq 0x18(%rax), %rdi
cmpl 0x8(%rdi), %r8d
jne 0x23ea
movl 0x4(%rsi), %esi
movl %esi, 0x8(%rdi)
incq %rdx
movslq 0x78(%rbx), %rsi
cmpq %rsi, %rdx
jl 0x23cf
incl %ecx
movq 0x28(%rax), %rax
testq %rax, %rax
jne 0x2336
movl $0xa, %edi
callq 0x2040
cmpl $0x0, 0x38(%rbx)
jle 0x2431
xorl %r14d, %r14d
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x223c
incq %r14
movslq 0x38(%rbx), %rax
cmpq %rax, %r14
jl 0x2418
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq