// File: /workspace/github_c_makefile_star2_O0/melynx[P]peekaboo/read_trace.c
// Function: print_filter
bool print_filter(peekaboo_insn_t *insn, 
                  size_t insn_idx, 
                  const size_t num_insn, 
                  const bool is_search, 
                  const uint64_t target_addr,
                  const uint32_t target_addr_size)
{
    /* Return true to print this instruction. Otherwise, skip this instruction printing. */
    bool rvalue;

    // KH: If no target block, then by default print everything
    if (is_search)
        rvalue = false;
    else
        rvalue = true;

    if (target_addr != (uint64_t) -1)
    {
        rvalue = false;
        if (insn->num_mem > 0)
        {
            for (uint32_t mem_idx = 0; mem_idx < insn->num_mem; mem_idx++)
            {
                // We don't print zero-size memory accesses, i.e. lea instr
                if (insn->mem[mem_idx].size == 0) continue;

                // Exclude those don't have overlaps
                if (
                    !( 
                        (target_addr > insn->mem[mem_idx].addr + insn->mem[mem_idx].size)
                        ||
                        (target_addr+target_addr_size-1 < insn->mem[mem_idx].addr)
                    )
                   )
                {
                    rvalue = true;
                    break;
                }
            }
        }
    }

    // If print_next, then overide return value
    if (print_next)
    {
        print_next--;
        rvalue = true;
    }

    // Detailed settings for what to print
    /*
    if (insn_idx == num_insn)
    {
        print_register  = true;
        print_memory    = true;
    }
    else
    {
        print_register  = false;
        print_memory    = false;    
    }
    */

   return rvalue;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
testb $0x1, -0x19(%rbp)
je 0x434b
movb $0x0, -0x2d(%rbp)
jmp 0x434f
movb $0x1, -0x2d(%rbp)
cmpq $-0x1, -0x28(%rbp)
je 0x4414
movb $0x0, -0x2d(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jbe 0x4412
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x4410
movq -0x8(%rbp), %rax
addq $0x28, %rax
movl -0x34(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $0x0, 0x10(%rax)
jne 0x439f
jmp 0x4402
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
addq $0x28, %rcx
movl -0x34(%rbp), %edx
shlq $0x5, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movq -0x8(%rbp), %rdx
addq $0x28, %rdx
movl -0x34(%rbp), %esi
shlq $0x5, %rsi
addq %rsi, %rdx
movl 0x10(%rdx), %edx
addq %rdx, %rcx
cmpq %rcx, %rax
ja 0x4400
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
addq %rcx, %rax
subq $0x1, %rax
movq -0x8(%rbp), %rcx
addq $0x28, %rcx
movl -0x34(%rbp), %edx
shlq $0x5, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jb 0x4400
movb $0x1, -0x2d(%rbp)
jmp 0x4410
jmp 0x4402
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4374
jmp 0x4412
jmp 0x4414
cmpl $0x0, 0x8d11(%rip)      # 0xd12c
je 0x4430
movl 0x8d09(%rip), %eax      # 0xd12c
addl $-0x1, %eax
movl %eax, 0x8d00(%rip)      # 0xd12c
movb $0x1, -0x2d(%rbp)
movb -0x2d(%rbp), %al
andb $0x1, %al
popq %rbp
retq
nopw (%rax,%rax)