// File: rofl0r[P]ascc/cs_parser.cpp
// Function: deal_with_end_of_switch(int*, long*, std::vector<ccChunk, std::allocator<ccChunk>>*, ccCompiledScript*, ccInternalList*, int*, long*)
int deal_with_end_of_switch (int32_t *nested_assign_addr, long *nested_start, std::vector<ccChunk> *nested_chunk, ccCompiledScript *scrip, ccInternalList *targ, int *nestlevel, long *nested_info) {
    int index;
    int limit = nested_chunk->size();
    int nested_level = nestlevel[0];
    int skip;
    int operation = is_any_type_of_string(nested_info[nested_level]) ? SCMD_STRINGSNOTEQ : SCMD_NOTEQUAL;
    if(scrip->code[scrip->codesize - 2] != SCMD_JMP || scrip->code[scrip->codesize - 1] != nested_start[nested_level] - scrip->codesize + 2) {
        // If there was no terminating break, write a jump at the end of the last case
        scrip->write_cmd1(SCMD_JMP, 0);
    }
    skip = scrip->codesize;
    // Write the location for the jump to this point (the jump table)
    scrip->code[nested_start[nested_level] + 1] = (scrip->codesize - nested_start[nested_level]) - 2;
    for(index = 0; index < limit; index++) {
        // Put the result of the expression into AX
        write_chunk(scrip, (*nested_chunk)[index]);
        // Do the comparison
        scrip->write_cmd2(operation, SREG_AX, SREG_BX);
        scrip->write_cmd1(SCMD_JZ, (*nested_chunk)[index].codeoffset - scrip->codesize - 2);
    }
    // Write the default jump if necessary
    if(nested_assign_addr[nested_level] != -1)
        scrip->write_cmd1(SCMD_JMP, nested_assign_addr[nested_level] - scrip->codesize - 2);
    // Write the location for the jump to the end of the switch block (for break statements)
    scrip->code[nested_start[nested_level] + 3] = scrip->codesize - nested_start[nested_level] - 4;
    // Write the jump for the end of the switch block
    scrip->code[skip - 1] = scrip->codesize - skip;
    clear_chunk_list(nested_chunk);
    nestlevel[0]--;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x18(%rbp), %rdi
callq 0x17eb0
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq 0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %edi
callq 0x83d0
movl %eax, %edx
movl $0x10, %eax
movl $0x42, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movl 0x20(%rcx), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
cmpl $0x1f, (%rax,%rcx,4)
jne 0x81f8
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movl 0x20(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movslq (%rax,%rcx,4), %rax
movq -0x10(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x20(%rbp), %rdx
movslq 0x20(%rdx), %rdx
subq %rdx, %rcx
addq $0x2, %rcx
cmpq %rcx, %rax
je 0x8208
movq -0x20(%rbp), %rdi
movl $0x1f, %esi
xorl %edx, %edx
callq 0x25200
movq -0x20(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movslq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
subq (%rcx,%rdx,8), %rax
subq $0x2, %rax
movl %eax, %edx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movslq -0x3c(%rbp), %rsi
movq (%rcx,%rsi,8), %rcx
movl %edx, 0x4(%rax,%rcx,4)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x8323
movq -0x20(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x17ee0
movq %rax, %rsi
leaq -0x98(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x17f00
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x6390
jmp 0x829a
leaq -0x98(%rbp), %rdi
callq 0x17da0
movq -0x20(%rbp), %rdi
movl -0x44(%rbp), %esi
movl $0x3, %edx
movl $0x4, %ecx
callq 0x25240
movq -0x20(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x17ee0
movq -0xc0(%rbp), %rdi
movl 0x48(%rax), %edx
movq -0x20(%rbp), %rax
subl 0x20(%rax), %edx
subl $0x2, %edx
movl $0x1c, %esi
callq 0x25200
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x824b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x17da0
jmp 0x83c3
movq -0x8(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpl $-0x1, (%rax,%rcx,4)
je 0x8354
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x20(%rbp), %rax
subl 0x20(%rax), %edx
subl $0x2, %edx
movl $0x1f, %esi
callq 0x25200
movq -0x20(%rbp), %rax
movslq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
subq (%rcx,%rdx,8), %rax
subq $0x4, %rax
movl %eax, %edx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movslq -0x3c(%rbp), %rsi
movq (%rcx,%rsi,8), %rcx
movl %edx, 0xc(%rax,%rcx,4)
movq -0x20(%rbp), %rax
movl 0x20(%rax), %edx
subl -0x40(%rbp), %edx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x18(%rbp), %rdi
callq 0x6480
movq -0x30(%rbp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
xorl %eax, %eax
addq $0xc0, %rsp
popq %rbp
retq
movq -0xa0(%rbp), %rdi
callq 0x4670
nop