// File: /workspace/github_c_makefile_star2_O0/Mithreindeir[P]ewcc/src/main.c
// Function: main
int main()
{
	char *str = NULL;
	int slen = 1;
	char buf[64];
	int len = 0;
	while ((len = read(0, buf, 64)) > 0) {
		slen += len;
		if (!str)
			str = malloc(slen);
		else
			str = realloc(str, slen + len);
		memcpy(str + (slen - len - 1), buf, len);
		str[slen - 1] = 0;
	}
	int toks = 0;
	struct token **tok = tokenify(str, &toks);
	free(str);

	struct parser *p = parser_init(tok, toks);
	//struct stmt *s = parse_function(p);
	struct stmt *s = parse_unit(p);
	if (s) {
		node_check(s, NULL);
		printf("AST Tree View\n");
		printf("------------------------------------\n");
		node_debug(s);
		printf("\n");
		printf("------------------------------------\n");

		struct ir_stmt *stmt = generate(s);

		optimize(stmt);
		printf("TAC Intermediate Representation\n");
		printf("------------------------------------\n");
		ir_debug(stmt);
		int nbbs=0;
		printf("------------------------------------\n");
		printf("Interference Graph\n");
		printf("------------------------------------\n");
		struct bb **bbs = cfg(stmt, &nbbs);
		bb_creg(bbs[0]);
		optimize(stmt);
		printf("------------------------------------\n");
		printf("After Register Rewriting:\n");
		//instr(stmt);
		ir_debug(stmt);
		for (int i = 0; i < nbbs; i++) {
			bb_free(bbs[i]);
		}
		free(bbs);
		printf("------------------------------------\n");

	       	struct ir_stmt *next=NULL;
		while (stmt) {
			next = stmt->next;
			ir_stmt_free(stmt);
			stmt = next;
		}
		node_free(s);
	}
	parser_free(p);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movl $0x0, -0x4(%rbp)
movq $0x0, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movl $0x0, -0x64(%rbp)
leaq -0x60(%rbp), %rsi
xorl %edi, %edi
movl $0x40, %edx
callq 0x2080
movl %eax, -0x64(%rbp)
cmpl $0x0, %eax
jle 0x44f7
movl -0x64(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x44af
movslq -0x14(%rbp), %rdi
callq 0x20e0
movq %rax, -0x10(%rbp)
jmp 0x44c5
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %eax
addl -0x64(%rbp), %eax
movslq %eax, %rsi
callq 0x20f0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %eax
subl -0x64(%rbp), %eax
subl $0x1, %eax
cltq
addq %rax, %rdi
leaq -0x60(%rbp), %rsi
movslq -0x64(%rbp), %rdx
callq 0x20d0
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
jmp 0x4478
movl $0x0, -0x68(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x93b0
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2030
movq -0x70(%rbp), %rdi
movl -0x68(%rbp), %esi
callq 0xa870
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
callq 0xa810
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
je 0x4709
movq -0x80(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8aa0
leaq 0x7d50(%rip), %rdi      # 0xc2a4
movb $0x0, %al
callq 0x2060
leaq 0x7bd8(%rip), %rdi      # 0xc13a
movb $0x0, %al
callq 0x2060
movq -0x80(%rbp), %rdi
callq 0x29f0
leaq 0x7e76(%rip), %rdi      # 0xc3ef
movb $0x0, %al
callq 0x2060
leaq 0x7bb3(%rip), %rdi      # 0xc13a
movb $0x0, %al
callq 0x2060
movq -0x80(%rbp), %rdi
callq 0x58e0
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
callq 0x51e0
leaq 0x7d02(%rip), %rdi      # 0xc2b3
movb $0x0, %al
callq 0x2060
leaq 0x7b7b(%rip), %rdi      # 0xc13a
movb $0x0, %al
callq 0x2060
movq -0x88(%rbp), %rdi
callq 0x28d0
movl $0x0, -0x8c(%rbp)
leaq 0x7b57(%rip), %rdi      # 0xc13a
movb $0x0, %al
callq 0x2060
leaq 0x7ce3(%rip), %rdi      # 0xc2d4
movb $0x0, %al
callq 0x2060
leaq 0x7b3b(%rip), %rdi      # 0xc13a
movb $0x0, %al
callq 0x2060
movq -0x88(%rbp), %rdi
leaq -0x8c(%rbp), %rsi
callq 0x3e60
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq (%rax), %rdi
callq 0x3c60
movq -0x88(%rbp), %rdi
callq 0x51e0
leaq 0x7af8(%rip), %rdi      # 0xc13a
movb $0x0, %al
callq 0x2060
leaq 0x7c98(%rip), %rdi      # 0xc2e8
movb $0x0, %al
callq 0x2060
movq -0x88(%rbp), %rdi
callq 0x28d0
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
cmpl -0x8c(%rbp), %eax
jge 0x46a3
movq -0x98(%rbp), %rax
movslq -0x9c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3840
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x466d
movq -0x98(%rbp), %rdi
callq 0x2030
leaq 0x7a84(%rip), %rdi      # 0xc13a
movb $0x0, %al
callq 0x2060
movq $0x0, -0xa8(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x4700
movq -0x88(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x88(%rbp), %rdi
callq 0x7180
movq -0xa8(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x46c8
movq -0x80(%rbp), %rdi
callq 0x7660
movq -0x78(%rbp), %rdi
callq 0xa980
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nop