// File: /workspace/github_cpp_makefile_star2_O2/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 0x1bd66(%rip), %rax     # 0x22610
movl 0x10(%rax), %edi
leaq 0x58(%rsp), %rax
movq %rdi, (%rax)
callq 0x6400
leaq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movl (%rbx), %eax
leaq 0xc0(%rsp), %r14
leaq 0x60(%rsp), %r12
leaq 0x90(%rsp), %r15
leaq 0x1bd40(%rip), %r13     # 0x22620
movl %eax, %ecx
movq %rbx, 0x18(%rsp)
addl 0x4(%rbx), %eax
cmpl %eax, %ecx
jae 0x6bc8
movq 0x1bd0f(%rip), %rax     # 0x22608
movl %ecx, 0x8(%rsp)
movl %ecx, %ebx
movq %rbx, %rcx
shlq $0x4, %rcx
movq 0x1bcf3(%rip), %rsi     # 0x22600
addq (%rax,%rcx), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x681c
movq %rax, 0x30(%rsp)
xorl %ebp, %ebp
movq 0x10(%rsp), %rax
movq %rax, 0x28(%rsp)
imulq $0x18, %rbx, %rax
movq %rax, 0x20(%rsp)
movslq %ebp, %rbx
cmpq %rbx, 0x30(%rsp)
jbe 0x6baf
movq %r14, %rdi
callq 0x7110
movq 0x28(%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, 0x38(%rsp)
addq %rax, %rdx
addq $0x4, %rdx
movq %r12, %rdi
callq 0x73e4
movq %r14, %rdi
movq %r12, %rsi
callq 0x6600
testb %al, %al
je 0x6c1a
movq %r12, %rdi
callq 0x6160
movq 0x148(%rsp), %rax
movq 0x1bc6c(%rip), %rcx     # 0x22618
movq 0x20(%rsp), %rdx
cmpq 0x4(%rcx,%rdx), %rax
jb 0x6c33
movq %r14, %rdi
callq 0x7290
movl %ebp, 0xc(%rsp)
testb %al, %al
je 0x6b8f
movq 0xf0(%rsp), %rax
testq %rax, %rax
jne 0x69e4
leaq 0x1bfb4(%rip), %rax     # 0x22998
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, 0x40(%rsp)
cmpq %rbp, %r14
je 0x6b8f
movq (%rbx,%rbp), %rsi
movq %r12, %rdi
callq 0xbbfc
movq %r12, %rdi
callq 0x7310
testb %al, %al
je 0x6ac4
movq 0x78(%rsp), %rsi
testq %rsi, %rsi
jne 0x6a38
leaq 0x1bde0(%rip), %rsi     # 0x22818
movq %r15, %rdi
callq 0xafa6
movq %rbp, 0x48(%rsp)
movq %rbx, %rbp
movq %r13, %r14
movq %r12, %rbx
movq %r15, %r13
leaq 0x1bc38(%rip), %rdi     # 0x22690
callq 0x64b0
movq 0xb0(%rsp), %r15
movq 0xb8(%rsp), %rax
movslq 0xa8(%rsp), %r12
movq %rax, 0x50(%rsp)
leaq 0x1bbdf(%rip), %rdi     # 0x22660
leaq 0x50(%rsp), %rsi
callq 0x7118
leaq (%r15,%r12,4), %rsi
movq %r15, %rdi
movq %rax, %rdx
callq 0x77b2
leaq 0x1bbef(%rip), %rdi     # 0x22690
callq 0x6240
movq %r13, %r15
movq %r13, %rdi
callq 0xb016
movq %rbx, %r12
movq %r14, %r13
movq %rbp, %rbx
movq 0x40(%rsp), %r14
movq 0x48(%rsp), %rbp
movq %r13, %rdi
callq 0x64b0
movq 0x148(%rsp), %rcx
movq 0x1bbed(%rip), %rax     # 0x226c8
cmpq %rax, %rcx
jae 0x6bfb
movq 0x1bbe5(%rip), %rdx     # 0x226d0
subq %rdx, %rcx
movq %rcx, %xmm0
movq 0xe515(%rip), %xmm2     # 0x15010
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0xe519(%rip), %xmm3     # 0x15020
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 0x1bb83(%rip), %ecx     # 0x226c0
cvtsi2sd %ecx, %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
cmpl %eax, %ecx
jle 0x6bdc
cltq
imulq $0x30, %rax, %rdi
addq 0x1baea(%rip), %rdi     # 0x22648
movq 0x80(%rsp), %rax
movq %rax, 0x90(%rsp)
movq %r15, %rsi
callq 0x7974
movq %r13, %rdi
callq 0x6240
movq %r12, %rdi
callq 0xbc8c
addq $0x8, %rbp
jmp 0x6a02
movl 0xc(%rsp), %ebp
addl $0x4, %ebp
addl 0x38(%rsp), %ebp
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
callq 0xf38c
jmp 0x693a
lock
incl 0x1bb02(%rip)           # 0x226b8
movl 0x8(%rsp), %ecx
incl %ecx
movq 0x18(%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 0xe51a(%rip), %rdi      # 0x150fd
leaq 0xe4ab(%rip), %rsi      # 0x15095
leaq 0xe4b4(%rip), %rcx      # 0x150a5
movl $0x8c, %edx
callq 0x61f0
leaq 0xe4e4(%rip), %rdi      # 0x150e6
leaq 0xe48c(%rip), %rsi      # 0x15095
leaq 0xe495(%rip), %rcx      # 0x150a5
movl $0x8b, %edx
callq 0x61f0
leaq 0xe42e(%rip), %rdi      # 0x1504f
leaq 0xe46d(%rip), %rsi      # 0x15095
leaq 0xe476(%rip), %rcx      # 0x150a5
pushq $0x78
jmp 0x6c4a
leaq 0xe488(%rip), %rdi      # 0x150c2
leaq 0xe454(%rip), %rsi      # 0x15095
leaq 0xe45d(%rip), %rcx      # 0x150a5
pushq $0x7a
popq %rdx
callq 0x61f0
jmp 0x6c79
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x6160
jmp 0x6c8b
jmp 0x6c79
jmp 0x6c7e
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0xb016
jmp 0x6c81
jmp 0x6c7e
movq %rax, %rbx
jmp 0x6c8b
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xbc8c
leaq 0xc0(%rsp), %rdi
callq 0xf38c
movq %rbx, %rdi
callq 0x65c0