// File: /workspace/github_c_makefile_star2_O3/anuwu[P]ERPLAG-Compiler/codegen.c
// Function: expr
void expr (astNode *node, moduleST *lst, int singleAssign)
{
	if (node->child == NULL || node->child->next == NULL)
	{
		exprLeaf (node, lst, singleAssign) ;
		return ;
	}

	expr (node->child->next, lst, singleAssign) ;
	expr (node->child, lst, singleAssign); 
	codePrint ("\t\tPOP AX\n");
	codePrint ("\t\tPOP BX\n");

	switch (node->id)
	{
		case TK_PLUS :
			codePrint ("\t\tADD AX,BX\n");
			break ;

		case TK_MINUS :
			codePrint ("\t\tSUB AX,BX\n");
			break ;

		case TK_MUL :
			codePrint ("\t\tIMUL BX\n");
			break ;

		case TK_DIV :
		{
			codePrint ("\t\tCMP BX, 0\n") ;

			tf |= 1 << divZeroERROR ;
			int lab = get_label (LABEL_DIV_ZERO) ;
			codePrint ("\t\tJNE @DIV_ZERO%d\n", lab) ;
			codePrint ("\t\tCALL @divZeroERROR\n") ;

			codePrint ("\n\t@DIV_ZERO%d:\n", lab) ;
			codePrint ("\t\tCWD\n") ;
			codePrint ("\t\tIDIV BX\n");
			break ;
		}

		case TK_LT : case TK_GT : case TK_LE : case TK_GE : case TK_NE : case TK_EQ :
		{
			codePrint ("\t\tCMP AX,BX\n");

			switch (node->id)
			{
				case TK_LT :
					codePrint ("\t\tSETL AL\n");
					break ;
				case TK_GT :
					codePrint ("\t\tSETG AL\n");
					break ;
				case TK_LE :
					codePrint ("\t\tSETLE AL\n");
					break ;
				case TK_GE :
					codePrint ("\t\tSETGE AL\n");
					break ;
				case TK_NE :
					codePrint ("\t\tSETNE AL\n");
					break ;
				case TK_EQ :
					codePrint ("\t\tSETE AL\n");
					break ;
			}
			codePrint ("\t\tMOVSX AX, AL\n") ;

			break ;
		}

		case TK_AND : case TK_OR :
		{
			if (node->id == TK_AND)
				codePrint ("\t\tAND AX, BX\n");
			else
				codePrint ("\t\tOR AX, BX\n");

			break ;
		}
	}

	codePrint ("\t\tPUSH AX\n") ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %rbx
movq 0x30(%rdi), %rax
testq %rax, %rax
je 0x1f33
movq 0x38(%rax), %rdi
testq %rdi, %rdi
je 0x1f33
movq %r15, %rsi
movl %r14d, %edx
callq 0x1e4f
movq 0x30(%rbx), %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0x1e4f
leaq 0x154ab(%rip), %r14     # 0x17348
movq (%r14), %rcx
leaq 0xd46c(%rip), %rdi      # 0xf313
movl $0x9, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rcx
leaq 0xd4ce(%rip), %rdi      # 0xf38e
movl $0x9, %esi
movl $0x1, %edx
callq 0x1170
movl (%rbx), %eax
addl $-0x4e, %eax
cmpl $0x12, %eax
ja 0x2095
leaq 0xd298(%rip), %rcx      # 0xf17c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r14), %rcx
leaq 0xd51e(%rip), %rdi      # 0xf415
movl $0xc, %esi
movl $0x1, %edx
callq 0x1170
movl (%rbx), %eax
addl $-0x5b, %eax
cmpl $0x5, %eax
ja 0x207c
leaq 0xd2ad(%rip), %rcx      # 0xf1c8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r14), %rcx
leaq 0xd4f4(%rip), %rdi      # 0xf422
jmp 0x2050
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1cad
movq (%r14), %rcx
leaq 0xd443(%rip), %rdi      # 0xf398
jmp 0x2016
movq (%r14), %rcx
leaq 0xd459(%rip), %rdi      # 0xf3bd
movl $0xc, %esi
movl $0x1, %edx
callq 0x1170
orb $0x20, 0x153ee(%rip)    # 0x17368
movl 0x153e0(%rip), %ebx     # 0x17360
incl %ebx
movl %ebx, 0x153d8(%rip)     # 0x17360
movq (%r14), %rdi
leaq 0xd438(%rip), %rsi      # 0xf3ca
movl %ebx, %edx
xorl %eax, %eax
callq 0x1100
movq (%r14), %rcx
leaq 0xd438(%rip), %rdi      # 0xf3dd
movl $0x15, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rdi
leaq 0xd435(%rip), %rsi      # 0xf3f3
movl %ebx, %edx
xorl %eax, %eax
callq 0x1100
movq (%r14), %rcx
leaq 0xd432(%rip), %rdi      # 0xf403
movl $0x6, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rcx
leaq 0xd420(%rip), %rdi      # 0xf40a
jmp 0x2027
movq (%r14), %rcx
leaq 0xd481(%rip), %rdi      # 0xf477
movl $0xd, %esi
jmp 0x208b
movq (%r14), %rcx
leaq 0xd47b(%rip), %rdi      # 0xf485
jmp 0x2016
movq (%r14), %rcx
leaq 0xd38f(%rip), %rdi      # 0xf3a5
movl $0xc, %esi
jmp 0x208b
movq (%r14), %rcx
leaq 0xd38b(%rip), %rdi      # 0xf3b2
movl $0xa, %esi
jmp 0x208b
movq (%r14), %rcx
leaq 0xd424(%rip), %rdi      # 0xf45c
jmp 0x2050
movq (%r14), %rcx
leaq 0xd400(%rip), %rdi      # 0xf444
jmp 0x206d
movq (%r14), %rcx
leaq 0xd3dd(%rip), %rdi      # 0xf42d
movl $0xa, %esi
jmp 0x2072
movq (%r14), %rcx
leaq 0xd3d7(%rip), %rdi      # 0xf438
jmp 0x206d
movq (%r14), %rcx
leaq 0xd3e3(%rip), %rdi      # 0xf450
movl $0xb, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rcx
leaq 0xd3e1(%rip), %rdi      # 0xf467
movl $0xf, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rcx
leaq 0xd3f3(%rip), %rdi      # 0xf492
movl $0xa, %esi
movl $0x1, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1170