// File: /workspace/github_c_makefile_star2_O0/Mithreindeir[P]ewcc/src/live.c
// Function: bb_set
void bb_set(struct bb *blk)
{
	struct ir_stmt *cur = blk->blk;

	int iter = 0;
	while (cur && iter < blk->len) {
		def(blk, cur);
		use(blk, cur);
		iter++;
		cur = cur->next;
	}

	for (int i = 0; i < blk->ndef; i++)
		(void)bb_get_treg(blk, blk->def[i]);
	for (int i = 0; i < blk->nuse; i++)
		(void)bb_get_treg(blk, blk->use[i]);

	cur = blk->blk;
	iter = 0;
	int *defd = calloc(blk->nvert, sizeof(int)), ndefd = blk->nvert;
	int *kill = calloc(blk->nvert, sizeof(int)), nkill = blk->nvert;

	while (cur && iter < blk->len) {
		/*Stores do not overwrite registers*/
		if (cur->result && cur->result->type == oper_reg && cur->type != stmt_store) {
			defd[bb_get_treg(blk, cur->result->val.virt_reg)] = iter;
			kill[bb_get_treg(blk, cur->result->val.virt_reg)] = iter;
		}
		/*set kill*/
		if (cur->arg1 && cur->arg1->type == oper_reg) {
			kill[bb_get_treg(blk, cur->arg1->val.virt_reg)] = iter;
		}
		if (cur->arg2 && cur->arg2->type == oper_reg) {
			kill[bb_get_treg(blk, cur->arg2->val.virt_reg)] = iter;
		}
		cur = cur->next;
		iter++;
	}
	/*Get the line number*/
	struct ir_stmt *cnt = blk->blk;
	int pl = 0;
	while (cnt) {
		pl++;
		cnt = cnt->prev;
	}

	for (int i = 0; i < nkill; i++)
		printf("R%d is defined at %d and killed at %d\n",blk->graph[i]->ocolor, pl+defd[i], pl+kill[i]);

	/*Construct interference graph*/
	for (int i = 0; i < ndefd; i++) {
		for (int j = 0; j < nkill; j++) {
			if (j == i) continue;
			if (kill[j] < (defd[i]+1) || (defd[j]+1) > kill[i])
				continue;
			struct vertex *v2 = blk->graph[j];
			struct vertex *v = blk->graph[i];
			int added = 0;
			for (int k = 0; k < v->num_siblings; k++) {
				if (v->siblings[k] == v2) {
					added = 1;
					break;
				}
			}
			if (!added) {
				printf("R%d interferes with R%d\n", v->ocolor, v2->ocolor);
				add_edge(v, v2);
			}
		}
	}

	free(kill);
	free(defd);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x10(%rbp)
movb %al, -0x71(%rbp)
je 0x33ed
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
setl %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x33f6
jmp 0x3427
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3af0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x3bd0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x33d1
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x68(%rcx), %eax
jge 0x345d
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x38e0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x342e
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x58(%rcx), %eax
jge 0x3493
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x38e0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3464
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rax
movslq 0x78(%rax), %rdi
movl $0x4, %esi
callq 0x2090
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl 0x78(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movslq 0x78(%rax), %rdi
movl $0x4, %esi
callq 0x2090
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0x78(%rax), %eax
movl %eax, -0x3c(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x10(%rbp)
movb %al, -0x72(%rbp)
je 0x3501
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
setl %al
movb %al, -0x72(%rbp)
movb -0x72(%rbp), %al
testb $0x1, %al
jne 0x350d
jmp 0x366a
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x35a6
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x0, (%rax)
jne 0x35a6
movq -0x10(%rbp), %rax
cmpl $0x12, (%rax)
je 0x35a6
movl -0x14(%rbp), %eax
movl %eax, -0x94(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %esi
callq 0x38e0
movl -0x94(%rbp), %edx
movl %eax, %ecx
movq -0x90(%rbp), %rax
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
movl %eax, -0x84(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x8(%rax), %esi
callq 0x38e0
movl -0x84(%rbp), %edx
movl %eax, %ecx
movq -0x80(%rbp), %rax
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x35fb
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
cmpl $0x0, (%rax)
jne 0x35fb
movl -0x14(%rbp), %eax
movl %eax, -0xa4(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x8(%rax), %esi
callq 0x38e0
movl -0xa4(%rbp), %edx
movl %eax, %ecx
movq -0xa0(%rbp), %rax
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x3650
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
cmpl $0x0, (%rax)
jne 0x3650
movl -0x14(%rbp), %eax
movl %eax, -0xb4(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x8(%rax), %esi
callq 0x38e0
movl -0xb4(%rbp), %edx
movl %eax, %ecx
movq -0xb0(%rbp), %rax
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x10(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x34e5
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x369a
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x367c
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x36f0
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %esi
movl -0x4c(%rbp), %edx
movq -0x28(%rbp), %rax
movslq -0x50(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movl -0x4c(%rbp), %ecx
movq -0x38(%rbp), %rax
movslq -0x50(%rbp), %rdi
addl (%rax,%rdi,4), %ecx
leaq 0x8b73(%rip), %rdi      # 0xc251
movb $0x0, %al
callq 0x2060
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x36a1
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x381b
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x380b
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jne 0x3723
jmp 0x37fd
movq -0x38(%rbp), %rax
movslq -0x58(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x28(%rbp), %rcx
movslq -0x54(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jl 0x375b
movq -0x28(%rbp), %rax
movslq -0x58(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl $0x1, %eax
movq -0x38(%rbp), %rcx
movslq -0x54(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x3760
jmp 0x37fd
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
movq -0x68(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x37ce
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x60(%rbp), %rax
jne 0x37c1
movl $0x1, -0x6c(%rbp)
jmp 0x37ce
jmp 0x37c3
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x3796
cmpl $0x0, -0x6c(%rbp)
jne 0x37fb
movq -0x68(%rbp), %rax
movl (%rax), %esi
movq -0x60(%rbp), %rax
movl (%rax), %edx
leaq 0x8a91(%rip), %rdi      # 0xc278
movb $0x0, %al
callq 0x2060
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x5300
jmp 0x37fd
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x370a
jmp 0x380d
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x36f7
movq -0x38(%rbp), %rdi
callq 0x2030
movq -0x28(%rbp), %rdi
callq 0x2030
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)