// File: rofl0r[P]ascc/cs_parser.cpp
// Function: deal_with_end_of_ifelse(char*, long*, long*, ccCompiledScript*, ccInternalList*, int*, std::vector<ccChunk, std::allocator<ccChunk>>*)
int deal_with_end_of_ifelse (char*nested_type,long*nested_info,long*nested_start,
                             ccCompiledScript*scrip,ccInternalList*targ,int*nestlevel, std::vector<ccChunk> *nested_chunk) {
     int nested_level = nestlevel[0];
     int is_else=0;
     if (nested_type[nested_level] == NEST_ELSESINGLE) ;
     else if (nested_type[nested_level] == NEST_ELSE) ;
     else if (sym.get_type(targ->peeknext()) == SYM_ELSE) {
         targ->getnext();
         scrip->write_cmd1(SCMD_JMP,0);
         is_else=1;
     }
     if (nested_start[nested_level]) {
         scrip->flush_line_numbers();
         // if it's a for loop, drop the yanked chunk (loop increment) back in
         if(nested_chunk[nested_level].size() > 0) {
             write_chunk(scrip, nested_chunk[nested_level][0]);
             clear_chunk_list(&nested_chunk[nested_level]);
         }
         // it's a while loop, so write a jump back to the check again
        scrip->write_cmd1(SCMD_JMP,-((scrip->codesize+2) - nested_start[nested_level]) );
     }
     // write the correct relative jump location
     scrip->code[nested_info[nested_level]] =
         (scrip->codesize - nested_info[nested_level]) - 1;
     if (is_else) {
         // convert the IF into an ELSE
         if (sym.get_type(targ->peeknext()) == SYM_OPENBRACE) {
             nested_type[nested_level] = NEST_ELSE;
             targ->getnext();
         }
         else
             nested_type[nested_level] = NEST_ELSESINGLE;
         nested_info[nested_level] = scrip->codesize-1;
         return 1;
     }
     else
     {
         nestlevel[0]--;
         if(nested_type[nestlevel[0]] == NEST_FOR)
         {
             nestlevel[0]--;
             // find local variables that have just been removed
             int totalsub = remove_locals (nestlevel[0], 0, scrip);

             if (totalsub > 0) {
                 scrip->cur_sp -= totalsub;
                 scrip->write_cmd2(SCMD_SUB,SREG_SP,totalsub);
             }
         }
     }
     return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x6, %eax
jne 0x78ea
jmp 0x793d
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5, %eax
jne 0x78fd
jmp 0x793b
movq -0x30(%rbp), %rdi
callq 0x1dd60
movl %eax, %esi
leaq 0x3af61(%rip), %rdi     # 0x42870
callq 0x1e1e0
cmpl $0x1d, %eax
jne 0x7939
movq -0x30(%rbp), %rdi
callq 0x1de00
movq -0x28(%rbp), %rdi
movl $0x1f, %esi
xorl %edx, %edx
callq 0x25200
movl $0x1, -0x40(%rbp)
jmp 0x793b
jmp 0x793d
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x7a39
movq -0x28(%rbp), %rdi
callq 0x25fb0
movq 0x10(%rbp), %rdi
movslq -0x3c(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x17eb0
cmpq $0x0, %rax
jbe 0x7a0b
movq -0x28(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq 0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x17ee0
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x17f00
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0x6390
jmp 0x79c6
leaq -0x90(%rbp), %rdi
callq 0x17da0
movq 0x10(%rbp), %rdi
movslq -0x3c(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x6480
jmp 0x7a0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x17da0
jmp 0x7b6a
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
addl $0x2, %eax
movslq %eax, %rcx
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rdx
subq (%rax,%rdx,8), %rcx
xorl %eax, %eax
subq %rcx, %rax
movl %eax, %edx
movl $0x1f, %esi
callq 0x25200
movq -0x28(%rbp), %rax
movslq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
subq (%rcx,%rdx,8), %rax
subq $0x1, %rax
movl %eax, %edx
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movslq -0x3c(%rbp), %rsi
movq (%rcx,%rsi,8), %rcx
movl %edx, (%rax,%rcx,4)
cmpl $0x0, -0x40(%rbp)
je 0x7ad4
movq -0x30(%rbp), %rdi
callq 0x1dd60
movl %eax, %esi
leaq 0x3adee(%rip), %rdi     # 0x42870
callq 0x1e1e0
cmpl $0x17, %eax
jne 0x7aa3
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb $0x5, (%rax,%rcx)
movq -0x30(%rbp), %rdi
callq 0x1de00
jmp 0x7aaf
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb $0x6, (%rax,%rcx)
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
subl $0x1, %eax
movslq %eax, %rdx
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x1, -0x4(%rbp)
jmp 0x7b5e
movq -0x38(%rbp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq (%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x7b55
movq -0x38(%rbp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movl (%rax), %edi
movq -0x28(%rbp), %rdx
xorl %esi, %esi
callq 0x7550
movl %eax, -0xa0(%rbp)
cmpl $0x0, -0xa0(%rbp)
jle 0x7b53
movslq -0xa0(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x8d40(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x8d40(%rax)
movq -0x28(%rbp), %rdi
movl -0xa0(%rbp), %ecx
movl $0x2, %esi
movl $0x1, %edx
callq 0x25240
jmp 0x7b55
jmp 0x7b57
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
movq -0x98(%rbp), %rdi
callq 0x4670
nopw %cs:(%rax,%rax)