// File: /workspace/github_cpp_makefile_star2_O3/jstaursky[P]hutch/src/hutch.cpp
// Function: Hutch::inspectPreviousInstruction(unsigned long, unsigned long, Hutch_Instructions&, bool (*)(PcodeData))
vector<Instruction>
Hutch::inspectPreviousInstruction (uintb offset, uintb limit,
                                   Hutch_Instructions& insn,
                                   bool (*select) (PcodeData))
{
    vector<Instruction> res;

    resetMark (offset, insn);
    if (insn.getMark ()->address - 1 == 0)
        return {};

    for (auto r = 1; (r != limit) && ((offset - r) > 0) &&
                     disassemble_iter (offset - r, &insn);
         ++r)
        ;
    for (auto rinsn = insn.getMark () - 1; rinsn != insn.current (); --rinsn) {
        // For ROP:
        // Need to determine whether the instruction ends immediately prior to
        // the marked/c3(ret) instruction for instruction to be useful.
        if (select == nullptr) {
            if ((rinsn->address + rinsn->bytelength) ==
                insn.getMark ()->address)
                res.push_back (*rinsn);
            continue;
        }
        // Only add those instructions that meet the alignment requirement
        // described above AND satisfy whatever condition the fptr "select" imposes.
        if (bool isSelected = false;
            (rinsn->address + rinsn->bytelength) == insn.getMark ()->address) {
            for (auto p : rinsn->pcode) {
                isSelected = select (p);
                if (isSelected) {
                    res.push_back (*rinsn);
                    break;
                }
            }
        }
    }
    return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, %r14
movq %r8, %r15
movq %rcx, %r13
movq %rdx, %rbp
movq %rsi, %rbx
movq %rdi, 0x8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq %rsi, %rdi
movq %rdx, %rsi
movq %r8, %rdx
callq 0x416c0
movq 0x10(%r15), %r12
movq 0x28(%r15), %rax
movq %rax, 0x30(%r15)
cmpq $0x1, (%rax)
movq 0x8(%rsp), %rcx
je 0x77390
cmpq $0x1, %r13
sete %cl
cmpq $0x1, %rbp
sete %dl
orb %cl, %dl
je 0x7724d
movq %rax, %rdx
jmp 0x7728b
addq $-0x2, %r13
leaq -0x2(%rbp), %rax
cmpq %rax, %r13
cmovaeq %rax, %r13
decq %rbp
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x416c0
subq $0x1, %r13
setb %cl
testl %eax, %eax
je 0x7727f
decq %rbp
testb %cl, %cl
je 0x7725f
movq 0x10(%r15), %r12
movq 0x28(%r15), %rax
movq 0x30(%r15), %rdx
subq %r12, %rdx
leaq (%r12,%rdx), %rcx
addq $-0x58, %rcx
cmpq %rax, %rcx
je 0x77378
addq %rdx, %r12
leaq 0x48(%rsp), %r13
movq %r12, %rax
movq -0x50(%r12), %rdx
addq -0x58(%r12), %rdx
movq %rcx, %r12
movq 0x30(%r15), %rcx
movq (%rcx), %rcx
testq %r14, %r14
je 0x77348
cmpq %rcx, %rdx
jne 0x77369
movq -0x28(%rax), %rbx
movq -0x20(%rax), %rbp
cmpq %rbp, %rbx
je 0x77369
leaq 0x30(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl (%rbx), %eax
movl %eax, 0x28(%rsp)
movl 0x18(%rbx), %eax
movl %eax, 0x40(%rsp)
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
leaq 0x28(%rsp), %rdi
callq 0x41010
leaq 0x50(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl 0x28(%rsp), %eax
movl %eax, 0x48(%rsp)
movl 0x40(%rsp), %eax
movl %eax, 0x60(%rsp)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %r13, %rdi
callq 0x41010
movq %r13, %rdi
callq *%r14
testb %al, %al
jne 0x7735c
addq $0x20, %rbx
jmp 0x772d8
cmpq %rcx, %rdx
jne 0x77369
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x41fc0
jmp 0x77369
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x41fc0
leaq -0x58(%r12), %rcx
cmpq 0x28(%r15), %rcx
jne 0x772a7
leaq 0x10(%rsp), %rcx
movaps (%rcx), %xmm0
movq 0x8(%rsp), %rdx
movups %xmm0, (%rdx)
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rdx)
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
movq $0x0, 0x10(%rcx)
leaq 0x10(%rsp), %rdi
callq 0x401b0
movq 0x8(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x773c4
jmp 0x773c4
jmp 0x773c4
jmp 0x773c4
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x401b0
movq %rbx, %rdi
callq 0x41f10
nop