// File: /workspace/github_cpp_makefile_star2_O3/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 0x1d5b4(%rip), %rax     # 0x24600
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 0x73b4
leaq 0x38(%rsp), %r14
leaq 0xc0(%rsp), %r15
leaq 0x28(%rsp), %r13
movq 0x1d56a(%rip), %rax     # 0x245f8
movq %rdx, %rcx
movq %rdx, 0x18(%rsp)
shlq $0x4, %rcx
movq 0x1d54f(%rip), %rsi     # 0x245f0
addq (%rax,%rcx), %rsi
leaq 0x20(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x6fbc
movq %rax, 0x78(%rsp)
testq %rax, %rax
je 0x7392
xorl %ebx, %ebx
movq 0x20(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x18(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x68(%rsp)
xorl %ebp, %ebp
movq %r15, %rdi
xorl %esi, %esi
callq 0x136b4
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 0x7e6e
movq %r15, %rdi
movq %r13, %rsi
callq 0x65f0
testb %al, %al
je 0x73e7
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0x7141
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6370
movq 0x148(%rsp), %rax
movq 0x1d4b8(%rip), %rcx     # 0x24608
movq 0x68(%rsp), %rdx
cmpq 0x4(%rcx,%rdx,8), %rax
leaq 0x90(%rsp), %rbx
leaq 0x1d4d7(%rip), %r14     # 0x24640
jb 0x73c8
movq %r12, 0x80(%rsp)
movl %ebp, 0x14(%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 0x71e4
movq %r13, %rdi
movl $0x3, %esi
leaq 0x11f94(%rip), %rdx     # 0x19142
movl $0x1bd2, %ecx           # imm = 0x1BD2
callq 0x6530
movq %r13, %rdi
leaq 0x11f8c(%rip), %rsi     # 0x1914e
callq 0x6580
movq %rbx, %rdi
movq %rax, %rsi
callq 0x6450
movq %r13, %rdi
callq 0x65a0
movq 0xf0(%rsp), %rax
jmp 0x71ed
testb $0x8, %cl
je 0x7361
testq %rax, %rax
jne 0x71f9
leaq 0x1d78f(%rip), %rax     # 0x24988
movq 0x28(%rax), %rcx
leaq 0x8(%rcx), %r15
testq %rcx, %rcx
cmoveq %rcx, %r15
movslq 0x20(%rax), %rbp
testq %rbp, %rbp
je 0x7361
shlq $0x3, %rbp
xorl %r12d, %r12d
movq (%r15,%r12), %rsi
movq %rbx, %rdi
callq 0xe676
movl 0xa0(%rsp), %eax
movq 0xa8(%rsp), %rsi
testq %rsi, %rsi
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x728b
movq %r13, %rdi
movl $0x3, %esi
leaq 0x11eef(%rip), %rdx     # 0x19142
movl $0x1394, %ecx           # imm = 0x1394
callq 0x6530
movq %r13, %rdi
leaq 0x11f1b(%rip), %rsi     # 0x19182
callq 0x6580
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x6450
movq %r13, %rdi
callq 0x65a0
movq 0xa8(%rsp), %rsi
jmp 0x728f
testb $0x1, %al
je 0x7306
testq %rsi, %rsi
jne 0x729b
leaq 0x1d56d(%rip), %rsi     # 0x24808
movq %r13, %rdi
callq 0xd3a8
leaq 0x1d3ee(%rip), %rdi     # 0x24698
callq 0x64b0
movq 0x48(%rsp), %rbx
movq 0x50(%rsp), %rax
movslq 0x40(%rsp), %r14
movq %rax, 0x8(%rsp)
leaq 0x1d39e(%rip), %rdi     # 0x24668
leaq 0x8(%rsp), %rsi
callq 0x7922
leaq (%rbx,%r14,4), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x811c
leaq 0x1d3ae(%rip), %rdi     # 0x24698
callq 0x6240
movq %r13, %rdi
callq 0xd41e
leaq 0x90(%rsp), %rbx
leaq 0x1d33a(%rip), %r14     # 0x24640
movq %r14, %rdi
callq 0x64b0
movq 0xb0(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x1d2ee(%rip), %rdi     # 0x24610
movq %r13, %rsi
callq 0x7988
movq 0x140(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
callq 0x84e4
movq %r14, %rdi
callq 0x6240
movq %rbx, %rdi
callq 0xe784
addq $0x8, %r12
cmpq %r12, %rbp
jne 0x721c
movl 0x14(%rsp), %ebp
addl $0x4, %ebp
addl 0x80(%rsp), %ebp
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
callq 0x13f0c
movslq %ebp, %rbx
cmpq %rbx, 0x78(%rsp)
leaq 0x38(%rsp), %r14
ja 0x70e1
lock
incl 0x1d327(%rip)           # 0x246c0
movq 0x18(%rsp), %rdx
incq %rdx
movq 0x60(%rsp), %rcx
movl 0x4(%rcx), %eax
addl (%rcx), %eax
cmpq %rax, %rdx
jb 0x7087
xorl %eax, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11cdd(%rip), %rdi     # 0x190ac
leaq 0x11cab(%rip), %rsi     # 0x19081
leaq 0x11cb2(%rip), %rcx     # 0x1908f
movl $0x76, %edx
callq 0x61f0
leaq 0x11c4d(%rip), %rdi     # 0x1903b
leaq 0x11c8c(%rip), %rsi     # 0x19081
leaq 0x11c93(%rip), %rcx     # 0x1908f
movl $0x74, %edx
callq 0x61f0
jmp 0x7408
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x65a0
jmp 0x7472
jmp 0x7453
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r14, %rdi
je 0x7472
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6370
jmp 0x7472
jmp 0x7453
jmp 0x744e
jmp 0x743b
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x65a0
jmp 0x7465
jmp 0x744e
jmp 0x744e
movq %rax, %rbx
jmp 0x7465
movq %rax, %rbx
jmp 0x7472
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0xd41e
leaq 0x90(%rsp), %rdi
callq 0xe784
leaq 0xc0(%rsp), %rdi
callq 0x13f0c
movq %rbx, %rdi
callq 0x65b0