// File: /workspace/github_c_makefile_star2_O3/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 0x2445
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
cmpl $0x0, 0x9c(%rdi)
jne 0x243d
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 0x245b
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 0x3fa8
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 0x2411
xorl %ecx, %ecx
cmpl 0x10(%rbx), %ecx
jge 0x2411
movq 0x8(%rax), %rdx
testq %rdx, %rdx
je 0x2380
cmpl $0x0, (%rdx)
jne 0x2380
movl 0x78(%rbx), %edx
testl %edx, %edx
jle 0x2380
xorl %esi, %esi
movq 0x70(%rbx), %rdi
movq (%rdi,%rsi,8), %rdi
movl (%rdi), %r9d
movq 0x8(%rax), %r8
cmpl 0x8(%r8), %r9d
jne 0x2375
movl 0x4(%rdi), %edx
movl %edx, 0x8(%r8)
movl 0x78(%rbx), %edx
incq %rsi
movslq %edx, %rdi
cmpq %rdi, %rsi
jl 0x2356
movq 0x10(%rax), %rdx
testq %rdx, %rdx
je 0x23c1
cmpl $0x0, (%rdx)
jne 0x23c1
movl 0x78(%rbx), %edx
testl %edx, %edx
jle 0x23c1
xorl %esi, %esi
movq 0x70(%rbx), %rdi
movq (%rdi,%rsi,8), %rdi
movl (%rdi), %r9d
movq 0x10(%rax), %r8
cmpl 0x8(%r8), %r9d
jne 0x23b6
movl 0x4(%rdi), %edx
movl %edx, 0x8(%r8)
movl 0x78(%rbx), %edx
incq %rsi
movslq %edx, %rdi
cmpq %rdi, %rsi
jl 0x2397
movq 0x18(%rax), %rdx
testq %rdx, %rdx
je 0x2402
cmpl $0x0, (%rdx)
jne 0x2402
movl 0x78(%rbx), %edx
testl %edx, %edx
jle 0x2402
xorl %esi, %esi
movq 0x70(%rbx), %rdi
movq (%rdi,%rsi,8), %rdi
movl (%rdi), %r9d
movq 0x18(%rax), %r8
cmpl 0x8(%r8), %r9d
jne 0x23f7
movl 0x4(%rdi), %edx
movl %edx, 0x8(%r8)
movl 0x78(%rbx), %edx
incq %rsi
movslq %edx, %rdi
cmpq %rdi, %rsi
jl 0x23d8
incl %ecx
movq 0x28(%rax), %rax
testq %rax, %rax
jne 0x2336
movl $0xa, %edi
callq 0x2040
cmpl $0x0, 0x38(%rbx)
jle 0x243d
xorl %r14d, %r14d
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x223c
incq %r14
movslq 0x38(%rbx), %rax
cmpq %rax, %r14
jl 0x2424
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq