// File: /workspace/github_cpp_makefile_star2_O1/moyix[P]pandalog_taint_parser/label_instr.cpp
// Function: process_chunks(void*)
void *process_chunks(void *args) {
    arg *a = (arg *)args;
    unsigned long chunk_size = hdr->chunk_size;
    uint8_t *outbuf = (uint8_t *) malloc(chunk_size);

    for (unsigned int i = a->start; i < a->start+a->size; i++) {
        PlChunk *chunk = &chunks[i];
        unsigned long uncompressed_size = 
            decompress_chunk(&outbuf, plog+chunk->start, &chunk_size);
        int j = 0;
        while (j < uncompressed_size) {
            panda::LogEntry le;
            uint32_t entry_size = *(uint32_t *)(outbuf+j);
            j += 4;
            assert(le.ParseFromString(std::string((const char *)(outbuf+j), entry_size)));
            //if (i > 0) std::cout << le.DebugString() << std::endl;
            assert(le.instr() >= dir->entries[i].instr);
            if (le.has_tainted_instr()) {
                for (auto tq : le.tainted_instr().taint_query()) {
                    //printf("(%zu, %zu, %zu) %zu %u\n", dir->entries[i].instr, dir->entries[i].start, dir->entries[i].num_entries, le.instr(), tq.tcn());
                    if (tq.has_unique_label_set()) {
                        auto uls = tq.unique_label_set();
                        pthread_mutex_lock(&maplock);
                        std::copy(
                            uls.label().begin(),
                            uls.label().end(),
                            std::back_inserter(ptr_to_label[uls.ptr()])
                        );
                        pthread_mutex_unlock(&maplock);
                    }
                    // Can we get rid of this lock in favor of an atomic?
                    pthread_mutex_lock(&tcn_insert_lock);
                    int index = ((le.instr()-first_instr)/((double)(num_instr-first_instr)))*buckets;
                    assert(le.instr() < num_instr);
                    assert(index < buckets);
                    bucket_to_ptr[index].insert(tq.ptr());
                    pthread_mutex_unlock(&tcn_insert_lock);

                }
            }
            j += entry_size;
        }
        processed++;
    }
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %rdi, %rbx
movq 0x1d467(%rip), %rax     # 0x24610
movl 0x10(%rax), %edi
movq %rdi, 0x98(%rsp)
callq 0x6420
movq %rax, 0x28(%rsp)
movl (%rbx), %edx
movq %rbx, 0x68(%rsp)
movl 0x4(%rbx), %eax
addl %edx, %eax
cmpl %eax, %edx
jae 0x75a9
leaq 0x40(%rsp), %r14
leaq 0xd0(%rsp), %r15
leaq 0x30(%rsp), %r13
leaq 0x1d435(%rip), %rbp     # 0x24620
movq 0x1d416(%rip), %rax     # 0x24608
movq %rdx, %rcx
movq %rdx, 0x10(%rsp)
shlq $0x4, %rcx
movq 0x1d3fb(%rip), %rsi     # 0x24600
addq (%rax,%rcx), %rsi
leaq 0x28(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0x711c
movq %rax, 0x80(%rsp)
testq %rax, %rax
je 0x7587
xorl %ebx, %ebx
movq 0x28(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x10(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x70(%rsp)
xorl %eax, %eax
movq %r15, %rdi
xorl %esi, %esi
movl %eax, %r12d
callq 0x1348e
movq 0x78(%rsp), %rcx
movl (%rcx,%rbx), %ebx
movl %r12d, 0xc(%rsp)
movslq %r12d, %rax
leaq (%rax,%rcx), %rsi
addq $0x4, %rsi
addq %rcx, %rax
movq %r14, 0x30(%rsp)
leaq (%rbx,%rax), %rdx
addq $0x4, %rdx
movq %r13, %rdi
callq 0x7dd6
movq %r15, %rdi
movq %r13, %rsi
callq 0x6610
testb %al, %al
je 0x761a
movq 0x30(%rsp), %rdi
cmpq %r14, %rdi
je 0x72af
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x6370
movq 0x158(%rsp), %rax
movq 0x1d35a(%rip), %rcx     # 0x24618
movq 0x70(%rsp), %rdx
cmpq 0x4(%rcx,%rdx,8), %rax
leaq 0xa0(%rsp), %r14
jb 0x75fb
movq %rbx, 0x88(%rsp)
movl 0xe0(%rsp), %ebx
testb $0x8, %bl
je 0x7330
cmpq $0x0, 0x100(%rsp)
jne 0x7330
movq %r13, %rdi
movl $0x3, %esi
leaq 0x11eb1(%rip), %rdx     # 0x191b5
movl $0x1bd2, %ecx           # imm = 0x1BD2
callq 0x6550
movq %r13, %rdi
leaq 0x11ea9(%rip), %rsi     # 0x191c1
callq 0x65a0
movq %r14, %rdi
movq %rax, %rsi
callq 0x6460
movq %r13, %rdi
callq 0x65c0
testb $0x8, %bl
je 0x7551
movq 0x100(%rsp), %rax
testq %rax, %rax
jne 0x734d
leaq 0x1d64b(%rip), %rax     # 0x24998
movq 0x28(%rax), %rcx
leaq 0x8(%rcx), %rdx
testq %rcx, %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x90(%rsp)
movslq 0x20(%rax), %rax
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x7551
shlq $0x3, 0x18(%rsp)
xorl %r15d, %r15d
movq 0x90(%rsp), %rax
movq (%rax,%r15), %rsi
movq %r14, %rdi
callq 0xe406
movq %r13, %rbx
movq %rbp, %r12
movl 0xb0(%rsp), %ebp
testb $0x1, %bpl
je 0x73f1
cmpq $0x0, 0xb8(%rsp)
jne 0x73f1
movq %rbx, %r13
movq %rbx, %rdi
movl $0x3, %esi
leaq 0x11df2(%rip), %rdx     # 0x191b5
movl $0x1394, %ecx           # imm = 0x1394
callq 0x6550
movq %r13, %rdi
leaq 0x11e1e(%rip), %rsi     # 0x191f5
callq 0x65a0
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x6460
movq %rbx, %rdi
callq 0x65c0
testb $0x1, %bpl
je 0x7476
movq 0xb8(%rsp), %rsi
testq %rsi, %rsi
jne 0x740b
leaq 0x1d40d(%rip), %rsi     # 0x24818
movq %rbx, %rdi
callq 0xd112
leaq 0x1d276(%rip), %rdi     # 0x24690
callq 0x64c0
movq 0x50(%rsp), %rbp
movq 0x58(%rsp), %rax
movslq 0x48(%rsp), %r14
movq %rax, 0x20(%rsp)
leaq 0x1d226(%rip), %rdi     # 0x24660
leaq 0x20(%rsp), %rsi
callq 0x7bba
leaq (,%r14,4), %rsi
addq %rbp, %rsi
movq %rbp, %rdi
movq %rax, %rdx
callq 0x80ce
leaq 0x1d22f(%rip), %rdi     # 0x24690
callq 0x6240
movq %rbx, %rdi
callq 0xd188
leaq 0xa0(%rsp), %r14
movq %r12, %rbp
movq %r12, %rdi
callq 0x64c0
movq 0x158(%rsp), %rcx
movq 0x1d238(%rip), %rax     # 0x246c8
cmpq %rax, %rcx
jae 0x75dc
movq 0x1d230(%rip), %rdx     # 0x246d0
subq %rdx, %rcx
movq %rcx, %xmm0
movq 0x11b60(%rip), %xmm2    # 0x19010
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x11b64(%rip), %xmm3    # 0x19020
subpd %xmm3, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
subq %rdx, %rax
movq %rax, %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm3, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
divsd %xmm2, %xmm1
movl 0x1d1ce(%rip), %ecx     # 0x246c0
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
cmpl %eax, %ecx
jle 0x75bd
cltq
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
addq 0x1d12e(%rip), %rdi     # 0x24648
movq 0xc0(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %rbx, %r13
movq %rbx, %rsi
callq 0x8274
movq %rbp, %rdi
callq 0x6240
movq %r14, %rdi
callq 0xe512
addq $0x8, %r15
cmpq %r15, 0x18(%rsp)
jne 0x737f
movl 0xc(%rsp), %ebx
addl $0x4, %ebx
addl 0x88(%rsp), %ebx
leaq 0xd0(%rsp), %r15
movq %r15, %rdi
callq 0x13c38
movl %ebx, %eax
movslq %ebx, %rbx
cmpq %rbx, 0x80(%rsp)
leaq 0x40(%rsp), %r14
ja 0x7248
lock
incl 0x1d12a(%rip)           # 0x246b8
movq 0x10(%rsp), %rdx
incq %rdx
movq 0x68(%rsp), %rcx
movl 0x4(%rcx), %eax
addl (%rcx), %eax
cmpq %rax, %rdx
jb 0x71eb
xorl %eax, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11b39(%rip), %rdi     # 0x190fd
leaq 0x11aca(%rip), %rsi     # 0x19095
leaq 0x11ad3(%rip), %rcx     # 0x190a5
movl $0x8c, %edx
callq 0x61f0
leaq 0x11b03(%rip), %rdi     # 0x190e6
leaq 0x11aab(%rip), %rsi     # 0x19095
leaq 0x11ab4(%rip), %rcx     # 0x190a5
movl $0x8b, %edx
callq 0x61f0
leaq 0x11ac0(%rip), %rdi     # 0x190c2
leaq 0x11a8c(%rip), %rsi     # 0x19095
leaq 0x11a95(%rip), %rcx     # 0x190a5
movl $0x7a, %edx
callq 0x61f0
leaq 0x11a2e(%rip), %rdi     # 0x1904f
leaq 0x11a6d(%rip), %rsi     # 0x19095
leaq 0x11a76(%rip), %rcx     # 0x190a5
movl $0x78, %edx
callq 0x61f0
jmp 0x76a0
jmp 0x763d
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x65c0
jmp 0x76a3
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r14, %rdi
je 0x76a3
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x6370
jmp 0x76a3
jmp 0x76a0
jmp 0x768e
jmp 0x7670
jmp 0x768e
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x65c0
jmp 0x7691
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xd188
jmp 0x7691
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0xe512
jmp 0x76a3
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x13c38
movq %rbx, %rdi
callq 0x65d0