// File: jstaursky[P]hutch/src/Sleigh/globalcontext.cc
// Function: ContextInternal::restoreContext(Element const*, Address const&, Address const&)
void ContextInternal::restoreContext(const Element *el,const Address &addr1,const Address &addr2)

{
  const List &list(el->getChildren());
  List::const_iterator iter = list.begin();

  while(iter != list.end()) {
    const Element *subel = *iter;
    istringstream s(subel->getAttributeValue("val"));
    s.unsetf(ios::dec | ios::hex | ios::oct);
    uintm val;
    s >> val;
    ContextBitRange &var(getVariable(subel->getAttributeValue("name")));
    vector<uintm *> vec;
    if (addr1.isInvalid()) {		// Invalid addr1, indicates we should set default value
      uintm *defaultBuffer = getDefaultValue();
      for(int4 i=0;i<size;++i)
	defaultBuffer[i] = 0;
      vec.push_back(defaultBuffer);
    }
    else
      getRegionForSet(vec,addr1,addr2,var.getWord(),var.getMask()<<var.getShift());
    for(int4 i=0;i<vec.size();++i)
      var.setValue(vec[i],val);
    ++iter;
  }
}

// Assembly:
subq $0x2e8, %rsp            # imm = 0x2E8
movq %rdi, 0x2e0(%rsp)
movq %rsi, 0x2d8(%rsp)
movq %rdx, 0x2d0(%rsp)
movq %rcx, 0x2c8(%rsp)
movq 0x2e0(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x2d8(%rsp), %rdi
callq 0xde930
movq %rax, 0x2c0(%rsp)
movq 0x2c0(%rsp), %rdi
callq 0xd4960
movq %rax, 0x2b8(%rsp)
movq 0x2c0(%rsp), %rdi
callq 0xd7a70
movq %rax, 0x2b0(%rsp)
leaq 0x2b8(%rsp), %rdi
leaq 0x2b0(%rsp), %rsi
callq 0xd72b0
testb $0x1, %al
jne 0xebc64
jmp 0xec0de
leaq 0x2b8(%rsp), %rdi
callq 0xddc90
movq (%rax), %rax
movq %rax, 0x2a8(%rsp)
movq 0x2a8(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x107(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0xe0c80
movq 0x88(%rsp), %rdx
leaq 0x9b531(%rip), %rsi     # 0x1871e1
leaq 0x108(%rsp), %rdi
callq 0xe00a0
jmp 0xebcbf
movq 0x80(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0xdb6f0
movq %rax, 0x78(%rsp)
jmp 0xebcdb
movq 0x78(%rsp), %rsi
leaq 0x128(%rsp), %rdi
movl $0x8, %edx
callq 0xdfcc0
jmp 0xebcf4
leaq 0x108(%rsp), %rdi
callq 0xd4550
leaq 0x107(%rsp), %rdi
callq 0xd8ec0
movq 0x128(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x128(%rsp,%rax), %rax
movq %rax, 0x68(%rsp)
movl $0x2, %edi
movl $0x8, %esi
callq 0xe0e70
movl %eax, 0x74(%rsp)
jmp 0xebd3c
movl 0x74(%rsp), %edi
movl $0x40, %esi
callq 0xe0e70
movl %eax, 0x64(%rsp)
jmp 0xebd50
movl 0x64(%rsp), %esi
movq 0x68(%rsp), %rdi
callq 0xda6e0
jmp 0xebd60
leaq 0x128(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0xceae0
jmp 0xebd77
movq 0x2a8(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0xc7(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0xe0c80
movq 0x58(%rsp), %rdx
leaq 0x9b28f(%rip), %rsi     # 0x187031
leaq 0xc8(%rsp), %rdi
callq 0xe00a0
jmp 0xebdb1
movq 0x50(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0xdb6f0
movq %rax, 0x48(%rsp)
jmp 0xebdca
movq 0x48(%rsp), %rsi
movq 0x90(%rsp), %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movq %rax, 0x40(%rsp)
jmp 0xebde6
leaq 0xc8(%rsp), %rdi
callq 0xd4550
leaq 0xc7(%rsp), %rdi
callq 0xd8ec0
movq 0x40(%rsp), %rax
movq %rax, 0xe8(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0xd3f20
movq 0x2d0(%rsp), %rdi
callq 0xce5a0
movb %al, 0x3f(%rsp)
jmp 0xebe2d
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0xebe3a
jmp 0xebf99
movq 0x90(%rsp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movq %rax, 0x30(%rsp)
jmp 0xebe52
movq 0x30(%rsp), %rax
movq %rax, 0xa0(%rsp)
movl $0x0, 0x9c(%rsp)
movq 0x90(%rsp), %rcx
movl 0x9c(%rsp), %eax
cmpl 0x8(%rcx), %eax
jge 0xebf7d
movq 0xa0(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0xebe6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
jmp 0xebee3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0x108(%rsp), %rdi
callq 0xd4550
leaq 0x107(%rsp), %rdi
callq 0xd8ec0
jmp 0xec0e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
jmp 0xec0cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
jmp 0xebf45
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0xd4550
leaq 0xc7(%rsp), %rdi
callq 0xd8ec0
jmp 0xec0cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf8(%rsp)
movl %eax, 0xf4(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0xdd240
jmp 0xec0cf
leaq 0xa8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xd0fc0
jmp 0xebf94
jmp 0xec026
movq 0x2d0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x2c8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xe8(%rsp), %rdi
callq 0xcf7a0
movl %eax, 0x2c(%rsp)
jmp 0xebfc6
movq 0xe8(%rsp), %rdi
callq 0xd3af0
movl %eax, 0x14(%rsp)
jmp 0xebfd9
movq 0xe8(%rsp), %rdi
callq 0xdf3e0
movl %eax, 0x10(%rsp)
jmp 0xebfec
movl 0x2c(%rsp), %r8d
movq 0x18(%rsp), %rdx
movq 0x90(%rsp), %rdi
movl 0x14(%rsp), %r9d
movl 0x10(%rsp), %eax
movb %al, %cl
shll %cl, %r9d
movq 0x20(%rsp), %rcx
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq 0xa8(%rsp), %rsi
callq *%rax
jmp 0xec024
jmp 0xec026
movl $0x0, 0x98(%rsp)
movslq 0x98(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0xce5b0
movq %rax, %rcx
movq 0x8(%rsp), %rax
cmpq %rcx, %rax
jae 0xec0a3
movq 0xe8(%rsp), %rax
movq %rax, (%rsp)
movslq 0x98(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
callq 0xdc850
movq (%rsp), %rdi
movq (%rax), %rsi
movl 0xf0(%rsp), %edx
callq 0xe17e0
jmp 0xec08e
jmp 0xec090
movl 0x98(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x98(%rsp)
jmp 0xec031
leaq 0x2b8(%rsp), %rdi
callq 0xd0700
leaq 0xa8(%rsp), %rdi
callq 0xdd240
leaq 0x128(%rsp), %rdi
callq 0xd25a0
jmp 0xebc31
leaq 0x128(%rsp), %rdi
callq 0xd25a0
jmp 0xec0e6
addq $0x2e8, %rsp            # imm = 0x2E8
retq
movq 0xf8(%rsp), %rdi
callq 0xe0be0
nopw %cs:(%rax,%rax)