// File: /workspace/github_c_makefile_star2_O2/melynx[P]peekaboo/read_trace.c
// Function: print_pattern
void print_pattern(const cache_linked_list_t* pattern)
{
    printf("Search for the following snippet (%lu instructions):\n", pattern->length);
    uint32_t instr_id;
    insn_rawbyte_node_t *this_node = pattern->head;
    for (instr_id = 0; instr_id < pattern->length; instr_id++, this_node=this_node->succ)
    {
        uint32_t byte_offset;
        bool has_arbitrary_byte = false;
        assert(this_node!=NULL);
        printf("\t");
        if (this_node->is_arbitrary)
        {
            printf("**                   \t[Any Instr.]\n");
            continue;
        }
        for(byte_offset = 0; byte_offset < this_node->size; byte_offset++)
        {
            uint16_t byte_to_print = this_node->bytes[byte_offset];
            if (byte_to_print == 0x101*16+0x101)
            {
                printf("?? ");
                has_arbitrary_byte = true;
                continue;
            }
            printf("%02hhx ", byte_to_print);
        }
        if (!has_arbitrary_byte)
        {
        #ifdef ASM_CAPSTONE
            cs_insn *capstone_insn;
            uint8_t *tmp_rawbytes = malloc(this_node->size);
            if (!tmp_rawbytes) PEEKABOO_DIE("Failed to malloc");
            uint32_t tmp_idx;
            for (tmp_idx = 0; tmp_idx < this_node->size; tmp_idx++)
            {
                tmp_rawbytes[tmp_idx] = this_node->bytes[tmp_idx] & 0xFF;
            }
            size_t count = cs_disasm(capstone_handler, tmp_rawbytes, this_node->size, 0x0, 0, &capstone_insn);
            free(tmp_rawbytes);
            if (count > 0) 
            {
                size_t k;
                for (k = this_node->size; k < 8; k++) printf("   ");
                printf("%s\t\t%s", capstone_insn[0].mnemonic, capstone_insn[00].op_str);
                cs_free(capstone_insn, count);
            }
        #endif
        }
        printf("\n");
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movq 0x10(%rdi), %rsi
leaq 0x25f8(%rip), %rdi      # 0x6277
xorl %eax, %eax
callq 0x30d0
pushq $0x9
popq %rbp
leaq 0x265d(%rip), %r15      # 0x62ed
leaq 0x265a(%rip), %r12      # 0x62f1
movq %r14, %rbx
xorl %r13d, %r13d
movq %r14, (%rsp)
movl %r13d, %eax
cmpq %rax, 0x10(%r14)
jbe 0x3d1c
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x3d2b
movl %ebp, %edi
callq 0x3040
cmpb $0x0, (%rbx)
je 0x3ccc
leaq 0x2ab2(%rip), %rdi      # 0x6777
callq 0x3080
jmp 0x3d13
movl %ebp, %r14d
xorl %ebp, %ebp
movl 0x10(%rbx), %eax
cmpq %rax, %rbp
jae 0x3d04
movq 0x8(%rbx), %rax
movzwl (%rax,%rbp,2), %esi
cmpl $0x1111, %esi           # imm = 0x1111
jne 0x3cf5
movq %r15, %rdi
xorl %eax, %eax
callq 0x30d0
jmp 0x3cff
movq %r12, %rdi
xorl %eax, %eax
callq 0x30d0
incq %rbp
jmp 0x3cd1
pushq $0xa
popq %rdi
callq 0x3040
movl %r14d, %ebp
movq (%rsp), %r14
incl %r13d
addq $0x20, %rbx
jmp 0x3ca1
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x257b(%rip), %rdi      # 0x62ad
leaq 0x234e(%rip), %rsi      # 0x6087
leaq 0x257d(%rip), %rcx      # 0x62bd
movl $0x243, %edx            # imm = 0x243
callq 0x3110