// File: jstaursky[P]hutch/src/Sleigh/semantics.cc
// Function: ConstructTpl::fillinBuild(std::vector<int, std::allocator<int>>&, AddrSpace*)
int4 ConstructTpl::fillinBuild(vector<int4> &check,AddrSpace *const_space)

{ // Make sure there is a build statement for all subtable params
  // Return 0 upon success, 1 if there is a duplicate BUILD, 2 if there is a build for a non-subtable
  vector<OpTpl *>::iterator iter;
  OpTpl *op;
  VarnodeTpl *indvn;

  for(iter=vec.begin();iter!=vec.end();++iter) {
    op = *iter;
    if (op->getOpcode() == BUILD) {
      int4 index = op->getIn(0)->getOffset().getReal();
      if (check[index] != 0)
	return check[index];	// Duplicate BUILD statement or non-subtable
      check[index] = 1;		// Mark to avoid future duplicate build
    }
  }
  for(int4 i=0;i<check.size();++i) {
    if (check[i] == 0) {	// Didn't see a BUILD statement
      op = new OpTpl(BUILD);
      indvn = new VarnodeTpl(ConstTpl(const_space),
			      ConstTpl(ConstTpl::real,i),
			      ConstTpl(ConstTpl::real,4));
      op->addInput(indvn);
      vec.insert(vec.begin(),op);
    }
  }
  return 0;
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0xf8(%rsp)
movq %rsi, 0xf0(%rsp)
movq %rdx, 0xe8(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0xcf8f0
movq 0x28(%rsp), %rdi
addq $0x8, %rdi
callq 0xd1660
movq %rax, 0xc8(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0x28(%rsp), %rdi
addq $0x8, %rdi
callq 0xdcb70
movq %rax, 0xc0(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0xd92e0
testb $0x1, %al
jne 0x118043
jmp 0x1180ff
leaq 0xe0(%rsp), %rdi
callq 0xce980
movq (%rax), %rax
movq %rax, 0xd8(%rsp)
movq 0xd8(%rsp), %rdi
callq 0xe2420
cmpl $0x3c, %eax
jne 0x1180eb
movq 0xd8(%rsp), %rdi
xorl %esi, %esi
callq 0xd3b80
movq %rax, %rdi
callq 0xdbaf0
movq %rax, %rdi
callq 0xdd890
movl %eax, 0xbc(%rsp)
movq 0xf0(%rsp), %rdi
movslq 0xbc(%rsp), %rsi
callq 0xd2680
cmpl $0x0, (%rax)
je 0x1180d0
movq 0xf0(%rsp), %rdi
movslq 0xbc(%rsp), %rsi
callq 0xd2680
movl (%rax), %eax
movl %eax, 0x104(%rsp)
jmp 0x1182c9
movq 0xf0(%rsp), %rdi
movslq 0xbc(%rsp), %rsi
callq 0xd2680
movl $0x1, (%rax)
jmp 0x1180ed
leaq 0xe0(%rsp), %rdi
callq 0xd52f0
jmp 0x11800f
movl $0x0, 0xb8(%rsp)
movslq 0xb8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xf0(%rsp), %rdi
callq 0xe30e0
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0x1182be
movq 0xf0(%rsp), %rdi
movslq 0xb8(%rsp), %rsi
callq 0xd2680
cmpl $0x0, (%rax)
jne 0x1182a6
movl $0x28, %edi
callq 0xd8380
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
movl $0x3c, %esi
callq 0xcf490
jmp 0x118174
movq 0x18(%rsp), %rax
movq %rax, 0xd8(%rsp)
movl $0x68, %edi
callq 0xd8380
movq %rax, 0x10(%rsp)
movq 0xe8(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0xd69a0
jmp 0x1181a7
movslq 0xb8(%rsp), %rdx
leaq 0x68(%rsp), %rdi
xorl %esi, %esi
callq 0xd9880
jmp 0x1181bd
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0xd9880
jmp 0x1181d0
movq 0x10(%rsp), %rdi
leaq 0x88(%rsp), %rsi
leaq 0x68(%rsp), %rdx
leaq 0x48(%rsp), %rcx
callq 0xdf370
jmp 0x1181ee
movq 0x10(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0xd8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
callq 0xe1280
movq 0x28(%rsp), %rdi
movq %rdi, %rax
addq $0x8, %rax
movq %rax, 0x8(%rsp)
addq $0x8, %rdi
callq 0xd1660
movq %rax, 0x38(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0xd90f0
movq 0x8(%rsp), %rdi
movq 0x40(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
callq 0xd3310
movq %rax, 0x30(%rsp)
jmp 0x1182a6
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
movl $0x28, %esi
callq 0xd8620
jmp 0x1182d8
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
movl $0x68, %esi
callq 0xd8620
jmp 0x1182d8
jmp 0x1182a8
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x11810a
movl $0x0, 0x104(%rsp)
movl 0x104(%rsp), %eax
addq $0x108, %rsp            # imm = 0x108
retq
movq 0xb0(%rsp), %rdi
callq 0xe0be0
nopw %cs:(%rax,%rax)