// File: /workspace/github_cpp_makefile_star2_O2/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 0x1bd56(%rip), %rax     # 0x22600
movl 0x10(%rax), %edi
leaq 0x58(%rsp), %rax
movq %rdi, (%rax)
callq 0x6400
leaq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movl (%rbx), %eax
leaq 0xc0(%rsp), %r14
leaq 0x60(%rsp), %r13
leaq 0x90(%rsp), %r12
leaq 0x1bd60(%rip), %r15     # 0x22640
movl %eax, %ecx
movq %rbx, 0x20(%rsp)
addl 0x4(%rbx), %eax
cmpl %eax, %ecx
jae 0x6b57
movq 0x1bcff(%rip), %rax     # 0x225f8
movl %ecx, 0x10(%rsp)
movl %ecx, %ebx
movq %rbx, %rcx
shlq $0x4, %rcx
movq 0x1bce3(%rip), %rsi     # 0x225f0
addq (%rax,%rcx), %rsi
leaq 0x18(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x681c
movq %rax, 0x38(%rsp)
xorl %ebp, %ebp
movq 0x18(%rsp), %rax
movq %rax, 0x30(%rsp)
imulq $0x18, %rbx, %rax
movq %rax, 0x28(%rsp)
movslq %ebp, %rbx
cmpq %rbx, 0x38(%rsp)
jbe 0x6b3e
movq %r14, %rdi
callq 0x700c
movq 0x30(%rsp), %rcx
leaq (%rcx,%rbx), %rax
leaq (%rcx,%rbx), %rsi
addq $0x4, %rsi
movl -0x4(%rsi), %edx
leaq 0x70(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movq %rdx, 0x40(%rsp)
addq %rax, %rdx
addq $0x4, %rdx
movq %r13, %rdi
callq 0x76dc
movq %r14, %rdi
movq %r13, %rsi
callq 0x65e0
testb %al, %al
je 0x6b84
movq %r13, %rdi
callq 0x6160
movq 0x148(%rsp), %rax
movq 0x1bc5c(%rip), %rcx     # 0x22608
movq 0x28(%rsp), %rdx
cmpq 0x4(%rcx,%rdx), %rax
jb 0x6b6b
movq %r14, %rdi
callq 0x72a2
movl %ebp, 0x14(%rsp)
testb %al, %al
je 0x6b1e
movq 0xf0(%rsp), %rax
testq %rax, %rax
jne 0x69e4
leaq 0x1bfa4(%rip), %rax     # 0x22988
movq 0x28(%rax), %rcx
leaq 0x8(%rcx), %rbx
testq %rcx, %rcx
cmoveq %rcx, %rbx
movslq 0x20(%rax), %r14
shlq $0x3, %r14
xorl %ebp, %ebp
movq %r14, 0x48(%rsp)
cmpq %rbp, %r14
je 0x6b1e
movq (%rbx,%rbp), %rsi
movq %r13, %rdi
callq 0xbfa0
movq %r13, %rdi
callq 0x7322
testb %al, %al
je 0x6ac4
movq 0x78(%rsp), %rsi
testq %rsi, %rsi
jne 0x6a38
leaq 0x1bdd0(%rip), %rsi     # 0x22808
movq %r12, %rdi
callq 0xb34a
movq %rbp, 0x50(%rsp)
movq %rbx, %rbp
movq %r15, %rbx
movq %r13, %r15
movq %r12, %r13
leaq 0x1bc40(%rip), %rdi     # 0x22698
callq 0x64a0
movq 0xb0(%rsp), %r14
movq 0xb8(%rsp), %rax
movslq 0xa8(%rsp), %r12
movq %rax, 0x8(%rsp)
leaq 0x1bbe7(%rip), %rdi     # 0x22668
leaq 0x8(%rsp), %rsi
callq 0x7014
leaq (%r14,%r12,4), %rsi
movq %r14, %rdi
movq %rax, %rdx
callq 0x79f0
leaq 0x1bbf7(%rip), %rdi     # 0x22698
callq 0x6240
movq %r13, %r12
movq %r13, %rdi
callq 0xb3ba
movq %r15, %r13
movq %rbx, %r15
movq %rbp, %rbx
movq 0x48(%rsp), %r14
movq 0x50(%rsp), %rbp
movq %r15, %rdi
callq 0x64a0
movq 0x80(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x1bb2d(%rip), %rdi     # 0x22610
movq %r12, %rsi
callq 0x7064
movq 0x140(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
callq 0x7e10
movq %r15, %rdi
callq 0x6240
movq %r13, %rdi
callq 0xc030
addq $0x8, %rbp
jmp 0x6a02
movl 0x14(%rsp), %ebp
addl $0x4, %ebp
addl 0x40(%rsp), %ebp
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
callq 0xf730
jmp 0x693a
lock
incl 0x1bb7b(%rip)           # 0x226c0
movl 0x10(%rsp), %ecx
incl %ecx
movq 0x20(%rsp), %rbx
movl (%rbx), %eax
jmp 0x68e7
xorl %eax, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe522(%rip), %rdi      # 0x15094
leaq 0xe4f0(%rip), %rsi      # 0x15069
leaq 0xe4f7(%rip), %rcx      # 0x15077
pushq $0x76
jmp 0x6b9b
leaq 0xe498(%rip), %rdi      # 0x15023
leaq 0xe4d7(%rip), %rsi      # 0x15069
leaq 0xe4de(%rip), %rcx      # 0x15077
pushq $0x74
popq %rdx
callq 0x61f0
jmp 0x6bcc
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x6160
jmp 0x6bde
jmp 0x6bcc
jmp 0x6bd1
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0xb3ba
jmp 0x6bd4
jmp 0x6bd1
jmp 0x6bd1
movq %rax, %rbx
jmp 0x6bde
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xc030
leaq 0xc0(%rsp), %rdi
callq 0xf730
movq %rbx, %rdi
callq 0x65a0