// File: jstaursky[P]hutch/src/Sleigh/sleigh.cc
// Function: SleighBuilder::appendCrossBuild(OpTpl*, int)
void SleighBuilder::appendCrossBuild (OpTpl* bld, int4 secnum)

{ // Weave in the p-code section from an instruction at another address
    // bld-param(0) contains the address of the instruction
    // bld-param(1) contains the section number
    if (secnum >= 0)
        throw LowlevelError ("CROSSBUILD directive within a named section");
    secnum = bld->getIn (1)->getOffset ().getReal ();
    VarnodeTpl* vn = bld->getIn (0);
    AddrSpace* spc = vn->getSpace ().fixSpace (*walker);
    uintb addr = spc->wrapOffset (vn->getOffset ().fix (*walker));

    ParserWalker* tmp = walker;
    uintb olduniqueoffset = uniqueoffset;

    Address newaddr (spc, addr);
    setUniqueOffset (newaddr);
    const ParserContext* pos = discache->getParserContext (newaddr);
    if (pos->getParserState () != ParserContext::pcode)
        throw LowlevelError ("Could not obtain cached crossbuild instruction");

    ParserWalker newwalker (pos, tmp->getParserContext ());
    walker = &newwalker;

    walker->baseState ();
    Constructor* ct = walker->getConstructor ();
    ConstructTpl* construct = ct->getNamedTempl (secnum);
    if (construct == (ConstructTpl*)0)
        buildEmpty (ct, secnum);
    else
        build (construct, secnum);
    walker = tmp;
    uniqueoffset = olduniqueoffset;
}

// Assembly:
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rdi, 0x1a0(%rsp)
movq %rsi, 0x198(%rsp)
movl %edx, 0x194(%rsp)
movq 0x1a0(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpl $0x0, 0x194(%rsp)
jl 0x11b865
movb $0x1, 0x15b(%rsp)
movl $0x20, %edi
callq 0xd2b40
movq %rax, 0x28(%rsp)
leaq 0x16f(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xe0c80
movq 0x30(%rsp), %rdx
leaq 0x6cc99(%rip), %rsi     # 0x188457
leaq 0x170(%rsp), %rdi
callq 0xe00a0
jmp 0x11b7cd
movq 0x28(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0xd1ae0
jmp 0x11b7e1
movq 0x28(%rsp), %rdi
movb $0x0, 0x15b(%rsp)
movq 0xac69b(%rip), %rsi     # 0x1c7e90
movq 0xac3d4(%rip), %rdx     # 0x1c7bd0
callq 0xe01f0
jmp 0x11bb3e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x160(%rsp)
movl %eax, 0x15c(%rsp)
jmp 0x11b83d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x160(%rsp)
movl %eax, 0x15c(%rsp)
leaq 0x170(%rsp), %rdi
callq 0xd4550
leaq 0x16f(%rsp), %rdi
callq 0xd8ec0
testb $0x1, 0x15b(%rsp)
jne 0x11b856
jmp 0x11b860
movq 0x28(%rsp), %rdi
callq 0xd5400
jmp 0x11bb31
movq 0x198(%rsp), %rdi
movl $0x1, %esi
callq 0xd3b80
movq %rax, %rdi
callq 0xdbaf0
movq %rax, %rdi
callq 0xdd890
movl %eax, 0x194(%rsp)
movq 0x198(%rsp), %rdi
xorl %esi, %esi
callq 0xd3b80
movq %rax, 0x150(%rsp)
movq 0x150(%rsp), %rdi
callq 0xe3000
movq %rax, %rdi
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0xd4e60
movq %rax, 0x148(%rsp)
movq 0x148(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x150(%rsp), %rdi
callq 0xdbaf0
movq %rax, %rdi
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0xd5220
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0xcfa10
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x140(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x138(%rsp)
movq 0x30(%rax), %rax
movq %rax, 0x130(%rsp)
movq 0x148(%rsp), %rsi
movq 0x140(%rsp), %rdx
leaq 0x120(%rsp), %rdi
callq 0xd81b0
movq 0x38(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0xdae10
movq 0x38(%rsp), %rax
movq 0x38(%rax), %rdi
leaq 0x120(%rsp), %rsi
callq 0xd3bf0
movq %rax, 0x118(%rsp)
movq 0x118(%rsp), %rdi
callq 0xdbfb0
cmpl $0x2, %eax
je 0x11ba6a
movb $0x1, 0xf6(%rsp)
movl $0x20, %edi
callq 0xd2b40
movq %rax, 0x10(%rsp)
leaq 0xf7(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0xe0c80
movq 0x18(%rsp), %rdx
leaq 0x6cac0(%rip), %rsi     # 0x188483
leaq 0xf8(%rsp), %rdi
callq 0xe00a0
jmp 0x11b9d2
movq 0x10(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0xd1ae0
jmp 0x11b9e6
movq 0x10(%rsp), %rdi
movb $0x0, 0xf6(%rsp)
movq 0xac496(%rip), %rsi     # 0x1c7e90
movq 0xac1cf(%rip), %rdx     # 0x1c7bd0
callq 0xe01f0
jmp 0x11bb3e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x160(%rsp)
movl %eax, 0x15c(%rsp)
jmp 0x11ba42
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x160(%rsp)
movl %eax, 0x15c(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0xd4550
leaq 0xf7(%rsp), %rdi
callq 0xd8ec0
testb $0x1, 0xf6(%rsp)
jne 0x11ba5b
jmp 0x11ba65
movq 0x10(%rsp), %rdi
callq 0xd5400
jmp 0x11bb31
movq 0x118(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x138(%rsp), %rdi
callq 0xd4da0
movq 0x8(%rsp), %rsi
movq %rax, %rdx
leaq 0x50(%rsp), %rdi
callq 0xe2680
movq 0x38(%rsp), %rax
leaq 0x50(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x10(%rax), %rdi
callq 0xe07e0
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0xd81d0
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
movl 0x194(%rsp), %esi
callq 0xe0d30
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x11baf6
movq 0x38(%rsp), %rdi
movq 0x48(%rsp), %rsi
movl 0x194(%rsp), %edx
callq 0xde230
jmp 0x11bb0c
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl 0x194(%rsp), %edx
callq 0xd0740
movq 0x38(%rsp), %rax
movq 0x138(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x130(%rsp), %rcx
movq %rcx, 0x30(%rax)
addq $0x1a8, %rsp            # imm = 0x1A8
retq
movq 0x160(%rsp), %rdi
callq 0xe0be0
nop