// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x41dc
xorl %edi, %edi
callq 0x1600
movl %eax, %edx
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x41b5
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x10ba0
movq %rax, -0x30(%rbp)
leaq 0x19128(%rip), %rax     # 0x1d328
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movl 0x1c(%rax), %edi
callq 0x1730
movq -0x40(%rbp), %rdi
movq %rax, %rdx
leaq 0x1185f(%rip), %rsi     # 0x15a80
movb $0x0, %al
callq 0x10d0
movl $0xa, %edi
leaq 0x1185f(%rip), %rsi     # 0x15a93
callq 0x16c0
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x37, 0x8(%rax)
jne 0x433b
jmp 0x4264
cmpq $0x0, -0x38(%rbp)
je 0x4336
leaq 0x190b2(%rip), %rax     # 0x1d328
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdx
leaq 0x1181f(%rip), %rsi     # 0x15aab
movb $0x0, %al
callq 0x10d0
movl $0xb, %edi
leaq 0x1181a(%rip), %rsi     # 0x15ab9
callq 0x16c0
leaq 0x1907d(%rip), %rax     # 0x1d328
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x11805(%rip), %rsi     # 0x15ac5
movb $0x0, %al
callq 0x10d0
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rax
cmpl $0xc, (%rax)
jne 0x4314
xorl %edi, %edi
callq 0x1600
movl %eax, -0x28(%rbp)
leaq 0x1903b(%rip), %rax     # 0x1d328
movq (%rax), %rdi
movl -0x28(%rbp), %edx
leaq 0x117db(%rip), %rsi     # 0x15ad5
movb $0x0, %al
callq 0x10d0
movl $0xb, %edi
leaq 0x117d9(%rip), %rsi     # 0x15ae6
callq 0x16c0
jmp 0x4336
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x4264
jmp 0x4420
leaq 0x18fe6(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x117a7(%rip), %rsi     # 0x15af3
movb $0x0, %al
callq 0x10d0
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x74, %eax
jne 0x4398
leaq 0x18fba(%rip), %rax     # 0x1d328
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %edx
leaq 0x11783(%rip), %rsi     # 0x15b01
movb $0x0, %al
callq 0x10d0
movl $0xb, %edi
leaq 0x11780(%rip), %rsi     # 0x15b11
callq 0x16c0
jmp 0x43c7
leaq 0x18f89(%rip), %rax     # 0x1d328
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %edx
leaq 0x1176c(%rip), %rsi     # 0x15b1b
movb $0x0, %al
callq 0x10d0
movl $0xb, %edi
leaq 0x11768(%rip), %rsi     # 0x15b2a
callq 0x16c0
leaq 0x18f5a(%rip), %rax     # 0x1d328
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edx
leaq 0x116f7(%rip), %rsi     # 0x15ad6
movb $0x0, %al
callq 0x10d0
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x74, %eax
jne 0x440d
movl $0xb, %edi
leaq 0x11724(%rip), %rsi     # 0x15b2a
callq 0x16c0
jmp 0x441e
movl $0xb, %edi
leaq 0x116f8(%rip), %rsi     # 0x15b11
callq 0x16c0
jmp 0x4420
movl -0x28(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)