// File: AutomataLab[P]JSONSki/src/QueryProcessor.cpp
// Function: QueryProcessor::build_bitmap_basic()
__attribute__((always_inline)) void QueryProcessor::build_bitmap_basic() {
    unsigned long quotebit0, escapebit0;
    unsigned long quotebit, escapebit;
    // step 1: build structural quote and escape bitmaps for the current word
    // first half of bitmap
    top_word = start_id / 2; // word id 
    unsigned long i = start_id * 32;
    v_text0 = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(mRecord + i));
    quotebit0 = (unsigned)_mm256_movemask_epi8(_mm256_cmpeq_epi8(v_text0, v_quote));
    escapebit0 = (unsigned)_mm256_movemask_epi8(_mm256_cmpeq_epi8(v_text0, v_escape));
    // second half of bitmap 
    ++start_id;
    i = (start_id) * 32;
    v_text = _mm256_loadu_si256(reinterpret_cast<const __m256i *>(mRecord + i));
    quotebit = (unsigned)_mm256_movemask_epi8(_mm256_cmpeq_epi8(v_text, v_quote));
    escapebit = (unsigned)_mm256_movemask_epi8(_mm256_cmpeq_epi8(v_text, v_escape));
    quotebit = (quotebit << 32) | quotebit0;
    escapebit = (escapebit << 32) | escapebit0;
    // step 2: update structural quote bitmaps
    uint64_t bs_bits = escapebit;
    uint64_t start_edges = bs_bits & ~(bs_bits << 1);
    int64_t even_start_mask = even_bits ^ prev_iter_ends_odd_backslash;
    uint64_t even_starts = start_edges & even_start_mask;
    uint64_t odd_starts = start_edges & ~even_start_mask;
    uint64_t even_carries = bs_bits + even_starts;
    int64_t odd_carries;
    bool iter_ends_odd_backslash = __builtin_uaddll_overflow(bs_bits, odd_starts,
        (unsigned long long *)(&odd_carries));
    odd_carries |= prev_iter_ends_odd_backslash;
    prev_iter_ends_odd_backslash = iter_ends_odd_backslash ? 0x1ULL : 0x0ULL;
    uint64_t even_carry_ends = even_carries & ~bs_bits;
    uint64_t odd_carry_ends = odd_carries & ~bs_bits;
    uint64_t even_start_odd_end = even_carry_ends & odd_bits;
    uint64_t odd_start_even_end = odd_carry_ends & even_bits;
    uint64_t odd_ends = even_start_odd_end | odd_start_even_end;
    quote_bits = quotebit & ~odd_ends;
     // step 3: build string mask bitmaps
    str_mask = _mm_cvtsi128_si64(_mm_clmulepi64_si128(
        _mm_set_epi64x(0ULL, quote_bits), _mm_set1_epi8(0xFFu), 0));
    str_mask ^= prev_iter_inside_quote;
    prev_iter_inside_quote = static_cast<uint64_t>(static_cast<int64_t>(str_mask) >> 63);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
andq $-0x20, %rsp
subq $0x2c0, %rsp            # imm = 0x2C0
movq %rdi, 0xa8(%rsp)
movq 0xa8(%rsp), %rax
movq 0x88(%rax), %rcx
movq %rcx, %rdx
shrq $0x3f, %rdx
addq %rdx, %rcx
sarq %rcx
movq %rcx, 0x270(%rax)
movq 0x88(%rax), %rcx
shlq $0x5, %rcx
movq %rcx, 0x80(%rsp)
movq 0x2c8(%rax), %rcx
movq 0x80(%rsp), %rdx
addq %rdx, %rcx
movq %rcx, 0xb8(%rsp)
movq 0xb8(%rsp), %rcx
vmovups (%rcx), %ymm0
vmovaps %ymm0, 0xa0(%rax)
vmovaps 0xa0(%rax), %ymm1
vmovaps 0x140(%rax), %ymm0
vmovaps %ymm1, 0x220(%rsp)
vmovaps %ymm0, 0x200(%rsp)
vmovaps 0x220(%rsp), %ymm0
vmovaps 0x200(%rsp), %ymm1
vpcmpeqb %ymm1, %ymm0, %ymm0
vmovaps %ymm0, 0x120(%rsp)
vmovaps 0x120(%rsp), %ymm0
vpmovmskb %ymm0, %ecx
movq %rcx, 0xa0(%rsp)
vmovaps 0xa0(%rax), %ymm1
vmovaps 0x180(%rax), %ymm0
vmovaps %ymm1, 0x1e0(%rsp)
vmovaps %ymm0, 0x1c0(%rsp)
vmovaps 0x1e0(%rsp), %ymm0
vmovaps 0x1c0(%rsp), %ymm1
vpcmpeqb %ymm1, %ymm0, %ymm0
vmovaps %ymm0, 0x100(%rsp)
vmovaps 0x100(%rsp), %ymm0
vpmovmskb %ymm0, %ecx
movq %rcx, 0x98(%rsp)
movq 0x88(%rax), %rcx
incq %rcx
movq %rcx, 0x88(%rax)
movq 0x88(%rax), %rcx
shlq $0x5, %rcx
movq %rcx, 0x80(%rsp)
movq 0x2c8(%rax), %rcx
movq 0x80(%rsp), %rdx
addq %rdx, %rcx
movq %rcx, 0xb0(%rsp)
movq 0xb0(%rsp), %rcx
vmovups (%rcx), %ymm0
vmovaps %ymm0, 0xc0(%rax)
vmovaps 0xc0(%rax), %ymm1
vmovaps 0x140(%rax), %ymm0
vmovaps %ymm1, 0x1a0(%rsp)
vmovaps %ymm0, 0x180(%rsp)
vmovaps 0x1a0(%rsp), %ymm0
vmovaps 0x180(%rsp), %ymm1
vpcmpeqb %ymm1, %ymm0, %ymm0
vmovaps %ymm0, 0xe0(%rsp)
vmovaps 0xe0(%rsp), %ymm0
vpmovmskb %ymm0, %ecx
movq %rcx, 0x90(%rsp)
vmovaps 0xc0(%rax), %ymm1
vmovaps 0x180(%rax), %ymm0
vmovaps %ymm1, 0x160(%rsp)
vmovaps %ymm0, 0x140(%rsp)
vmovaps 0x160(%rsp), %ymm0
vmovaps 0x140(%rsp), %ymm1
vpcmpeqb %ymm1, %ymm0, %ymm0
vmovaps %ymm0, 0xc0(%rsp)
vmovaps 0xc0(%rsp), %ymm0
vpmovmskb %ymm0, %ecx
movq %rcx, 0x88(%rsp)
movq 0x90(%rsp), %rcx
shlq $0x20, %rcx
movq 0xa0(%rsp), %rdx
orq %rdx, %rcx
movq %rcx, 0x90(%rsp)
movq 0x88(%rsp), %rcx
shlq $0x20, %rcx
movq 0x98(%rsp), %rdx
orq %rdx, %rcx
movq %rcx, 0x88(%rsp)
movq 0x88(%rsp), %rcx
movq %rcx, 0x78(%rsp)
movq 0x78(%rsp), %rcx
movq %rcx, %rdx
addq %rdx, %rdx
notq %rdx
andq %rdx, %rcx
movq %rcx, 0x70(%rsp)
movq 0x240(%rax), %rdx
movq 0x250(%rax), %rcx
xorq %rdx, %rcx
movq %rcx, 0x68(%rsp)
movq 0x70(%rsp), %rcx
movq 0x68(%rsp), %rdx
andq %rdx, %rcx
movq %rcx, 0x60(%rsp)
movq 0x70(%rsp), %rcx
movq 0x68(%rsp), %rdx
notq %rdx
andq %rdx, %rcx
movq %rcx, 0x58(%rsp)
movq 0x78(%rsp), %rcx
movq 0x60(%rsp), %rdx
addq %rdx, %rcx
movq %rcx, 0x50(%rsp)
movq 0x78(%rsp), %rcx
movq 0x58(%rsp), %rdx
addq %rdx, %rcx
movq %rcx, 0x48(%rsp)
setb 0x47(%rsp)
movq 0x240(%rax), %rdx
movq 0x48(%rsp), %rcx
orq %rdx, %rcx
movq %rcx, 0x48(%rsp)
movzbl 0x47(%rsp), %ecx
andl $0x1, %ecx
movq %rcx, 0x240(%rax)
movq 0x50(%rsp), %rcx
movq 0x78(%rsp), %rdx
notq %rdx
andq %rdx, %rcx
movq %rcx, 0x38(%rsp)
movq 0x48(%rsp), %rcx
movq 0x78(%rsp), %rdx
notq %rdx
andq %rdx, %rcx
movq %rcx, 0x30(%rsp)
movq 0x38(%rsp), %rcx
movq 0x258(%rax), %rdx
andq %rdx, %rcx
movq %rcx, 0x28(%rsp)
movq 0x30(%rsp), %rcx
movq 0x250(%rax), %rdx
andq %rdx, %rcx
movq %rcx, 0x20(%rsp)
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rdx
orq %rdx, %rcx
movq %rcx, 0x18(%rsp)
movq 0x90(%rsp), %rcx
movq 0x18(%rsp), %rdx
notq %rdx
andq %rdx, %rcx
movq %rcx, 0xe0(%rax)
movq 0xe0(%rax), %rcx
movq $0x0, 0x280(%rsp)
movq %rcx, 0x278(%rsp)
vmovq 0x280(%rsp), %xmm1
vmovq 0x278(%rsp), %xmm0
vpunpcklqdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0]
vmovdqa %xmm0, 0x260(%rsp)
vmovdqa 0x260(%rsp), %xmm0
movb $-0x1, 0x28f(%rsp)
movb 0x28f(%rsp), %cl
movb %cl, 0x2af(%rsp)
movb %cl, 0x2ae(%rsp)
movb %cl, 0x2ad(%rsp)
movb %cl, 0x2ac(%rsp)
movb %cl, 0x2ab(%rsp)
movb %cl, 0x2aa(%rsp)
movb %cl, 0x2a9(%rsp)
movb %cl, 0x2a8(%rsp)
movb %cl, 0x2a7(%rsp)
movb %cl, 0x2a6(%rsp)
movb %cl, 0x2a5(%rsp)
movb %cl, 0x2a4(%rsp)
movb %cl, 0x2a3(%rsp)
movb %cl, 0x2a2(%rsp)
movb %cl, 0x2a1(%rsp)
movb %cl, 0x2a0(%rsp)
movzbl 0x2a0(%rsp), %ecx
vmovd %ecx, %xmm1
movzbl 0x2a1(%rsp), %ecx
vpinsrb $0x1, %ecx, %xmm1, %xmm1
movzbl 0x2a2(%rsp), %ecx
vpinsrb $0x2, %ecx, %xmm1, %xmm1
movzbl 0x2a3(%rsp), %ecx
vpinsrb $0x3, %ecx, %xmm1, %xmm1
movzbl 0x2a4(%rsp), %ecx
vpinsrb $0x4, %ecx, %xmm1, %xmm1
movzbl 0x2a5(%rsp), %ecx
vpinsrb $0x5, %ecx, %xmm1, %xmm1
movzbl 0x2a6(%rsp), %ecx
vpinsrb $0x6, %ecx, %xmm1, %xmm1
movzbl 0x2a7(%rsp), %ecx
vpinsrb $0x7, %ecx, %xmm1, %xmm1
movzbl 0x2a8(%rsp), %ecx
vpinsrb $0x8, %ecx, %xmm1, %xmm1
movzbl 0x2a9(%rsp), %ecx
vpinsrb $0x9, %ecx, %xmm1, %xmm1
movzbl 0x2aa(%rsp), %ecx
vpinsrb $0xa, %ecx, %xmm1, %xmm1
movzbl 0x2ab(%rsp), %ecx
vpinsrb $0xb, %ecx, %xmm1, %xmm1
movzbl 0x2ac(%rsp), %ecx
vpinsrb $0xc, %ecx, %xmm1, %xmm1
movzbl 0x2ad(%rsp), %ecx
vpinsrb $0xd, %ecx, %xmm1, %xmm1
movzbl 0x2ae(%rsp), %ecx
vpinsrb $0xe, %ecx, %xmm1, %xmm1
movzbl 0x2af(%rsp), %ecx
vpinsrb $0xf, %ecx, %xmm1, %xmm1
vmovdqa %xmm1, 0x290(%rsp)
vmovdqa 0x290(%rsp), %xmm1
vpclmulqdq $0x0, %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0x250(%rsp)
movq 0x250(%rsp), %rcx
movq %rcx, (%rax)
movq 0x248(%rax), %rcx
xorq (%rax), %rcx
movq %rcx, (%rax)
movq (%rax), %rcx
sarq $0x3f, %rcx
movq %rcx, 0x248(%rax)
movq %rbp, %rsp
popq %rbp
vzeroupper
retq
nopl (%rax)