// File: /workspace/github_c_makefile_star2_O0/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
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x20e6
movq -0x8(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x20e6
leaq -0x17(%rbp), %rdi
leaq 0x137f1(%rip), %rsi     # 0x158d0
callq 0x1040
jmp 0x20f6
leaq -0x17(%rbp), %rdi
leaq 0x133d1(%rip), %rsi     # 0x154c2
callq 0x1040
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
subl $0x40, %eax
je 0x2141
jmp 0x2106
movl -0x2c(%rbp), %eax
subl $0x48, %eax
je 0x2280
jmp 0x2114
movl -0x2c(%rbp), %eax
subl $0x49, %eax
je 0x229e
jmp 0x2122
movl -0x2c(%rbp), %eax
subl $0x71, %eax
je 0x2256
jmp 0x2130
movl -0x2c(%rbp), %eax
subl $0x72, %eax
je 0x2254
jmp 0x22ba
movq -0x8(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x21a5
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x10ba0
movq %rax, -0x20(%rbp)
leaq 0x1b1bc(%rip), %rax     # 0x1d328
movq (%rax), %rax
movq %rax, -0x40(%rbp)
leaq -0x17(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %edi
callq 0x1730
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq %rax, %rcx
leaq 0x13a19(%rip), %rsi     # 0x15bb2
movb $0x0, %al
callq 0x10d0
jmp 0x2252
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x10ba0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x13fc0
cmpl $0x0, %eax
je 0x2223
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
cmpl $0x71, (%rax)
jne 0x2223
leaq 0x1b148(%rip), %rax     # 0x1d328
movq (%rax), %rax
movq %rax, -0x50(%rbp)
leaq -0x17(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl $0x2, %edx
callq 0x19f0
movl %eax, %edi
callq 0x1730
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rdx
movq %rax, %rcx
leaq 0x13998(%rip), %rsi     # 0x15bb2
movb $0x0, %al
callq 0x10d0
jmp 0x2250
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x1a60
leaq 0x1b0ed(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x17(%rbp), %rdx
leaq 0x1328b(%rip), %rsi     # 0x154d4
movb $0x0, %al
callq 0x10d0
jmp 0x2252
jmp 0x22ba
jmp 0x22ba
leaq 0x1b0cb(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x17(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rcx
leaq 0x13135(%rip), %rsi     # 0x153ac
movb $0x0, %al
callq 0x10d0
jmp 0x22ba
leaq 0x1b0a1(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x17(%rbp), %rdx
leaq 0x13257(%rip), %rsi     # 0x154ec
movb $0x0, %al
callq 0x10d0
jmp 0x22ba
leaq 0x1b083(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x17(%rbp), %rdx
leaq 0x13655(%rip), %rsi     # 0x15908
movb $0x0, %al
callq 0x10d0
cmpl $0x0, -0x14(%rbp)
jne 0x22dc
leaq 0x1b061(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x17(%rbp), %rdx
leaq 0x13224(%rip), %rsi     # 0x154f9
movb $0x0, %al
callq 0x10d0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)