// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %rdx, %rbx
movq %rsi, 0x10(%rsp)
movq 0x18(%rdx), %r15
addq $0x8, %rbx
cmpq %rbx, %r15
je 0x2c94f
movq %r15, %rdi
callq 0xf270
movq %rax, %r12
cmpl $0x1, 0x34(%r15)
jne 0x2c943
cmpl $0x1, 0x38(%r15)
jne 0x2c943
movl 0x40(%r15), %esi
cmpl 0x3c(%r15), %esi
jne 0x2c943
testl %esi, %esi
js 0x2c891
movq 0x10(%rsp), %rdi
callq 0x4cae0
movq %rax, %r13
jmp 0x2c89a
movq 0x10(%rsp), %rax
movq 0x60(%rax), %r13
movslq 0x2c(%r15), %rdx
movl 0x28(%r15), %eax
cmpl %edx, %eax
jge 0x2c967
leaq 0x28(%r15), %rsi
movq 0x8(%r13), %rcx
movq (%rcx,%rdx,8), %rdx
cmpl $0x1, 0x8(%rdx)
movq %rsi, 0x8(%rsp)
jne 0x2c902
movslq %eax, %rbp
movl $0x0, 0x44(%r15)
movq (%rdx), %r14
incq %rbp
movslq 0x2c(%r15), %rax
cmpq %rax, %rbp
jge 0x2c953
movq 0x8(%r13), %rax
movq (%rax,%rbp,8), %rdx
movq %r14, %rsi
movl $0x1, %ecx
callq 0x2c560
incq %rbp
testb %al, %al
je 0x2c8d2
movq 0x8(%rsp), %rax
movl (%rax), %eax
movq 0x8(%r13), %rcx
movslq %eax, %rbp
movq (%rcx,%rbp,8), %rax
cmpl $0x1, 0x8(%rax)
jne 0x2c943
movl $0x1, 0x44(%r15)
movq 0x10(%rax), %rax
movq (%rax), %r14
incq %rbp
movslq 0x2c(%r15), %rax
cmpq %rax, %rbp
jge 0x2c953
movq 0x8(%r13), %rax
movq (%rax,%rbp,8), %rdx
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x2c560
incq %rbp
testb %al, %al
je 0x2c921
movq %r12, %r15
cmpq %rbx, %r12
jne 0x2c84f
xorl %eax, %eax
jmp 0x2c958
movq 0x8(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x20, %edi
callq 0xf1b0
movq %rax, %rbx
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x356e6(%rip), %rsi     # 0x6206a
leaq 0x356fd(%rip), %rdx     # 0x62088
leaq 0x18(%rsp), %rdi
callq 0x117f6
movb $0x1, %bpl
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x11796
xorl %ebp, %ebp
leaq 0x5dba2(%rip), %rsi     # 0x8a550
leaq -0x1b1db(%rip), %rdx    # 0x117da
movq %rbx, %rdi
callq 0xf6d0
movq %rax, %r14
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x2c9d7
movq 0x28(%rsp), %rsi
incq %rsi
callq 0xf380
testb %bpl, %bpl
jne 0x2c9e1
jmp 0x2c9e9
movq %rax, %r14
movq %rbx, %rdi
callq 0xf290
movq %r14, %rdi
callq 0xf730
nop