// File: /workspace/github_c_makefile_star2_O1/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 0x1f3f
movq 0x38(%rax), %rdi
testq %rdi, %rdi
je 0x1f3f
movq %r15, %rsi
movl %r14d, %edx
callq 0x1e5b
movq 0x30(%rbx), %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0x1e5b
leaq 0x1649f(%rip), %r14     # 0x18348
movq (%r14), %rcx
leaq 0xe460(%rip), %rdi      # 0x10313
movl $0x9, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rcx
leaq 0xe4c2(%rip), %rdi      # 0x1038e
movl $0x9, %esi
movl $0x1, %edx
callq 0x1170
movl (%rbx), %eax
addl $-0x4e, %eax
cmpl $0x12, %eax
ja 0x20a1
leaq 0xe28c(%rip), %rcx      # 0x1017c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r14), %rcx
leaq 0xe512(%rip), %rdi      # 0x10415
movl $0xc, %esi
movl $0x1, %edx
callq 0x1170
movl (%rbx), %eax
addl $-0x5b, %eax
cmpl $0x5, %eax
ja 0x2088
leaq 0xe2a1(%rip), %rcx      # 0x101c8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r14), %rcx
leaq 0xe4e8(%rip), %rdi      # 0x10422
jmp 0x205c
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1cb9
movq (%r14), %rcx
leaq 0xe437(%rip), %rdi      # 0x10398
jmp 0x2022
movq (%r14), %rcx
leaq 0xe44d(%rip), %rdi      # 0x103bd
movl $0xc, %esi
movl $0x1, %edx
callq 0x1170
orb $0x20, 0x163e2(%rip)    # 0x18368
movl 0x163d4(%rip), %ebx     # 0x18360
incl %ebx
movl %ebx, 0x163cc(%rip)     # 0x18360
movq (%r14), %rdi
leaq 0xe42c(%rip), %rsi      # 0x103ca
movl %ebx, %edx
xorl %eax, %eax
callq 0x1100
movq (%r14), %rcx
leaq 0xe42c(%rip), %rdi      # 0x103dd
movl $0x15, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rdi
leaq 0xe429(%rip), %rsi      # 0x103f3
movl %ebx, %edx
xorl %eax, %eax
callq 0x1100
movq (%r14), %rcx
leaq 0xe426(%rip), %rdi      # 0x10403
movl $0x6, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rcx
leaq 0xe414(%rip), %rdi      # 0x1040a
jmp 0x2033
movq (%r14), %rcx
leaq 0xe475(%rip), %rdi      # 0x10477
movl $0xd, %esi
jmp 0x2097
movq (%r14), %rcx
leaq 0xe46f(%rip), %rdi      # 0x10485
jmp 0x2022
movq (%r14), %rcx
leaq 0xe383(%rip), %rdi      # 0x103a5
movl $0xc, %esi
jmp 0x2097
movq (%r14), %rcx
leaq 0xe37f(%rip), %rdi      # 0x103b2
movl $0xa, %esi
jmp 0x2097
movq (%r14), %rcx
leaq 0xe418(%rip), %rdi      # 0x1045c
jmp 0x205c
movq (%r14), %rcx
leaq 0xe3f4(%rip), %rdi      # 0x10444
jmp 0x2079
movq (%r14), %rcx
leaq 0xe3d1(%rip), %rdi      # 0x1042d
movl $0xa, %esi
jmp 0x207e
movq (%r14), %rcx
leaq 0xe3cb(%rip), %rdi      # 0x10438
jmp 0x2079
movq (%r14), %rcx
leaq 0xe3d7(%rip), %rdi      # 0x10450
movl $0xb, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rcx
leaq 0xe3d5(%rip), %rdi      # 0x10467
movl $0xf, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rcx
leaq 0xe3e7(%rip), %rdi      # 0x10492
movl $0xa, %esi
movl $0x1, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1170