// File: /workspace/github_c_makefile_star2_O1/anuwu[P]ERPLAG-Compiler/codegen.c
// Function: switchCaseLabels
int switchCaseLabels (astNode *node, moduleST *lst, int caseCount , int *caseLabels)
{
	int i, def_label = -1 ;

	for (i = 0 ; i < caseCount ; i++)
		caseLabels[i] = get_label (LABEL_SWITCH) ;

	varST *switchVar = searchVar (lst, node->next->tok->lexeme) ;
	codePrint ("\n\t\tMOV AX, [RBP%s]", getOffsetStr(switchVar->offset)) ;
	codeComment (10, "loading switch variable") ;

	astNode *caseValNode =  node->next->next->next ;
	i = 0 ;

	if (switchVar->datatype == TK_INTEGER)
	{
		while (caseValNode != NULL)
		{
			codePrint ("\n\t\tCMP AX, %s", caseValNode->tok->lexeme) ;
			codeComment (11, "switch case") ;
			codePrint ("\t\tJE @SWITCH%d\n", caseLabels[i]) ;

			if (caseValNode->next->next->next->id == statements)
			{
				def_label = get_label (LABEL_SWITCH) ;
				codePrint ("\n\t\tJMP @SWITCH%d", def_label) ;
				codeComment (11, "default case") ;
				break ;
			}

			i++ ;
			caseValNode = caseValNode->next->next->next ;
		}
	}
	else
	{		
		codePrint ("\n\t\tCMP AX, 0\n") ;
		if (caseValNode->tok->lexeme[0] == 't')
		{
			codePrint ("\t\tJNE @SWITCH%d", caseLabels[0]) ;
			codeComment (11, "true case") ;
		}
		else
		{
			codePrint ("\t\tJE @SWITCH%d", caseLabels[0]) ;
			codeComment (11, "false case") ;
		}

		codePrint ("\t\tJMP @SWITCH%d", caseLabels[1]) ;
		if (caseValNode->tok->lexeme[0] == 't')
			codeComment (11, "false case") ;
		else
			codeComment (11, "true case") ;
	}

	return def_label ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbx
movq %rsi, %rax
movq %rdi, %r14
testl %edx, %edx
jle 0x36f4
movl %edx, %ecx
xorl %edx, %edx
movl 0x14c6f(%rip), %esi     # 0x18350
incl %esi
movl %esi, 0x14c67(%rip)     # 0x18350
movl %esi, (%rbx,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x36db
movq 0x38(%r14), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rsi
movq %rax, %rdi
callq 0xc430
movq %rax, %r15
leaq 0x14c36(%rip), %r13     # 0x18348
movq (%r13), %r12
movl 0x1c(%rax), %edi
callq 0x158c
leaq 0xd1e5(%rip), %rsi      # 0x1090a
leaq 0x14c44(%rip), %rdx     # 0x18370
movq %r12, %rdi
xorl %eax, %eax
callq 0x1100
leaq 0xd1e0(%rip), %rsi      # 0x1091d
movl $0xa, %edi
callq 0x153a
movq 0x38(%r14), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %r14
cmpl $0x37, 0x8(%r15)
jne 0x37f0
testq %r14, %r14
je 0x38a1
leaq 0xd1d5(%rip), %r15      # 0x10943
leaq 0xd1da(%rip), %r12      # 0x1094f
movq (%r13), %rdi
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdx
leaq 0xd1ad(%rip), %rsi      # 0x10935
xorl %eax, %eax
callq 0x1100
movl $0xb, %edi
movq %r15, %rsi
callq 0x153a
movq (%r13), %rdi
movl (%rbx), %edx
movq %r12, %rsi
xorl %eax, %eax
callq 0x1100
movq 0x38(%r14), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %r14
addq $0x4, %rbx
cmpl $0xc, (%r14)
jne 0x3775
movl 0x14b88(%rip), %ebx     # 0x18350
incl %ebx
movl %ebx, 0x14b80(%rip)     # 0x18350
movq (%r13), %rdi
leaq 0xd184(%rip), %rsi      # 0x1095f
movl %ebx, %edx
xorl %eax, %eax
callq 0x1100
leaq 0xd185(%rip), %r12      # 0x10970
jmp 0x3883
movq (%r13), %rcx
leaq 0xd182(%rip), %rdi      # 0x1097d
movl $0xd, %esi
movl $0x1, %edx
callq 0x1170
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
cmpb $0x74, (%rax)
movq (%r13), %rdi
movl (%rbx), %edx
leaq 0xd169(%rip), %rax      # 0x1098b
leaq 0xd17c(%rip), %rsi      # 0x109a5
cmoveq %rax, %rsi
leaq 0xd167(%rip), %r12      # 0x1099b
leaq 0xd179(%rip), %r15      # 0x109b4
cmoveq %r12, %r15
xorl %eax, %eax
callq 0x1100
movl $0xb, %edi
movq %r15, %rsi
callq 0x153a
movq (%r13), %rdi
movl 0x4(%rbx), %edx
leaq 0xd0ff(%rip), %rsi      # 0x10960
xorl %eax, %eax
callq 0x1100
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
cmpb $0x74, (%rax)
leaq 0xd13a(%rip), %rax      # 0x109b4
cmoveq %rax, %r12
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0xb, %edi
movq %r12, %rsi
callq 0x153a
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x3890