// File: /workspace/github_c_makefile_star2_O1/anuwu[P]ERPLAG-Compiler/codegen.c
// Function: exprLeaf
void exprLeaf (astNode *node, moduleST *lst, int singleAssign)
{
	char reg[3] ;

	if (!singleAssign && node->prev != NULL)
		strcpy (reg, "BX") ;
	else
		strcpy (reg, "AX") ;

	switch (node->id)
	{
		case TK_ID :
			if (node->child == NULL)
			{
				varST *searchedVar = searchVar (lst, node->tok->lexeme) ;
				codePrint ("\t\tMOV %s, [RBP%s]\n", reg, getOffsetStr(searchedVar->offset)) ;
			}
			else
			{
				varST *vst ;
				vst = searchVar (lst,node->tok->lexeme) ;

				if (isVarStaticArr(vst) && node->child->id == TK_NUM)
					codePrint ("\t\tMOV %s, [RBP%s]\n", reg, getOffsetStr(getStaticOffset (vst, node, 2))) ;						
				else
				{
					arrBoundCheck (node, lst, vst) ;
					codePrint ("\t\tMOV %s, [RDI + RBX]\n\n", reg) ;
				}				
			}

			break ;

		case TK_RNUM :
			break ;

		case TK_NUM : 
			codePrint ("\t\tMOV %s, %s\n", reg, node->tok->lexeme);
			break ;

		case TK_TRUE :
			codePrint ("\t\tMOV %s, 1\n", reg);
			break ;

		case TK_FALSE :
			codePrint ("\t\tMOV %s, 0\n", reg);
			break ;
	}

	if (!singleAssign)
		codePrint ("\t\tPUSH %s\n", reg);	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, %r14
testl %edx, %edx
je 0x1cdf
movb $0x0, -0x2a(%rbp)
movw $0x5841, -0x2c(%rbp)    # imm = 0x5841
jmp 0x1cf0
cmpq $0x0, 0x40(%r14)
je 0x1cd3
movb $0x0, -0x2a(%rbp)
movw $0x5842, -0x2c(%rbp)    # imm = 0x5842
movl (%r14), %eax
cmpl $0x48, %eax
jg 0x1d1c
cmpl $0x40, %eax
je 0x1d50
cmpl $0x48, %eax
jne 0x1e2c
leaq 0x1663b(%rip), %rax     # 0x18348
movq (%rax), %rdi
leaq 0xe65f(%rip), %rsi      # 0x10376
jmp 0x1def
cmpl $0x49, %eax
je 0x1dbd
cmpl $0x71, %eax
jne 0x1e2c
leaq 0x16613(%rip), %rax     # 0x18348
movq (%rax), %rdi
movq 0x8(%r14), %rax
movq 0x8(%rax), %rcx
leaq 0xe4ef(%rip), %rsi      # 0x10236
leaq -0x2c(%rbp), %rdx
jmp 0x1e25
movq 0x30(%r14), %r13
movq 0x8(%r14), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0xc430
movq %rax, %r12
testq %r13, %r13
je 0x1dfc
movq %r12, %rdi
callq 0xe88a
testl %eax, %eax
je 0x1dd0
movq 0x30(%r14), %rax
cmpl $0x71, (%rax)
jne 0x1dd0
leaq 0x165bc(%rip), %rax     # 0x18348
movq (%rax), %r15
movq %r12, %rdi
movq %r14, %rsi
movl $0x2, %edx
callq 0x1778
movl %eax, %edi
callq 0x158c
leaq 0xec8f(%rip), %rsi      # 0x10a3c
leaq 0x165bc(%rip), %rcx     # 0x18370
leaq -0x2c(%rbp), %rdx
movq %r15, %rdi
jmp 0x1e25
leaq 0x16584(%rip), %rax     # 0x18348
movq (%rax), %rdi
leaq 0xe9c4(%rip), %rsi      # 0x10792
jmp 0x1def
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x17c3
leaq 0x16563(%rip), %rax     # 0x18348
movq (%rax), %rdi
leaq 0xe56f(%rip), %rsi      # 0x1035e
leaq -0x2c(%rbp), %rdx
xorl %eax, %eax
callq 0x1100
jmp 0x1e2c
leaq 0x16545(%rip), %rax     # 0x18348
movq (%rax), %r14
movl 0x1c(%r12), %edi
callq 0x158c
leaq 0xec25(%rip), %rsi      # 0x10a3c
leaq 0x16552(%rip), %rcx     # 0x18370
leaq -0x2c(%rbp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1100
testl %ebx, %ebx
jne 0x1e4c
leaq 0x16511(%rip), %rax     # 0x18348
movq (%rax), %rdi
leaq 0xe542(%rip), %rsi      # 0x10383
leaq -0x2c(%rbp), %rdx
xorl %eax, %eax
callq 0x1100
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq