// File: /workspace/github_c_makefile_star2_O3/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 0x36cc
movl %edx, %ecx
xorl %edx, %edx
movl 0x13c97(%rip), %esi     # 0x17350
incl %esi
movl %esi, 0x13c8f(%rip)     # 0x17350
movl %esi, (%rbx,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x36b3
movq 0x38(%r14), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rsi
movq %rax, %rdi
callq 0xb8e8
movq %rax, %r15
leaq 0x13c5e(%rip), %r13     # 0x17348
movq (%r13), %r12
movl 0x1c(%rax), %edi
callq 0x1580
leaq 0xc20d(%rip), %rsi      # 0xf90a
leaq 0x13c6c(%rip), %rdx     # 0x17370
movq %r12, %rdi
xorl %eax, %eax
callq 0x1100
leaq 0xc208(%rip), %rsi      # 0xf91d
movl $0xa, %edi
callq 0x152e
movq 0x38(%r14), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %r14
cmpl $0x37, 0x8(%r15)
jne 0x37c8
testq %r14, %r14
je 0x3879
leaq 0xc1fd(%rip), %r15      # 0xf943
leaq 0xc202(%rip), %r12      # 0xf94f
movq (%r13), %rdi
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdx
leaq 0xc1d5(%rip), %rsi      # 0xf935
xorl %eax, %eax
callq 0x1100
movl $0xb, %edi
movq %r15, %rsi
callq 0x152e
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 0x374d
movl 0x13bb0(%rip), %ebx     # 0x17350
incl %ebx
movl %ebx, 0x13ba8(%rip)     # 0x17350
movq (%r13), %rdi
leaq 0xc1ac(%rip), %rsi      # 0xf95f
movl %ebx, %edx
xorl %eax, %eax
callq 0x1100
leaq 0xc1ad(%rip), %r12      # 0xf970
jmp 0x385b
movq (%r13), %rcx
leaq 0xc1aa(%rip), %rdi      # 0xf97d
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 0xc191(%rip), %rax      # 0xf98b
leaq 0xc1a4(%rip), %rsi      # 0xf9a5
cmoveq %rax, %rsi
leaq 0xc18f(%rip), %r12      # 0xf99b
leaq 0xc1a1(%rip), %r15      # 0xf9b4
cmoveq %r12, %r15
xorl %eax, %eax
callq 0x1100
movl $0xb, %edi
movq %r15, %rsi
callq 0x152e
movq (%r13), %rdi
movl 0x4(%rbx), %edx
leaq 0xc127(%rip), %rsi      # 0xf960
xorl %eax, %eax
callq 0x1100
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
cmpb $0x74, (%rax)
leaq 0xc162(%rip), %rax      # 0xf9b4
cmoveq %rax, %r12
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0xb, %edi
movq %r12, %rsi
callq 0x152e
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 0x3868