// File: /workspace/github_cpp_makefile_star2_O3/jstaursky[P]hutch/src/Sleigh/slghsymbol.cc
// Function: DecisionNode::chooseOptimalField()
void DecisionNode::chooseOptimalField(void)

{
  double score = 0.0;
  
  int4 sbit,size;		// The current field
  bool context;
  double sc;

  int4 maxlength,numfixed,maxfixed;

  maxfixed = 1;
  context = true;
  do {
    maxlength = 8*getMaximumLength(context);
    for(sbit=0;sbit<maxlength;++sbit) {
      numfixed = getNumFixed(sbit,1,context); // How may patterns specify this bit
      if (numfixed < maxfixed) continue; // Skip this bit, if we don't have maximum specification
      sc = getScore(sbit,1,context);

 // if we got more patterns this time than previously, and a positive score, reset
 // the high score (we prefer this bit, because it has a higher numfixed, regardless
 // of the difference in score, as long as the new score is positive).
      if ((numfixed > maxfixed)&&(sc > 0.0)) {
	score = sc;
	maxfixed = numfixed;
	startbit = sbit;
	bitsize = 1;
	contextdecision = context;
	continue;
      }
				// We have maximum patterns
      if (sc > score) {
	score = sc;
	startbit = sbit;
	bitsize = 1;
	contextdecision = context;
      }
    }
    context = !context;
  } while(!context);

  context = true;
  do {
    maxlength = 8*getMaximumLength(context);
    for(size=2;size <= 8;++size) {
      for(sbit=0;sbit<maxlength-size+1;++sbit) {
	if (getNumFixed(sbit,size,context) < maxfixed) continue; // Consider only maximal fields
	sc = getScore(sbit,size,context);
	if (sc > score) {
	  score = sc;
	  startbit = sbit;
	  bitsize = size;
	  contextdecision = context;
	}
      }
    }
    context = !context;
  } while(!context);
  if (score <= 0.0)		// If we failed to get a positive score
    bitsize = 0;		// treat the node as terminal
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl $0x1, %r13d
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movb $0x1, %r15b
movzbl %r15b, %ebp
andl $0x1, %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x41480
testl %eax, %eax
movl %r15d, 0xc(%rsp)
je 0x6ca16
movl %eax, %r14d
shll $0x3, %r14d
movl %r15d, %eax
andb $0x1, %al
movb %al, 0x8(%rsp)
cmpl $0x1, %r14d
adcl $0x0, %r14d
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r15d, %esi
movl $0x1, %edx
movl %ebp, %ecx
callq 0x41590
cmpl %r13d, %eax
jl 0x6ca0e
movl %eax, %r12d
movq %rbx, %rdi
movl %r15d, %esi
movl $0x1, %edx
movl %ebp, %ecx
callq 0x41290
cmpl %r13d, %r12d
jle 0x6c9e8
ucomisd 0x1467a(%rip), %xmm0    # 0x81060
ja 0x6c9f3
ucomisd 0x10(%rsp), %xmm0
movl %r13d, %r12d
jbe 0x6ca0e
movl %r15d, 0x38(%rbx)
movl $0x1, 0x3c(%rbx)
movb 0x8(%rsp), %al
movb %al, 0x34(%rbx)
movsd %xmm0, 0x10(%rsp)
movl %r12d, %r13d
incl %r15d
cmpl %r15d, %r14d
jne 0x6c9ad
testb $0x1, 0xc(%rsp)
movl $0x0, %r15d
jne 0x6c974
movb $0x1, %al
movzbl %al, %r14d
movl %r14d, %esi
andl $0x1, %esi
movq %rbx, %rdi
callq 0x41480
andb $0x1, %r14b
leal -0x1(,%rax,8), %r12d
shll $0x3, %eax
movl %eax, 0xc(%rsp)
movl $0x2, %ebp
movl %r14d, 0x8(%rsp)
movzbl %r14b, %r14d
cmpl %ebp, 0xc(%rsp)
jb 0x6caae
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r15d, %esi
movl %ebp, %edx
movl %r14d, %ecx
callq 0x41590
cmpl %r13d, %eax
jl 0x6caa6
movq %rbx, %rdi
movl %r15d, %esi
movl %ebp, %edx
movl %r14d, %ecx
callq 0x41290
ucomisd 0x10(%rsp), %xmm0
jbe 0x6caa6
movl %r15d, 0x38(%rbx)
movl %ebp, 0x3c(%rbx)
movl 0x8(%rsp), %eax
movb %al, 0x34(%rbx)
movsd %xmm0, 0x10(%rsp)
incl %r15d
cmpl %r15d, %r12d
jne 0x6ca65
incl %ebp
decl %r12d
cmpl $0x9, %ebp
jne 0x6ca5c
xorl %eax, %eax
cmpb $0x0, 0x8(%rsp)
jne 0x6ca29
xorpd %xmm0, %xmm0
ucomisd 0x10(%rsp), %xmm0
jb 0x6cad8
movl $0x0, 0x3c(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop