// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
leaq 0x2f2a(%rip), %rdi      # 0x82a5
movb $0x0, %al
callq 0x40b0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x548a
movb $0x0, -0x1d(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x53b2
jmp 0x53d1
leaq 0x2f22(%rip), %rdi      # 0x82db
leaq 0x2cef(%rip), %rsi      # 0x80af
movl $0x243, %edx            # imm = 0x243
leaq 0x2f1f(%rip), %rcx      # 0x82eb
callq 0x40f0
leaq 0x2da6(%rip), %rdi      # 0x817e
movb $0x0, %al
callq 0x40b0
movq -0x18(%rbp), %rax
testb $0x1, (%rax)
je 0x53f8
leaq 0x2f2c(%rip), %rdi      # 0x831b
movb $0x0, %al
callq 0x40b0
jmp 0x5470
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x545a
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x1c(%rbp), %ecx
movw (%rax,%rcx,2), %ax
movw %ax, -0x20(%rbp)
movzwl -0x20(%rbp), %eax
cmpl $0x1111, %eax           # imm = 0x1111
jne 0x543d
leaq 0x2f0f(%rip), %rdi      # 0x833f
movb $0x0, %al
callq 0x40b0
movb $0x1, -0x1d(%rbp)
jmp 0x544f
movzwl -0x20(%rbp), %esi
leaq 0x2efb(%rip), %rdi      # 0x8343
movb $0x0, %al
callq 0x40b0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x53ff
testb $0x1, -0x1d(%rbp)
jne 0x5462
jmp 0x5462
leaq 0x40ed(%rip), %rdi      # 0x9556
movb $0x0, %al
callq 0x40b0
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x5394
addq $0x20, %rsp
popq %rbp
retq