// File: /workspace/github_cpp_makefile_star2_O2/AutomataLab[P]JSONSki/src/QueryProcessor.cpp
// Function: QueryProcessor::goToObjEnd(long&, bitmap&)
__attribute__((always_inline)) void QueryProcessor::goToObjEnd(long& pos, bitmap& bm) {
    int num_open = 1;
    int num_close = 0;
    long word_id = pos / 64;
    bool first_interval = false;
    bool new_word = false;
    while (true) {
        while (word_id < mNumWords) {
            if (word_id > top_word) {
                resetBitmap(bm);
                start_id = word_id * 2;
                build_bitmap_basic();
            } 
            get_bitmap_lbrace(bm);
            IntervalInfo interval;
            if (first_interval == false) {
                if (new_word == true) {
                    interval = get_interval_new_word(bm.lbracebit);
                } else {
                    interval = get_interval(pos, bm.lbracebit);
                }
                first_interval = true;
            } else {
                interval = next_interval(bm.lbracebit);
            }
            get_bitmap_rbrace(bm);
            unsigned long bitmap_rbrace = bm.rbracebit & interval.intervalbit;
            num_close = __builtin_popcountl(bitmap_rbrace);
            if (num_close < num_open) {
                if (interval.is_complete == true) {
                    num_open = num_open - num_close + 1;
                    break;
                } else {
                    num_open = num_open - num_close;
                }
            } else {  // results found
                pos = get_position(bitmap_rbrace, num_open);
                return;
            }
            // interval is incomplete in the current word
            ++word_id;
            first_interval = false;
            new_word = true;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %r8
movq %rsi, -0x10(%rsp)
movq (%rsi), %rax
movabsq $0x40, %rcx
cqto
idivq %rcx
movq %rax, %r9
leaq 0x30(%r8), %rax
movq %rax, -0x8(%rsp)
movl $0x1, %ebx
xorl %ebp, %ebp
vpcmpeqd %xmm0, %xmm0, %xmm0
xorl %eax, %eax
movq 0x2c8(%rdi), %rcx
movq %r9, %rdx
shlq $0x6, %rdx
leaq (%rcx,%rdx), %r12
addq $0x20, %r12
leaq (%r9,%r9), %r13
cmpq 0x2e0(%rdi), %r9
jge 0x17559
cmpq 0x270(%rdi), %r9
jle 0x1768d
movq -0x8(%rsp), %rcx
andw $0x0, 0x4(%rcx)
andl $0x0, (%rcx)
movq %r13, 0x88(%rdi)
movq %r9, 0x270(%rdi)
vmovdqu -0x20(%r12), %ymm1
vmovdqa %ymm1, 0xa0(%rdi)
vmovdqa 0x140(%rdi), %ymm2
vmovdqa 0x180(%rdi), %ymm3
vpcmpeqb %ymm1, %ymm2, %ymm4
vpmovmskb %ymm4, %r10d
vpcmpeqb %ymm1, %ymm3, %ymm1
vpmovmskb %ymm1, %r15d
leaq 0x1(%r13), %rcx
movq %rcx, 0x88(%rdi)
vmovdqu (%r12), %ymm1
vmovdqa %ymm1, 0xc0(%rdi)
vpcmpeqb %ymm1, %ymm2, %ymm2
vpmovmskb %ymm2, %ecx
vpcmpeqb %ymm1, %ymm3, %ymm1
vpmovmskb %ymm1, %edx
shlq $0x20, %rcx
orq %r10, %rcx
shlq $0x20, %rdx
orq %r15, %rdx
leaq (%rdx,%rdx), %r10
notq %r10
andq %rdx, %r10
movq 0x250(%rdi), %r11
movq 0x240(%rdi), %r14
movq %r14, %r15
xorq %r11, %r15
movq %r10, %rsi
andq %r15, %rsi
notq %r15
andq %r10, %r15
addq %rdx, %rsi
xorl %r10d, %r10d
addq %rdx, %r15
setb %r10b
movq %r10, 0x240(%rdi)
andq 0x258(%rdi), %rsi
orq %r14, %r15
andq %r11, %r15
orq %rsi, %r15
notq %r15
orq %rdx, %r15
andq %rcx, %r15
movq %r15, 0xe0(%rdi)
vmovq %r15, %xmm1
vpclmulqdq $0x0, %xmm0, %xmm1, %xmm1
vmovq %xmm1, %rcx
xorq 0x248(%rdi), %rcx
movq %rcx, (%rdi)
sarq $0x3f, %rcx
movq %rcx, 0x248(%rdi)
cmpb $0x0, 0x32(%r8)
jne 0x176cd
vmovdqa 0x1a0(%rdi), %ymm1
vpcmpeqb 0xa0(%rdi), %ymm1, %ymm2
vpmovmskb %ymm2, %ecx
vpcmpeqb 0xc0(%rdi), %ymm1, %ymm1
vpmovmskb %ymm1, %edx
shlq $0x20, %rdx
orq %rcx, %rdx
movq (%rdi), %rcx
notq %rcx
andq %rdx, %rcx
movq %rcx, 0x10(%r8)
movb $0x1, 0x32(%r8)
testb $0x1, %al
jne 0x176f3
testb $0x1, %bpl
je 0x17723
movq 0x10(%r8), %rax
movq %rax, %rsi
negq %rsi
setb %cl
andq %rax, %rsi
leaq -0x1(%rsi), %rdx
orq %rsi, %rdx
jmp 0x1779f
movq 0x10(%r8), %rdx
movq %rdx, %r15
negq %r15
andq %rdx, %r15
leaq -0x1(%rdx), %rcx
andq %rdx, %rcx
movq %rcx, 0x10(%r8)
je 0x17778
movq %rcx, %rsi
negq %rsi
andq %rcx, %rsi
movq %rsi, %rdx
subq %r15, %rdx
orq %rsi, %rdx
movb $0x1, %cl
jmp 0x177a1
movq -0x10(%rsp), %rax
movq (%rax), %rax
cqto
movabsq $0x40, %rcx
idivq %rcx
movq %rdx, %rcx
movabsq $0x1, %r15
shlq %cl, %r15
movq %r15, %rdx
negq %rdx
movq %rdx, %rax
btcq %rcx, %rax
movq 0x10(%r8), %r10
andq %rax, %r10
movq %r10, 0x10(%r8)
setne %cl
je 0x1778f
movq %r10, %rsi
negq %rsi
andq %r10, %rsi
movq %rsi, %rdx
subq %r15, %rdx
jmp 0x17799
negq %r15
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
orq %rcx, %r15
xorl %ecx, %ecx
movq %r15, %rdx
jmp 0x177a1
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
orq %rsi, %rdx
andq %rax, %rdx
movb $0x1, %al
cmpb $0x0, 0x33(%r8)
je 0x177ae
movq 0x18(%r8), %r15
jmp 0x177e7
vmovdqa 0x1c0(%rdi), %ymm1
vpcmpeqb 0xa0(%rdi), %ymm1, %ymm2
vpmovmskb %ymm2, %esi
vpcmpeqb 0xc0(%rdi), %ymm1, %ymm1
vpmovmskb %ymm1, %r10d
shlq $0x20, %r10
orq %rsi, %r10
movq (%rdi), %r15
notq %r15
andq %r10, %r15
movq %r15, 0x18(%r8)
movb $0x1, 0x33(%r8)
andq %rdx, %r15
popcntq %r15, %r10
movl %ebx, %edx
subl %r10d, %edx
jle 0x17824
testb %cl, %cl
jne 0x17811
incq %r9
addq $0x40, %r12
addq $0x2, %r13
movb $0x1, %bpl
xorl %eax, %eax
movl %edx, %ebx
jmp 0x17573
subl %r10d, %ebx
incl %ebx
jmp 0x17559
leaq -0x1(%r15), %rax
andq %rax, %r15
decl %ebx
cmpl $0x2, %ebx
jge 0x1781b
movq 0x270(%rdi), %rax
shlq $0x6, %rax
bsfq %r15, %rcx
orq %rax, %rcx
movq -0x10(%rsp), %rax
movq %rcx, (%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq
nop