// File: /workspace/github_cpp_makefile_star2_O3/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 $0x178, %rsp            # imm = 0x178
movq %rdi, %rbx
movq 0x1d584(%rip), %rax     # 0x24610
movl 0x10(%rax), %edi
movq %rdi, 0x88(%rsp)
callq 0x6420
movq %rax, 0x20(%rsp)
movl (%rbx), %edx
movq %rbx, 0x60(%rsp)
movl 0x4(%rbx), %eax
addl %edx, %eax
cmpl %eax, %edx
jae 0x746b
leaq 0x38(%rsp), %r14
leaq 0xc0(%rsp), %r15
leaq 0x28(%rsp), %r13
movq 0x1d53a(%rip), %rax     # 0x24608
movq %rdx, %rcx
movq %rdx, 0x10(%rsp)
shlq $0x4, %rcx
movq 0x1d51f(%rip), %rsi     # 0x24600
addq (%rax,%rcx), %rsi
leaq 0x20(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x6ffc
movq %rax, 0x78(%rsp)
testq %rax, %rax
je 0x7449
xorl %ebx, %ebx
movq 0x20(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x10(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x68(%rsp)
xorl %ebp, %ebp
movq %r15, %rdi
xorl %esi, %esi
callq 0x13328
movq 0x70(%rsp), %rcx
movl (%rcx,%rbx), %r12d
movslq %ebp, %rax
leaq (%rax,%rcx), %rsi
addq $0x4, %rsi
addq %rcx, %rax
movq %r14, 0x28(%rsp)
leaq (%r12,%rax), %rdx
addq $0x4, %rdx
movq %r13, %rdi
callq 0x7cc0
movq %r15, %rdi
movq %r13, %rsi
callq 0x6610
testb %al, %al
je 0x74dc
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0x7181
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6370
movq 0x148(%rsp), %rax
movq 0x1d488(%rip), %rcx     # 0x24618
movq 0x68(%rsp), %rdx
cmpq 0x4(%rcx,%rdx,8), %rax
leaq 0x90(%rsp), %rbx
leaq 0x1d477(%rip), %r14     # 0x24620
jb 0x74bd
movq %r12, 0x80(%rsp)
movl %ebp, 0xc(%rsp)
movl 0xd0(%rsp), %ecx
movl %ecx, %edx
shrb $0x3, %dl
movq 0xf0(%rsp), %rax
testq %rax, %rax
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x7224
movq %r13, %rdi
movl $0x3, %esi
leaq 0x11fc7(%rip), %rdx     # 0x191b5
movl $0x1bd2, %ecx           # imm = 0x1BD2
callq 0x6550
movq %r13, %rdi
leaq 0x11fbf(%rip), %rsi     # 0x191c1
callq 0x65a0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x6460
movq %r13, %rdi
callq 0x65c0
movq 0xf0(%rsp), %rax
jmp 0x722d
testb $0x8, %cl
je 0x7418
testq %rax, %rax
jne 0x7239
leaq 0x1d75f(%rip), %rax     # 0x24998
movq 0x28(%rax), %rcx
leaq 0x8(%rcx), %r12
testq %rcx, %rcx
cmoveq %rcx, %r12
movslq 0x20(%rax), %r15
testq %r15, %r15
je 0x7418
shlq $0x3, %r15
xorl %ebp, %ebp
movq (%r12,%rbp), %rsi
movq %rbx, %rdi
callq 0xe2ea
movl 0xa0(%rsp), %eax
movq 0xa8(%rsp), %rsi
testq %rsi, %rsi
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x72ca
movq %r13, %rdi
movl $0x3, %esi
leaq 0x11f23(%rip), %rdx     # 0x191b5
movl $0x1394, %ecx           # imm = 0x1394
callq 0x6550
movq %r13, %rdi
leaq 0x11f4f(%rip), %rsi     # 0x191f5
callq 0x65a0
leaq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x6460
movq %r13, %rdi
callq 0x65c0
movq 0xa8(%rsp), %rsi
jmp 0x72ce
testb $0x1, %al
je 0x7345
testq %rsi, %rsi
jne 0x72da
leaq 0x1d53e(%rip), %rsi     # 0x24818
movq %r13, %rdi
callq 0xd01c
leaq 0x1d3a7(%rip), %rdi     # 0x24690
callq 0x64c0
movq 0x48(%rsp), %rbx
movq 0x50(%rsp), %rax
movslq 0x40(%rsp), %r14
movq %rax, 0x18(%rsp)
leaq 0x1d357(%rip), %rdi     # 0x24660
leaq 0x18(%rsp), %rsi
callq 0x7aa6
leaq (%rbx,%r14,4), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x7fbe
leaq 0x1d367(%rip), %rdi     # 0x24690
callq 0x6240
movq %r13, %rdi
callq 0xd092
leaq 0x90(%rsp), %rbx
leaq 0x1d2db(%rip), %r14     # 0x24620
movq %r14, %rdi
callq 0x64c0
movq 0x148(%rsp), %rcx
movq 0x1d36c(%rip), %rax     # 0x246c8
cmpq %rax, %rcx
jae 0x749e
movq 0x1d364(%rip), %rdx     # 0x246d0
subq %rdx, %rcx
movq %rcx, %xmm0
movq 0x11c94(%rip), %xmm2    # 0x19010
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x11c98(%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 0x1d302(%rip), %ecx     # 0x246c0
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
cmpl %eax, %ecx
jle 0x747f
cltq
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
addq 0x1d262(%rip), %rdi     # 0x24648
movq 0xb0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %r13, %rsi
callq 0x8164
movq %r14, %rdi
callq 0x6240
movq %rbx, %rdi
callq 0xe3f8
addq $0x8, %rbp
cmpq %rbp, %r15
jne 0x725b
movl 0xc(%rsp), %ebp
addl $0x4, %ebp
addl 0x80(%rsp), %ebp
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
callq 0x13b80
movslq %ebp, %rbx
cmpq %rbx, 0x78(%rsp)
leaq 0x38(%rsp), %r14
ja 0x7121
lock
incl 0x1d268(%rip)           # 0x246b8
movq 0x10(%rsp), %rdx
incq %rdx
movq 0x60(%rsp), %rcx
movl 0x4(%rcx), %eax
addl (%rcx), %eax
cmpq %rax, %rdx
jb 0x70c7
xorl %eax, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11c77(%rip), %rdi     # 0x190fd
leaq 0x11c08(%rip), %rsi     # 0x19095
leaq 0x11c11(%rip), %rcx     # 0x190a5
movl $0x8c, %edx
callq 0x61f0
leaq 0x11c41(%rip), %rdi     # 0x190e6
leaq 0x11be9(%rip), %rsi     # 0x19095
leaq 0x11bf2(%rip), %rcx     # 0x190a5
movl $0x8b, %edx
callq 0x61f0
leaq 0x11bfe(%rip), %rdi     # 0x190c2
leaq 0x11bca(%rip), %rsi     # 0x19095
leaq 0x11bd3(%rip), %rcx     # 0x190a5
movl $0x7a, %edx
callq 0x61f0
leaq 0x11b6c(%rip), %rdi     # 0x1904f
leaq 0x11bab(%rip), %rsi     # 0x19095
leaq 0x11bb4(%rip), %rcx     # 0x190a5
movl $0x78, %edx
callq 0x61f0
jmp 0x74ff
jmp 0x7546
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x65c0
jmp 0x7565
jmp 0x7546
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0x7565
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6370
jmp 0x7565
jmp 0x7541
jmp 0x7530
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x65c0
jmp 0x7558
jmp 0x7541
movq %rax, %rbx
jmp 0x7558
movq %rax, %rbx
jmp 0x7565
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0xd092
leaq 0x90(%rsp), %rdi
callq 0xe3f8
leaq 0xc0(%rsp), %rdi
callq 0x13b80
movq %rbx, %rdi
callq 0x65d0