// File: /workspace/github_c_makefile_star2_O2/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 0x1c8c
movb $0x0, -0x2a(%rbp)
movw $0x5841, -0x2c(%rbp)    # imm = 0x5841
jmp 0x1c9d
cmpq $0x0, 0x40(%r14)
je 0x1c80
movb $0x0, -0x2a(%rbp)
movw $0x5842, -0x2c(%rbp)    # imm = 0x5842
movl (%r14), %eax
cmpl $0x71, %eax
je 0x1d5c
cmpl $0x48, %eax
je 0x1d36
cmpl $0x49, %eax
je 0x1d49
cmpl $0x40, %eax
jne 0x1dd7
movq 0x30(%r14), %r13
movq 0x8(%r14), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0xac19
movq %rax, %r12
testq %r13, %r13
je 0x1da7
movq %r12, %rdi
callq 0xcd66
testl %eax, %eax
je 0x1d7b
movq 0x30(%r14), %rax
cmpl $0x71, (%rax)
jne 0x1d7b
leaq 0x14634(%rip), %rax     # 0x16338
movq (%rax), %r15
pushq $0x2
popq %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x1757
movl %eax, %edi
callq 0x156f
leaq 0xcd19(%rip), %rsi      # 0xea3c
leaq 0x14636(%rip), %rcx     # 0x16360
leaq -0x2c(%rbp), %rdx
movq %r15, %rdi
jmp 0x1dd0
leaq 0x145fb(%rip), %rax     # 0x16338
movq (%rax), %rdi
leaq 0xc62f(%rip), %rsi      # 0xe376
jmp 0x1d9a
leaq 0x145e8(%rip), %rax     # 0x16338
movq (%rax), %rdi
leaq 0xca38(%rip), %rsi      # 0xe792
jmp 0x1d9a
leaq 0x145d5(%rip), %rax     # 0x16338
movq (%rax), %rdi
movq 0x8(%r14), %rax
movq 0x8(%rax), %rcx
leaq 0xc4c1(%rip), %rsi      # 0xe236
leaq -0x2c(%rbp), %rdx
jmp 0x1dd0
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x17a2
leaq 0x145a8(%rip), %rax     # 0x16338
movq (%rax), %rdi
leaq 0xc5c4(%rip), %rsi      # 0xe35e
leaq -0x2c(%rbp), %rdx
xorl %eax, %eax
callq 0x10f0
jmp 0x1dd7
leaq 0x1458a(%rip), %rax     # 0x16338
movq (%rax), %r14
movl 0x1c(%r12), %edi
callq 0x156f
leaq 0xcc7a(%rip), %rsi      # 0xea3c
leaq 0x14597(%rip), %rcx     # 0x16360
leaq -0x2c(%rbp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x10f0
testl %ebx, %ebx
jne 0x1df7
leaq 0x14556(%rip), %rax     # 0x16338
movq (%rax), %rdi
leaq 0xc597(%rip), %rsi      # 0xe383
leaq -0x2c(%rbp), %rdx
xorl %eax, %eax
callq 0x10f0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq