// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9CompileSwitch
static sxi32 jx9CompileSwitch(jx9_gen_state *pGen)
{
	GenBlock *pSwitchBlock;
	SyToken *pTmp, *pEnd;
	jx9_switch *pSwitch;
	sxu32 nLine;
	sxi32 rc;
	nLine = pGen->pIn->nLine;
	/* Jump the 'switch' keyword */
	pGen->pIn++;    
	if( pGen->pIn >= pGen->pEnd || (pGen->pIn->nType & JX9_TK_LPAREN) == 0 ){
		/* Syntax error */
		rc = jx9GenCompileError(pGen, E_ERROR, nLine, "Expected '(' after 'switch' keyword");
		if( rc == SXERR_ABORT ){
			/* Error count limit reached, abort immediately */
			return SXERR_ABORT;
		}
		goto Synchronize;
	}
	/* Jump the left parenthesis '(' */
	pGen->pIn++; 
	pEnd = 0; /* cc warning */
	/* Create the loop block */
	rc = GenStateEnterBlock(&(*pGen), GEN_BLOCK_LOOP|GEN_BLOCK_SWITCH, 
		jx9VmInstrLength(pGen->pVm), 0, &pSwitchBlock);
	if( rc != SXRET_OK ){
		return SXERR_ABORT;
	}
	/* Delimit the condition */
	jx9DelimitNestedTokens(pGen->pIn, pGen->pEnd, JX9_TK_LPAREN /* '(' */, JX9_TK_RPAREN /* ')' */, &pEnd);
	if( pGen->pIn == pEnd || pEnd >= pGen->pEnd ){
		/* Empty expression */
		rc = jx9GenCompileError(pGen, E_ERROR, nLine, "Expected expression after 'switch' keyword");
		if( rc == SXERR_ABORT ){
			/* Error count limit reached, abort immediately */
			return SXERR_ABORT;
		}
	}
	/* Swap token streams */
	pTmp = pGen->pEnd;
	pGen->pEnd = pEnd;
	/* Compile the expression */
	rc = jx9CompileExpr(&(*pGen), 0, 0);
	if( rc == SXERR_ABORT ){
		/* Expression handler request an operation abort [i.e: Out-of-memory] */
		return SXERR_ABORT;
	}
	/* Update token stream */
	while(pGen->pIn < pEnd ){
		rc = jx9GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, 
			"Switch: Unexpected token '%z'", &pGen->pIn->sData);
		if( rc == SXERR_ABORT ){
			return SXERR_ABORT;
		}
		pGen->pIn++;
	}
	pGen->pIn  = &pEnd[1];
	pGen->pEnd = pTmp;
	if( pGen->pIn >= pGen->pEnd || &pGen->pIn[1] >= pGen->pEnd ||
		(pGen->pIn->nType & (JX9_TK_OCB/*'{'*/|JX9_TK_COLON/*:*/)) == 0 ){
			pTmp = pGen->pIn;
			if( pTmp >= pGen->pEnd ){
				pTmp--;
			}
			/* Unexpected token */
			rc = jx9GenCompileError(&(*pGen), E_ERROR, pTmp->nLine, "Switch: Unexpected token '%z'", &pTmp->sData);
			if( rc == SXERR_ABORT ){
				return SXERR_ABORT;
			}
			goto Synchronize;
	}
	pGen->pIn++; /* Jump the leading curly braces/colons */
	/* Create the switch blocks container */
	pSwitch = (jx9_switch *)SyMemBackendAlloc(&pGen->pVm->sAllocator, sizeof(jx9_switch));
	if( pSwitch == 0 ){
		/* Abort compilation */
		return GenStateOutOfMem(pGen);
	}
	/* Zero the structure */
	SyZero(pSwitch, sizeof(jx9_switch));
	/* Initialize fields */
	SySetInit(&pSwitch->aCaseExpr, &pGen->pVm->sAllocator, sizeof(jx9_case_expr));
	/* Emit the switch instruction */
	jx9VmEmitInstr(pGen->pVm, JX9_OP_SWITCH, 0, 0, pSwitch, 0);
	/* Compile case blocks */
	for(;;){
		sxu32 nKwrd;
		if( pGen->pIn >= pGen->pEnd ){
			/* No more input to process */
			break;
		}
		if( (pGen->pIn->nType & JX9_TK_KEYWORD) == 0 ){
			if(  (pGen->pIn->nType & JX9_TK_CCB /*}*/) == 0 ){
				/* Unexpected token */
				rc = jx9GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "Switch: Unexpected token '%z'", 
					&pGen->pIn->sData);
				if( rc == SXERR_ABORT ){
					return SXERR_ABORT;
				}
				/* FALL THROUGH */
			}
			/* Block compiled */
			break;
		}
		/* Extract the keyword */
		nKwrd = SX_PTR_TO_INT(pGen->pIn->pUserData);
		if( nKwrd == JX9_TKWRD_DEFAULT ){
			/*
			 * Accroding to the JX9 language reference manual
			 *  A special case is the default case. This case matches anything
			 *  that wasn't matched by the other cases.
			 */
			if( pSwitch->nDefault > 0 ){
				/* Default case already compiled */ 
				rc = jx9GenCompileError(&(*pGen), E_WARNING, pGen->pIn->nLine, "Switch: 'default' case already compiled");
				if( rc == SXERR_ABORT ){
					return SXERR_ABORT;
				}
			}
			pGen->pIn++; /* Jump the 'default' keyword */
			/* Compile the default block */
			rc = GenStateCompileSwitchBlock(pGen,&pSwitch->nDefault);
			if( rc == SXERR_ABORT){
				return SXERR_ABORT;
			}else if( rc == SXERR_EOF ){
				break;
			}
		}else if( nKwrd == JX9_TKWRD_CASE ){
			jx9_case_expr sCase;
			/* Standard case block */
			pGen->pIn++; /* Jump the 'case' keyword */
			/* initialize the structure */
			SySetInit(&sCase.aByteCode, &pGen->pVm->sAllocator, sizeof(VmInstr));
			/* Compile the case expression */
			rc = GenStateCompileCaseExpr(pGen, &sCase);
			if( rc == SXERR_ABORT ){
				return SXERR_ABORT;
			}
			/* Compile the case block */
			rc = GenStateCompileSwitchBlock(pGen,&sCase.nStart);
			/* Insert in the switch container */
			SySetPut(&pSwitch->aCaseExpr, (const void *)&sCase);
			if( rc == SXERR_ABORT){
				return SXERR_ABORT;
			}else if( rc == SXERR_EOF ){
				break;
			}
		}else{
			/* Unexpected token */
			rc = jx9GenCompileError(&(*pGen), E_ERROR, pGen->pIn->nLine, "Switch: Unexpected token '%z'", 
				&pGen->pIn->sData);
			if( rc == SXERR_ABORT ){
				return SXERR_ABORT;
			}
			break;
		}
	}
	/* Fix all jumps now the destination is resolved */
	pSwitch->nOut = jx9VmInstrLength(pGen->pVm);
	GenStateFixJumps(pSwitchBlock, -1, jx9VmInstrLength(pGen->pVm));
	/* Release the loop block */
	GenStateLeaveBlock(pGen, 0);
	if( pGen->pIn < pGen->pEnd ){
		/* Jump the trailing curly braces */
		pGen->pIn++;
	}
	/* Statement successfully compiled */
	return SXRET_OK;
Synchronize:
	/* Synchronize with the first semi-colon */
	while( pGen->pIn < pGen->pEnd && (pGen->pIn->nType & JX9_TK_SEMI) == 0 ){
		pGen->pIn++;
	}
	return SXRET_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x14(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jae 0x82c36
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x10(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
jne 0x82c6a
movq -0x10(%rbp), %rdi
movl -0x34(%rbp), %edx
movl $0x1, %esi
leaq 0x41354(%rip), %rcx     # 0xc3f9d
movb $0x0, %al
callq 0x7e990
movl %eax, -0x38(%rbp)
cmpl $-0xa, -0x38(%rbp)
jne 0x82c65
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x83265
jmp 0x831f9
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7e8d0
movq -0x78(%rbp), %rdi
movl %eax, %edx
movl $0x101, %esi            # imm = 0x101
xorl %eax, %eax
movl %eax, %ecx
leaq -0x18(%rbp), %r8
callq 0x84100
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x82cc9
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x83265
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x160(%rax), %rsi
movl $0x200, %edx            # imm = 0x200
movl $0x400, %ecx            # imm = 0x400
leaq -0x28(%rbp), %r8
callq 0x841b0
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
cmpq -0x28(%rbp), %rax
je 0x82d14
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jb 0x82d45
movq -0x10(%rbp), %rdi
movl -0x34(%rbp), %edx
movl $0x1, %esi
leaq 0x4129a(%rip), %rcx     # 0xc3fc1
movb $0x0, %al
callq 0x7e990
movl %eax, -0x38(%rbp)
cmpl $-0xa, -0x38(%rbp)
jne 0x82d43
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x83265
jmp 0x82d45
movq -0x10(%rbp), %rax
movq 0x160(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x160(%rax)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x81110
movl %eax, -0x38(%rbp)
cmpl $-0xa, -0x38(%rbp)
jne 0x82d87
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x83265
jmp 0x82d89
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
cmpq -0x28(%rbp), %rax
jae 0x82df7
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x14(%rax), %edx
movq -0x10(%rbp), %rax
movq 0x158(%rax), %r8
movl $0x1, %esi
leaq 0x41229(%rip), %rcx     # 0xc3fec
movb $0x0, %al
callq 0x7e990
movl %eax, -0x38(%rbp)
cmpl $-0xa, -0x38(%rbp)
jne 0x82ddf
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x83265
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
jmp 0x82d89
movq -0x28(%rbp), %rcx
addq $0x20, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x158(%rax)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x160(%rax)
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jae 0x82e65
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
addq $0x20, %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jae 0x82e65
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x10(%rax), %eax
andl $0x100040, %eax         # imm = 0x100040
cmpl $0x0, %eax
jne 0x82ecd
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jb 0x82e91
movq -0x20(%rbp), %rax
addq $-0x20, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x14(%rax), %edx
movq -0x20(%rbp), %r8
movl $0x1, %esi
leaq 0x41140(%rip), %rcx     # 0xc3fec
movb $0x0, %al
callq 0x7e990
movl %eax, -0x38(%rbp)
cmpl $-0xa, -0x38(%rbp)
jne 0x82ec8
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x83265
jmp 0x831f9
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x30, %esi
callq 0x5bf70
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x82f10
movq -0x10(%rbp), %rdi
callq 0x84570
movl %eax, -0x4(%rbp)
jmp 0x83265
movq -0x30(%rbp), %rdi
movl $0x30, %esi
callq 0x54280
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movl $0x30, %edx
callq 0x5b470
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %r8
movl $0x45, %esi
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %r9d
movl %ecx, %edx
callq 0x7e8f0
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jb 0x82f6e
jmp 0x8317c
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x10(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x82fe8
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x10(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x82fe3
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x14(%rax), %edx
movq -0x10(%rbp), %rax
movq 0x158(%rax), %r8
movl $0x1, %esi
leaq 0x41027(%rip), %rcx     # 0xc3fec
movb $0x0, %al
callq 0x7e990
movl %eax, -0x38(%rbp)
cmpl $-0xa, -0x38(%rbp)
jne 0x82fe1
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x83265
jmp 0x82fe3
jmp 0x8317c
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movq 0x18(%rax), %rax
movl %eax, -0x3c(%rbp)
cmpl $0xa, -0x3c(%rbp)
jne 0x83098
movq -0x30(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jbe 0x8304a
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x14(%rax), %edx
movl $0x2, %esi
leaq 0x40fde(%rip), %rcx     # 0xc400a
movb $0x0, %al
callq 0x7e990
movl %eax, -0x38(%rbp)
cmpl $-0xa, -0x38(%rbp)
jne 0x83048
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x83265
jmp 0x8304a
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x2c, %rsi
callq 0x85330
movl %eax, -0x38(%rbp)
cmpl $-0xa, -0x38(%rbp)
jne 0x83086
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x83265
cmpl $-0x12, -0x38(%rbp)
jne 0x83091
jmp 0x8317c
jmp 0x83093
jmp 0x83177
cmpl $0x5, -0x3c(%rbp)
jne 0x8312e
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
leaq -0x70(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movl $0x18, %edx
callq 0x5b470
movq -0x10(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x854d0
movl %eax, -0x38(%rbp)
cmpl $-0xa, -0x38(%rbp)
jne 0x830ef
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x83265
movq -0x10(%rbp), %rdi
leaq -0x70(%rbp), %rsi
addq $0x28, %rsi
callq 0x85330
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x5a7b0
cmpl $-0xa, -0x38(%rbp)
jne 0x83122
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x83265
cmpl $-0x12, -0x38(%rbp)
jne 0x8312a
jmp 0x8317c
jmp 0x8312c
jmp 0x83175
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x14(%rax), %edx
movq -0x10(%rbp), %rax
movq 0x158(%rax), %r8
movl $0x1, %esi
leaq 0x40e95(%rip), %rcx     # 0xc3fec
movb $0x0, %al
callq 0x7e990
movl %eax, -0x38(%rbp)
cmpl $-0xa, -0x38(%rbp)
jne 0x83173
movl $0xfffffff6, -0x4(%rbp) # imm = 0xFFFFFFF6
jmp 0x83265
jmp 0x8317c
jmp 0x83177
jmp 0x82f51
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7e8d0
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x7e8d0
movq -0x80(%rbp), %rdi
movl %eax, %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x84440
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x84500
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x160(%rcx), %rax
jae 0x831f0
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x83265
jmp 0x831fb
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
movq -0x10(%rbp), %rdx
xorl %eax, %eax
cmpq 0x160(%rdx), %rcx
movb %al, -0x81(%rbp)
jae 0x8323a
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rax
movl 0x10(%rax), %eax
andl $0x40000, %eax          # imm = 0x40000
cmpl $0x0, %eax
sete %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x83246
jmp 0x8325e
movq -0x10(%rbp), %rax
movq 0x158(%rax), %rcx
addq $0x20, %rcx
movq %rcx, 0x158(%rax)
jmp 0x831fb
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)