// File: /workspace/github_c_makefile_star2_O3/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 0x1cd3
movb $0x0, -0x2a(%rbp)
movw $0x5841, -0x2c(%rbp)    # imm = 0x5841
jmp 0x1ce4
cmpq $0x0, 0x40(%r14)
je 0x1cc7
movb $0x0, -0x2a(%rbp)
movw $0x5842, -0x2c(%rbp)    # imm = 0x5842
movl (%r14), %eax
cmpl $0x48, %eax
jg 0x1d10
cmpl $0x40, %eax
je 0x1d44
cmpl $0x48, %eax
jne 0x1e20
leaq 0x15647(%rip), %rax     # 0x17348
movq (%rax), %rdi
leaq 0xd66b(%rip), %rsi      # 0xf376
jmp 0x1de3
cmpl $0x49, %eax
je 0x1db1
cmpl $0x71, %eax
jne 0x1e20
leaq 0x1561f(%rip), %rax     # 0x17348
movq (%rax), %rdi
movq 0x8(%r14), %rax
movq 0x8(%rax), %rcx
leaq 0xd4fb(%rip), %rsi      # 0xf236
leaq -0x2c(%rbp), %rdx
jmp 0x1e19
movq 0x30(%r14), %r13
movq 0x8(%r14), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0xb8e8
movq %rax, %r12
testq %r13, %r13
je 0x1df0
movq %r12, %rdi
callq 0xe01a
testl %eax, %eax
je 0x1dc4
movq 0x30(%r14), %rax
cmpl $0x71, (%rax)
jne 0x1dc4
leaq 0x155c8(%rip), %rax     # 0x17348
movq (%rax), %r15
movq %r12, %rdi
movq %r14, %rsi
movl $0x2, %edx
callq 0x176c
movl %eax, %edi
callq 0x1580
leaq 0xdc9b(%rip), %rsi      # 0xfa3c
leaq 0x155c8(%rip), %rcx     # 0x17370
leaq -0x2c(%rbp), %rdx
movq %r15, %rdi
jmp 0x1e19
leaq 0x15590(%rip), %rax     # 0x17348
movq (%rax), %rdi
leaq 0xd9d0(%rip), %rsi      # 0xf792
jmp 0x1de3
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x17b7
leaq 0x1556f(%rip), %rax     # 0x17348
movq (%rax), %rdi
leaq 0xd57b(%rip), %rsi      # 0xf35e
leaq -0x2c(%rbp), %rdx
xorl %eax, %eax
callq 0x1100
jmp 0x1e20
leaq 0x15551(%rip), %rax     # 0x17348
movq (%rax), %r14
movl 0x1c(%r12), %edi
callq 0x1580
leaq 0xdc31(%rip), %rsi      # 0xfa3c
leaq 0x1555e(%rip), %rcx     # 0x17370
leaq -0x2c(%rbp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1100
testl %ebx, %ebx
jne 0x1e40
leaq 0x1551d(%rip), %rax     # 0x17348
movq (%rax), %rdi
leaq 0xd54e(%rip), %rsi      # 0xf383
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