// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %rbx
movq 0x30(%rdi), %rax
testq %rax, %rax
je 0x1eeb
movq 0x38(%rax), %rdi
testq %rdi, %rdi
je 0x1eeb
movq %r15, %rsi
movl %r14d, %edx
callq 0x1e06
movq 0x30(%rbx), %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0x1e06
leaq 0x144e3(%rip), %r12     # 0x16338
movq (%r12), %rcx
leaq 0xc4b3(%rip), %rdi      # 0xe313
pushq $0x9
popq %r14
pushq $0x1
popq %r15
movq %r14, %rsi
movq %r15, %rdx
callq 0x1160
movq (%r12), %rcx
leaq 0xc510(%rip), %rdi      # 0xe38e
movq %r14, %rsi
movq %r15, %rdx
callq 0x1160
movl (%rbx), %eax
addl $-0x4e, %eax
cmpl $0x12, %eax
ja 0x204d
leaq 0xc2de(%rip), %rcx      # 0xe17c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r12), %rcx
leaq 0xc563(%rip), %rdi      # 0xe415
pushq $0xc
popq %rsi
pushq $0x1
popq %rdx
callq 0x1160
movl (%rbx), %eax
addl $-0x5b, %eax
cmpl $0x5, %eax
ja 0x2037
leaq 0xc2f6(%rip), %rcx      # 0xe1c8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r12), %rcx
leaq 0xc53c(%rip), %rdi      # 0xe422
jmp 0x2010
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x1c66
movq (%r12), %rcx
leaq 0xc48c(%rip), %rdi      # 0xe398
jmp 0x1fd8
movq (%r12), %rcx
leaq 0xc4a1(%rip), %rdi      # 0xe3bd
pushq $0xc
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x1160
orb $0x20, 0x14427(%rip)    # 0x16358
movl 0x14418(%rip), %r14d    # 0x16350
incl %r14d
movl %r14d, 0x1440e(%rip)    # 0x16350
movq (%r12), %rdi
leaq 0xc47d(%rip), %rsi      # 0xe3ca
movl %r14d, %edx
xorl %eax, %eax
callq 0x10f0
movq (%r12), %rcx
leaq 0xc47b(%rip), %rdi      # 0xe3dd
pushq $0x15
popq %rsi
movq %rbx, %rdx
callq 0x1160
movq (%r12), %rdi
leaq 0xc47b(%rip), %rsi      # 0xe3f3
movl %r14d, %edx
xorl %eax, %eax
callq 0x10f0
movq (%r12), %rcx
leaq 0xc476(%rip), %rdi      # 0xe403
pushq $0x6
popq %rsi
movq %rbx, %rdx
callq 0x1160
movq (%r12), %rcx
leaq 0xc467(%rip), %rdi      # 0xe40a
pushq $0xa
popq %rsi
movq %rbx, %rdx
jmp 0x2048
movq (%r12), %rcx
leaq 0xc4be(%rip), %rdi      # 0xe477
pushq $0xd
jmp 0x2044
movq (%r12), %rcx
leaq 0xc4ba(%rip), %rdi      # 0xe485
jmp 0x1fd8
movq (%r12), %rcx
leaq 0xc3cd(%rip), %rdi      # 0xe3a5
pushq $0xc
jmp 0x2044
movq (%r12), %rcx
leaq 0xc3cb(%rip), %rdi      # 0xe3b2
pushq $0xa
jmp 0x2044
movq (%r12), %rcx
leaq 0xc466(%rip), %rdi      # 0xe45c
jmp 0x2010
movq (%r12), %rcx
leaq 0xc441(%rip), %rdi      # 0xe444
jmp 0x202c
movq (%r12), %rcx
leaq 0xc41d(%rip), %rdi      # 0xe42d
pushq $0xa
jmp 0x202e
movq (%r12), %rcx
leaq 0xc419(%rip), %rdi      # 0xe438
jmp 0x202c
movq (%r12), %rcx
leaq 0xc424(%rip), %rdi      # 0xe450
pushq $0xb
popq %rsi
pushq $0x1
popq %rdx
callq 0x1160
movq (%r12), %rcx
leaq 0xc425(%rip), %rdi      # 0xe467
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
callq 0x1160
movq (%r12), %rcx
leaq 0xc43a(%rip), %rdi      # 0xe492
pushq $0xa
popq %rsi
pushq $0x1
popq %rdx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x1160