// File: jstaursky[P]hutch/src/Sleigh/sleigh.cc
// Function: SleighBuilder::delaySlot(OpTpl*)
void SleighBuilder::delaySlot (OpTpl* op)

{ // Append pcode for an entire instruction (delay slot)
    // in the middle of the current instruction
    ParserWalker* tmp = walker;
    uintb olduniqueoffset = uniqueoffset;

    Address baseaddr = tmp->getAddr ();
    int4 fallOffset = tmp->getLength ();
    int4 delaySlotByteCnt = tmp->getParserContext ()->getDelaySlot ();
    int4 bytecount = 0;
    do {
        Address newaddr = baseaddr + fallOffset;
        setUniqueOffset (newaddr);
        const ParserContext* pos = discache->getParserContext (newaddr);
        if (pos->getParserState () != ParserContext::pcode)
            throw LowlevelError (
                "Could not obtain cached delay slot instruction");
        int4 len = pos->getLength ();

        ParserWalker newwalker (pos);
        walker = &newwalker;
        walker->baseState ();
        build (walker->getConstructor ()->getTempl (),
               -1); // Build the whole delay slot
        fallOffset += len;
        bytecount += len;
    } while (bytecount < delaySlotByteCnt);
    walker = tmp; // Restore original context
    uniqueoffset = olduniqueoffset;
}

// Assembly:
subq $0x158, %rsp            # imm = 0x158
movq %rdi, 0x150(%rsp)
movq %rsi, 0x148(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x140(%rsp)
movq 0x30(%rax), %rax
movq %rax, 0x138(%rsp)
movq 0x140(%rsp), %rdi
callq 0xcee30
movq %rax, %rsi
leaq 0x128(%rsp), %rdi
callq 0xd6c50
movq 0x140(%rsp), %rdi
callq 0xd4f80
movl %eax, 0x124(%rsp)
movq 0x140(%rsp), %rdi
callq 0xd4da0
movq %rax, %rdi
callq 0xe2180
movl %eax, 0x120(%rsp)
movl $0x0, 0x11c(%rsp)
movl 0x124(%rsp), %edx
leaq 0x108(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0xd8150
movq 0x18(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0xdae10
movq 0x18(%rsp), %rax
movq 0x38(%rax), %rdi
leaq 0x108(%rsp), %rsi
callq 0xd3bf0
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rdi
callq 0xdbfb0
cmpl $0x2, %eax
je 0x11b512
movb $0x1, 0xcb(%rsp)
movl $0x20, %edi
callq 0xd2b40
movq %rax, 0x8(%rsp)
leaq 0xdf(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xe0c80
movq 0x10(%rsp), %rdx
leaq 0x6cfbd(%rip), %rsi     # 0x188428
leaq 0xe0(%rsp), %rdi
callq 0xe00a0
jmp 0x11b47a
movq 0x8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0xd1ae0
jmp 0x11b48e
movq 0x8(%rsp), %rdi
movb $0x0, 0xcb(%rsp)
movq 0xac9ee(%rip), %rsi     # 0x1c7e90
movq 0xac727(%rip), %rdx     # 0x1c7bd0
callq 0xe01f0
jmp 0x11b5e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd0(%rsp)
movl %eax, 0xcc(%rsp)
jmp 0x11b4ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd0(%rsp)
movl %eax, 0xcc(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0xd4550
leaq 0xdf(%rsp), %rdi
callq 0xd8ec0
testb $0x1, 0xcb(%rsp)
jne 0x11b503
jmp 0x11b50d
movq 0x8(%rsp), %rdi
callq 0xd5400
jmp 0x11b5da
movq 0x100(%rsp), %rdi
callq 0xd1b00
movl %eax, 0xc4(%rsp)
movq 0x100(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0xd7160
movq 0x18(%rsp), %rax
leaq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x10(%rax), %rdi
callq 0xe07e0
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0xd81d0
movq %rax, %rdi
callq 0xd87a0
movq 0x18(%rsp), %rdi
movq %rax, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xd0740
movl 0xc4(%rsp), %eax
addl 0x124(%rsp), %eax
movl %eax, 0x124(%rsp)
movl 0xc4(%rsp), %eax
addl 0x11c(%rsp), %eax
movl %eax, 0x11c(%rsp)
movl 0x11c(%rsp), %eax
cmpl 0x120(%rsp), %eax
jl 0x11b3d4
movq 0x18(%rsp), %rax
movq 0x140(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x138(%rsp), %rcx
movq %rcx, 0x30(%rax)
addq $0x158, %rsp            # imm = 0x158
retq
movq 0xd0(%rsp), %rdi
callq 0xe0be0
nopw (%rax,%rax)