// File: jstaursky[P]hutch/src/Sleigh/slgh_compile.cc
// Function: ConsistencyChecker::applyOptimization(Constructor*, ConsistencyChecker::OptimizeRecord const&)
void ConsistencyChecker::applyOptimization(Constructor *ct,const OptimizeRecord &rec)

{
  vector<int4> deleteops;
  ConstructTpl *ctempl;
  if (rec.readsection < 0)
    ctempl = ct->getTempl();
  else
    ctempl = ct->getNamedTempl(rec.readsection);
  
  if (rec.opttype == 0) { // If read op is COPY
    int4 readop = rec.readop;
    OpTpl *op = ctempl->getOpvec()[ readop ];
    VarnodeTpl *vnout = new VarnodeTpl(*op->getOut()); // Make COPY output
    ctempl->setOutput(vnout,rec.writeop); // become write output
    deleteops.push_back(readop); // and then delete the read (COPY)
  }
  else if (rec.opttype == 1) { // If write op is COPY
    int4 writeop = rec.writeop;
    OpTpl *op = ctempl->getOpvec()[ writeop ];
    VarnodeTpl *vnin = new VarnodeTpl(*op->getIn(0));	// Make COPY input
    ctempl->setInput(vnin,rec.readop,rec.inslot); // become read input
    deleteops.push_back(writeop); // and then delete the write (COPY)
  }
  ctempl->deleteOps(deleteops);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x6a7f0
movq -0x18(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jge 0x5fb44
movq -0x10(%rbp), %rdi
callq 0x52880
movq %rax, -0x78(%rbp)
jmp 0x5fb29
movq -0x78(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x5fb62
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5fd26
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x18(%rax), %esi
callq 0xaa8d0
movq %rax, -0x80(%rbp)
jmp 0x5fb5a
movq -0x80(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x5fc33
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x38(%rbp), %rdi
callq 0x3fd80
movq %rax, -0x88(%rbp)
jmp 0x5fb8c
movq -0x88(%rbp), %rdi
movslq -0x48(%rbp), %rsi
callq 0x3fc80
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movl $0x68, %edi
callq 0x11440
movq %rax, -0x90(%rbp)
jmp 0x5fbb6
movq -0x50(%rbp), %rdi
callq 0x3f7a0
movq %rax, -0x98(%rbp)
jmp 0x5fbc8
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdi
callq 0x4bb20
jmp 0x5fbdd
movq -0x90(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x18(%rbp), %rax
movl (%rax), %edx
callq 0x4d4a0
jmp 0x5fbfd
leaq -0x30(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x6ad80
jmp 0x5fc0c
jmp 0x5fd05
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x68, %esi
callq 0x11450
jmp 0x5fd26
movq -0x18(%rbp), %rax
cmpl $0x1, 0x1c(%rax)
jne 0x5fd03
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x38(%rbp), %rdi
callq 0x3fd80
movq %rax, -0xa0(%rbp)
jmp 0x5fc5c
movq -0xa0(%rbp), %rdi
movslq -0x5c(%rbp), %rsi
callq 0x3fc80
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movl $0x68, %edi
callq 0x11440
movq %rax, -0xa8(%rbp)
jmp 0x5fc86
movq -0x68(%rbp), %rdi
xorl %esi, %esi
callq 0x3fce0
movq %rax, -0xb0(%rbp)
jmp 0x5fc9a
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdi
callq 0x4bb20
jmp 0x5fcaf
movq -0xa8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edx
movl 0x8(%rax), %ecx
callq 0x4d420
jmp 0x5fcd3
leaq -0x30(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
callq 0x6ad80
jmp 0x5fce2
jmp 0x5fd03
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x68, %esi
callq 0x11450
jmp 0x5fd26
jmp 0x5fd05
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4d510
jmp 0x5fd14
leaq -0x30(%rbp), %rdi
callq 0x6a9d0
addq $0xb0, %rsp
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x6a9d0
movq -0x40(%rbp), %rdi
callq 0x118b0
nopl (%rax,%rax)