// File: /workspace/github_cpp_makefile_star2_O1/moyix[P]pandalog_taint_parser/label_pcs.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);
                    ptr_to_pc[tq.ptr()].insert(le.pc());
                    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 0x1d497(%rip), %rax     # 0x24600
movl 0x10(%rax), %edi
movq %rdi, 0x88(%rsp)
callq 0x6420
movq %rax, 0x18(%rsp)
movl (%rbx), %edx
movq %rbx, 0x58(%rsp)
movl 0x4(%rbx), %eax
addl %edx, %eax
cmpl %eax, %edx
jae 0x74c3
leaq 0x30(%rsp), %r14
leaq 0xc0(%rsp), %r15
leaq 0x20(%rsp), %r13
leaq 0x90(%rsp), %rbp
movq 0x1d445(%rip), %rax     # 0x245f8
movq %rdx, %rcx
movq %rdx, 0x10(%rsp)
shlq $0x4, %rcx
movq 0x1d42a(%rip), %rsi     # 0x245f0
addq (%rax,%rcx), %rsi
leaq 0x18(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x70dc
movq %rax, 0x70(%rsp)
testq %rax, %rax
je 0x74a1
xorl %ebx, %ebx
movq 0x18(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x10(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x60(%rsp)
xorl %r12d, %r12d
movq %r15, %rdi
xorl %esi, %esi
callq 0x137f2
movq 0x68(%rsp), %rcx
movl (%rcx,%rbx), %ebx
movslq %r12d, %rax
leaq (%rax,%rcx), %rsi
addq $0x4, %rsi
addq %rcx, %rax
movq %r14, 0x20(%rsp)
leaq (%rbx,%rax), %rdx
addq $0x4, %rdx
movq %r13, %rdi
callq 0x7f58
movq %r15, %rdi
movq %r13, %rsi
callq 0x65f0
testb %al, %al
je 0x74f6
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x7266
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6370
movq 0x148(%rsp), %rax
movq 0x1d393(%rip), %rcx     # 0x24608
movq 0x60(%rsp), %rdx
cmpq 0x4(%rcx,%rdx,8), %rax
leaq 0x1d3ba(%rip), %r14     # 0x24640
jb 0x74d7
movq %rbx, 0x78(%rsp)
movl %r12d, 0xc(%rsp)
movl 0xd0(%rsp), %ebx
testb $0x8, %bl
je 0x72e8
cmpq $0x0, 0xf0(%rsp)
jne 0x72e8
movq %r13, %rdi
movl $0x3, %esi
leaq 0x11e86(%rip), %rdx     # 0x19142
movl $0x1bd2, %ecx           # imm = 0x1BD2
callq 0x6530
movq %r13, %rdi
leaq 0x11e7e(%rip), %rsi     # 0x1914e
callq 0x6580
movq %rbp, %rdi
movq %rax, %rsi
callq 0x6450
movq %r13, %rdi
callq 0x65a0
testb $0x8, %bl
je 0x7470
movq 0xf0(%rsp), %rax
testq %rax, %rax
jne 0x7305
leaq 0x1d683(%rip), %rax     # 0x24988
movq 0x28(%rax), %rcx
leaq 0x8(%rcx), %rdx
testq %rcx, %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x80(%rsp)
movslq 0x20(%rax), %rbx
testq %rbx, %rbx
je 0x7470
shlq $0x3, %rbx
xorl %r15d, %r15d
movq 0x80(%rsp), %rax
movq (%rax,%r15), %rsi
movq %rbp, %rdi
callq 0xe76a
movl 0xa0(%rsp), %r12d
testb $0x1, %r12b
je 0x7398
cmpq $0x0, 0xa8(%rsp)
jne 0x7398
movq %r13, %rdi
movl $0x3, %esi
leaq 0x11dd6(%rip), %rdx     # 0x19142
movl $0x1394, %ecx           # imm = 0x1394
callq 0x6530
movq %r13, %rdi
leaq 0x11e02(%rip), %rsi     # 0x19182
callq 0x6580
movq %rsp, %rdi
movq %rax, %rsi
callq 0x6450
movq %r13, %rdi
callq 0x65a0
testb $0x1, %r12b
je 0x7418
movq 0xa8(%rsp), %rsi
testq %rsi, %rsi
jne 0x73b2
leaq 0x1d456(%rip), %rsi     # 0x24808
movq %r13, %rdi
callq 0xd476
movq %rbp, %r14
leaq 0x1d2d4(%rip), %rdi     # 0x24698
callq 0x64b0
movq 0x40(%rsp), %r12
movq 0x48(%rsp), %rax
movslq 0x38(%rsp), %rbp
movq %rax, (%rsp)
leaq 0x1d285(%rip), %rdi     # 0x24668
movq %rsp, %rsi
callq 0x7a0c
leaq (%r12,%rbp,4), %rsi
movq %r12, %rdi
movq %rax, %rdx
callq 0x8200
leaq 0x1d297(%rip), %rdi     # 0x24698
callq 0x6240
movq %r13, %rdi
callq 0xd4ec
movq %r14, %rbp
leaq 0x1d228(%rip), %r14     # 0x24640
movq %r14, %rdi
callq 0x64b0
movq 0xb0(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x1d1dc(%rip), %rdi     # 0x24610
movq %r13, %rsi
callq 0x7a72
movq 0x140(%rsp), %rcx
movq %rcx, (%rsp)
movq %rax, %rdi
movq %rsp, %rsi
callq 0x85ce
movq %r14, %rdi
callq 0x6240
movq %rbp, %rdi
callq 0xe876
addq $0x8, %r15
cmpq %r15, %rbx
jne 0x7330
movl 0xc(%rsp), %r12d
addl $0x4, %r12d
addl 0x78(%rsp), %r12d
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
callq 0x13f9c
movslq %r12d, %rbx
cmpq %rbx, 0x70(%rsp)
leaq 0x30(%rsp), %r14
ja 0x7207
lock
incl 0x1d218(%rip)           # 0x246c0
movq 0x10(%rsp), %rdx
incq %rdx
movq 0x58(%rsp), %rcx
movl 0x4(%rcx), %eax
addl (%rcx), %eax
cmpq %rax, %rdx
jb 0x71ac
xorl %eax, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11bce(%rip), %rdi     # 0x190ac
leaq 0x11b9c(%rip), %rsi     # 0x19081
leaq 0x11ba3(%rip), %rcx     # 0x1908f
movl $0x76, %edx
callq 0x61f0
leaq 0x11b3e(%rip), %rdi     # 0x1903b
leaq 0x11b7d(%rip), %rsi     # 0x19081
leaq 0x11b84(%rip), %rcx     # 0x1908f
movl $0x74, %edx
callq 0x61f0
jmp 0x7519
jmp 0x755b
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x65a0
jmp 0x7581
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x7581
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6370
jmp 0x7581
jmp 0x755b
jmp 0x7562
jmp 0x754a
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x65a0
jmp 0x7574
jmp 0x7562
movq %rax, %rbx
jmp 0x7581
jmp 0x7562
movq %rax, %rbx
jmp 0x7574
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xd4ec
leaq 0x90(%rsp), %rdi
callq 0xe876
leaq 0xc0(%rsp), %rdi
callq 0x13f9c
movq %rbx, %rdi
callq 0x65b0