// File: jstaursky[P]hutch/src/Sleigh/sleigh.cc
// Function: Sleigh::oneInstruction(PcodeEmit&, Address const&) const
int4 Sleigh::oneInstruction (PcodeEmit& emit, const Address& baseaddr) const

{
    int4 fallOffset;
    if (alignment != 1) {
        if ((baseaddr.getOffset () % alignment) != 0) {
            ostringstream s;
            s << "Instruction address not aligned: " << baseaddr;
            throw UnimplError (s.str (), 0);
        }
    }

    ParserContext* pos = obtainContext (baseaddr, ParserContext::pcode);
    pos->applyCommits ();
    fallOffset = pos->getLength ();

    if (pos->getDelaySlot () > 0) {
        int4 bytecount = 0;
        do {
            // Do not pass pos->getNaddr() to obtainContext, as pos may have
            // been previously cached and had naddr adjusted
            ParserContext* delaypos = obtainContext (
                pos->getAddr () + fallOffset, ParserContext::pcode);
            delaypos->applyCommits ();
            int4 len = delaypos->getLength ();
            fallOffset += len;
            bytecount += len;
        } while (bytecount < pos->getDelaySlot ());
        pos->setNaddr (pos->getAddr () + fallOffset);
    }
    ParserWalker walker (pos);
    walker.baseState ();
    pcode_cache.clear ();
    SleighBuilder builder (&walker, discache, &pcode_cache, getConstantSpace (),
                           getUniqueSpace (), unique_allocatemask);

    try {
        builder.build (walker.getConstructor ()->getTempl (), -1);
        pcode_cache.resolveRelatives ();
        pcode_cache.emit (baseaddr, &emit);
    } catch (UnimplError& err) {
        ostringstream s;
        s << "Instruction not implemented in pcode:\n ";
        ParserWalker* cur = builder.getCurrentWalker ();
        cur->baseState ();
        Constructor* ct = cur->getConstructor ();
        cur->getAddr ().printRaw (s);
        s << ": ";
        ct->printMnemonic (s, *cur);
        s << "  ";
        ct->printBody (s, *cur);
        err.explain = s.str ();
        err.instruction_length = fallOffset;
        throw err;
    }
    return fallOffset;
}

// Assembly:
subq $0x548, %rsp            # imm = 0x548
movq %rdi, 0x540(%rsp)
movq %rsi, 0x538(%rsp)
movq %rdx, 0x530(%rsp)
movq 0x540(%rsp), %rax
movq %rax, 0x98(%rsp)
cmpl $0x1, 0x128(%rax)
je 0x11cf5f
movq 0x530(%rsp), %rdi
callq 0xe03b0
movq 0x98(%rsp), %rcx
movslq 0x128(%rcx), %rcx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
je 0x11cf5d
leaq 0x3b0(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0xdbe90
movq 0x88(%rsp), %rdi
leaq 0x6b6a6(%rip), %rsi     # 0x1884f1
callq 0xd8300
movq %rax, 0x90(%rsp)
jmp 0x11ce5a
movq 0x90(%rsp), %rdi
movq 0x530(%rsp), %rsi
callq 0xd7ca0
jmp 0x11ce71
movb $0x1, 0x37f(%rsp)
movl $0x28, %edi
callq 0xd2b40
movq %rax, 0x80(%rsp)
leaq 0x380(%rsp), %rdi
leaq 0x3b0(%rsp), %rsi
callq 0xd8840
jmp 0x11cea2
movq 0x80(%rsp), %rdi
leaq 0x380(%rsp), %rsi
xorl %edx, %edx
callq 0xde210
jmp 0x11cebb
movq 0x80(%rsp), %rdi
movb $0x0, 0x37f(%rsp)
movq 0xab046(%rip), %rsi     # 0x1c7f18
movq 0xaaf2f(%rip), %rdx     # 0x1c7e08
callq 0xe01f0
jmp 0x11d451
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3a8(%rsp)
movl %eax, 0x3a4(%rsp)
jmp 0x11cf4b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3a8(%rsp)
movl %eax, 0x3a4(%rsp)
jmp 0x11cf30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3a8(%rsp)
movl %eax, 0x3a4(%rsp)
leaq 0x380(%rsp), %rdi
callq 0xd4550
testb $0x1, 0x37f(%rsp)
jne 0x11cf3c
jmp 0x11cf49
movq 0x80(%rsp), %rdi
callq 0xd5400
jmp 0x11cf4b
leaq 0x3b0(%rsp), %rdi
callq 0xd0160
jmp 0x11d43c
jmp 0x11cf5f
movq 0x98(%rsp), %rdi
movq 0x530(%rsp), %rsi
movl $0x2, %edx
callq 0xd40b0
movq %rax, 0x370(%rsp)
movq 0x370(%rsp), %rdi
callq 0xdc670
movq 0x370(%rsp), %rdi
callq 0xd1b00
movl %eax, 0x52c(%rsp)
movq 0x370(%rsp), %rdi
callq 0xe2180
cmpl $0x0, %eax
jle 0x11d0bd
movl $0x0, 0x36c(%rsp)
movq 0x370(%rsp), %rdi
callq 0xd2a50
movq %rax, %rsi
movl 0x52c(%rsp), %edx
leaq 0x350(%rsp), %rdi
callq 0xd8150
movq 0x98(%rsp), %rdi
leaq 0x350(%rsp), %rsi
movl $0x2, %edx
callq 0xd40b0
movq %rax, 0x360(%rsp)
movq 0x360(%rsp), %rdi
callq 0xdc670
movq 0x360(%rsp), %rdi
callq 0xd1b00
movl %eax, 0x34c(%rsp)
movl 0x34c(%rsp), %eax
addl 0x52c(%rsp), %eax
movl %eax, 0x52c(%rsp)
movl 0x34c(%rsp), %eax
addl 0x36c(%rsp), %eax
movl %eax, 0x36c(%rsp)
movl 0x36c(%rsp), %eax
movl %eax, 0x7c(%rsp)
movq 0x370(%rsp), %rdi
callq 0xe2180
movl %eax, %ecx
movl 0x7c(%rsp), %eax
cmpl %ecx, %eax
jl 0x11cfc3
movq 0x370(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x370(%rsp), %rdi
callq 0xd2a50
movq %rax, %rsi
movl 0x52c(%rsp), %edx
leaq 0x338(%rsp), %rdi
callq 0xd8150
movq 0x70(%rsp), %rdi
leaq 0x338(%rsp), %rsi
callq 0xd6e80
movq 0x370(%rsp), %rsi
leaq 0x298(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0xd7160
movq 0x60(%rsp), %rdi
callq 0xe07e0
movq 0x98(%rsp), %rdi
addq $0x200, %rdi            # imm = 0x200
movq %rdi, 0x50(%rsp)
callq 0xce380
movq 0x98(%rsp), %rdi
movq 0x1f8(%rdi), %rax
movq %rax, 0x48(%rsp)
callq 0xd9e20
movq 0x98(%rsp), %rdi
movq %rax, 0x58(%rsp)
callq 0xd8720
movq 0x48(%rsp), %rdx
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %r8
movq 0x60(%rsp), %rsi
movq %rax, %r9
movq 0x98(%rsp), %rax
movl 0x1d4(%rax), %edi
movq %rsp, %rax
movl %edi, (%rax)
leaq 0x250(%rsp), %rdi
callq 0xd0c90
movq 0x60(%rsp), %rdi
callq 0xd81d0
movq %rax, 0x68(%rsp)
jmp 0x11d16d
movq 0x68(%rsp), %rdi
callq 0xd87a0
movq %rax, 0x40(%rsp)
jmp 0x11d17e
movq 0x40(%rsp), %rsi
leaq 0x250(%rsp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xd0740
jmp 0x11d197
movq 0x98(%rsp), %rdi
addq $0x200, %rdi            # imm = 0x200
callq 0xe1e70
jmp 0x11d1ad
movq 0x98(%rsp), %rdi
addq $0x200, %rdi            # imm = 0x200
movq 0x530(%rsp), %rsi
movq 0x538(%rsp), %rdx
callq 0xd7d30
jmp 0x11d1d3
jmp 0x11d40b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3a8(%rsp)
movl %eax, 0x3a4(%rsp)
movl 0x3a4(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x11d42f
movq 0x3a8(%rsp), %rdi
callq 0xd1d20
movq %rax, 0x248(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0xdbe90
jmp 0x11d224
leaq 0x6b2e8(%rip), %rsi     # 0x188513
leaq 0xd0(%rsp), %rdi
callq 0xd8300
jmp 0x11d23a
leaq 0x250(%rsp), %rdi
callq 0xd4050
movq %rax, 0x38(%rsp)
jmp 0x11d24e
movq 0x38(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq 0xc8(%rsp), %rdi
callq 0xe07e0
jmp 0x11d26a
movq 0xc8(%rsp), %rdi
callq 0xd81d0
movq %rax, 0x30(%rsp)
jmp 0x11d27e
movq 0x30(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0xc8(%rsp), %rdi
callq 0xcee30
movq %rax, 0x28(%rsp)
jmp 0x11d29f
movq 0x28(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0xd82c0
jmp 0x11d2b3
leaq 0x6b256(%rip), %rsi     # 0x188510
leaq 0xd0(%rsp), %rdi
callq 0xd8300
jmp 0x11d2c9
movq 0xc0(%rsp), %rdi
movq 0xc8(%rsp), %rdx
leaq 0xd0(%rsp), %rsi
callq 0xd32e0
jmp 0x11d2e8
leaq 0x6c296(%rip), %rsi     # 0x189585
leaq 0xd0(%rsp), %rdi
callq 0xd8300
jmp 0x11d2fe
movq 0xc0(%rsp), %rdi
movq 0xc8(%rsp), %rdx
leaq 0xd0(%rsp), %rsi
callq 0xdad80
jmp 0x11d31d
leaq 0xa0(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0xd8840
jmp 0x11d334
movq 0x248(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
movq %rsi, 0x18(%rsp)
callq 0xda960
movq 0x18(%rsp), %rdi
callq 0xd4550
movl 0x52c(%rsp), %ecx
movq 0x248(%rsp), %rax
movl %ecx, 0x20(%rax)
movl $0x28, %edi
callq 0xd2b40
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x20(%rsp)
movq 0x248(%rsp), %rsi
callq 0xd4c30
jmp 0x11d38e
movq 0x20(%rsp), %rdi
movq 0xaab7e(%rip), %rsi     # 0x1c7f18
movq 0xaaa67(%rip), %rdx     # 0x1c7e08
callq 0xe01f0
jmp 0x11d451
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3a8(%rsp)
movl %eax, 0x3a4(%rsp)
jmp 0x11d402
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3a8(%rsp)
movl %eax, 0x3a4(%rsp)
jmp 0x11d3f5
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3a8(%rsp)
movl %eax, 0x3a4(%rsp)
callq 0xd5400
leaq 0xd0(%rsp), %rdi
callq 0xd0160
callq 0xdf2c0
jmp 0x11d409
jmp 0x11d42f
movl 0x52c(%rsp), %eax
movl %eax, 0x14(%rsp)
leaq 0x250(%rsp), %rdi
callq 0xd73f0
movl 0x14(%rsp), %eax
addq $0x548, %rsp            # imm = 0x548
retq
leaq 0x250(%rsp), %rdi
callq 0xd73f0
movq 0x3a8(%rsp), %rdi
callq 0xe0be0
movq %rax, %rdi
callq 0xe7140
nopw %cs:(%rax,%rax)