// File: /workspace/github_cpp_makefile_star2_O1/jstaursky[P]hutch/src/Sleigh/slgh_compile.cc
// Function: ConsistencyChecker::findValidRule(Constructor*, std::map<unsigned long, ConsistencyChecker::OptimizeRecord, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, ConsistencyChecker::OptimizeRecord>>>&) const
ConsistencyChecker::OptimizeRecord *ConsistencyChecker::findValidRule(Constructor *ct,map<uintb,OptimizeRecord> &recs) const

{
  map<uintb,OptimizeRecord>::iterator iter;
  iter = recs.begin();
  while(iter != recs.end()) {
    OptimizeRecord &currec( (*iter).second );
    ++iter;
    if ((currec.writecount==1)&&(currec.readcount==1)&&(currec.readsection==currec.writesection)) {
      // Temporary must be read and written exactly once
      ConstructTpl *tpl;
      if (currec.readsection < 0)
	tpl = ct->getTempl();
      else
	tpl = ct->getNamedTempl(currec.readsection);
      const vector<OpTpl *> &ops( tpl->getOpvec() );
      const OpTpl *op = ops[ currec.readop ];
      if (currec.writeop >= currec.readop) // Read must come after write
	throw SleighError("Read of temporary before write");
      if (op->getOpcode() == CPUI_COPY) {
	bool saverecord = true;
	currec.opttype = 0;	// Read op is a COPY
	const VarnodeTpl *vn = op->getOut();
	for(int4 i=currec.writeop+1;i<currec.readop;++i) { // Check for interference between write and read
	  if (readWriteInterference(vn,ops[i],true)) {
	    saverecord = false;
	    break;
	  }
	}
	if (saverecord)
	  return &currec;
      }
      op = ops[ currec.writeop ];
      if (op->getOpcode() == CPUI_COPY) {
	bool saverecord = true;
	currec.opttype = 1;	// Write op is a COPY
	const VarnodeTpl *vn = op->getIn(0);
	for(int4 i=currec.writeop+1;i<currec.readop;++i) { // Check for interference between write and read
	  if (readWriteInterference(vn,ops[i],false)) {
	    saverecord = false;
	    break;
	  }
	}
	if (saverecord)
	  return &currec;
      }
    }
  }
  return (OptimizeRecord *)0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r12
movq %rsi, 0x20(%rsp)
movq 0x18(%rdx), %r13
addq $0x8, %r12
movq %r12, 0x18(%rsp)
cmpq %r12, %r13
je 0x2cba0
movq %r13, %rdi
callq 0xf270
movq %rax, %r15
cmpl $0x1, 0x34(%r13)
movb $0x1, %r14b
jne 0x2cb92
cmpl $0x1, 0x38(%r13)
jne 0x2cb92
movl 0x40(%r13), %esi
cmpl 0x3c(%r13), %esi
jne 0x2cb92
testl %esi, %esi
js 0x2caa1
movq 0x20(%rsp), %rdi
callq 0x4cf22
movq %rax, %rbp
jmp 0x2caaa
movq 0x20(%rsp), %rax
movq 0x60(%rax), %rbp
movslq 0x2c(%r13), %rax
movslq 0x28(%r13), %rcx
cmpl %eax, %ecx
jge 0x2cbbd
leaq 0x28(%r13), %rdx
movq %rdx, 0x10(%rsp)
movq 0x8(%rbp), %rdx
movq (%rdx,%rax,8), %rax
cmpl $0x1, 0x8(%rax)
jne 0x2cb26
movq %r15, (%rsp)
movl $0x0, 0x44(%r13)
movq (%rax), %r15
incq %rcx
movq %rcx, %rbx
movslq 0x2c(%r13), %r12
cmpq %r12, %rcx
jge 0x2cb0e
movq 0x8(%rbp), %rax
movq (%rax,%rbx,8), %rdx
movq %r15, %rsi
movl $0x1, %ecx
callq 0x2c732
leaq 0x1(%rbx), %rcx
testb %al, %al
je 0x2cae3
jmp 0x2cb18
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq %r12, %rbx
movq (%rsp), %r15
jge 0x2cb7a
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %rax
movslq (%rax), %rbx
movq 0x8(%rbp), %rax
movq (%rax,%rbx,8), %rax
cmpl $0x1, 0x8(%rax)
jne 0x2cb92
movq %r15, (%rsp)
movl $0x1, 0x44(%r13)
movq 0x10(%rax), %rax
movq (%rax), %r15
incq %rbx
movslq 0x2c(%r13), %rax
cmpq %rax, %rbx
setl %r14b
jge 0x2cb84
movq 0x8(%rbp), %rax
movq (%rax,%rbx,8), %rdx
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x2c732
incq %rbx
testb %al, %al
je 0x2cb52
jmp 0x2cb8e
xorl %r14d, %r14d
movq 0x18(%rsp), %r12
jmp 0x2cb92
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movq (%rsp), %r15
movq %r15, %r13
testb %r14b, %r14b
jne 0x2ca53
jmp 0x2cba9
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x20, %edi
callq 0xf1b0
movq %rax, %rbx
leaq 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x35440(%rip), %rsi     # 0x6201a
leaq 0x35457(%rip), %rdx     # 0x62038
leaq 0x28(%rsp), %rdi
callq 0x1183c
movb $0x1, %bpl
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x117dc
xorl %ebp, %ebp
leaq 0x5d8ac(%rip), %rsi     # 0x8a4b0
leaq -0x1b3eb(%rip), %rdx    # 0x11820
movq %rbx, %rdi
callq 0xf6d0
movq %rax, %r14
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x2cc35
movq 0x38(%rsp), %rsi
incq %rsi
callq 0xf380
jmp 0x2cc35
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x2cc42
movq %rbx, %rdi
callq 0xf290
movq %r14, %rdi
callq 0xf730