// File: /workspace/github_cpp_makefile_star2_O1/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, 0x8(%rsp)
movb $0x1, %al
movq %rax, (%rsp)
movzbl %al, %ebp
andl $0x1, %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x41470
testl %eax, %eax
je 0x6cce4
movl %eax, %r14d
shll $0x3, %r14d
cmpl $0x1, %r14d
adcl $0x0, %r14d
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r15d, %esi
movl $0x1, %edx
movl %ebp, %ecx
callq 0x41580
cmpl %r13d, %eax
jl 0x6ccdc
movl %eax, %r12d
movq %rbx, %rdi
movl %r15d, %esi
movl $0x1, %edx
movl %ebp, %ecx
callq 0x41280
cmpl %r13d, %r12d
jle 0x6ccb6
ucomisd 0x143ac(%rip), %xmm0    # 0x81060
ja 0x6ccc1
ucomisd 0x8(%rsp), %xmm0
movl %r13d, %r12d
jbe 0x6ccdc
movl %r15d, 0x38(%rbx)
movl $0x1, 0x3c(%rbx)
movq (%rsp), %rax
movb %al, 0x34(%rbx)
movsd %xmm0, 0x8(%rsp)
movl %r12d, %r13d
incl %r15d
cmpl %r15d, %r14d
jne 0x6cc7b
movq (%rsp), %rcx
leal -0x1(%rcx), %eax
testb $0x1, %cl
jne 0x6cc51
movb $0x1, %al
movq %rax, (%rsp)
movzbl %al, %ebp
andl $0x1, %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x41470
leal -0x1(,%rax,8), %r12d
shll $0x3, %eax
movl %eax, 0x14(%rsp)
movl $0x2, %r14d
cmpl %r14d, 0x14(%rsp)
jb 0x6cd73
xorl %r15d, %r15d
movq %rbx, %rdi
movl %r15d, %esi
movl %r14d, %edx
movl %ebp, %ecx
callq 0x41580
cmpl %r13d, %eax
jl 0x6cd6b
movq %rbx, %rdi
movl %r15d, %esi
movl %r14d, %edx
movl %ebp, %ecx
callq 0x41280
ucomisd 0x8(%rsp), %xmm0
jbe 0x6cd6b
movl %r15d, 0x38(%rbx)
movl %r14d, 0x3c(%rbx)
movq (%rsp), %rax
movb %al, 0x34(%rbx)
movsd %xmm0, 0x8(%rsp)
incl %r15d
cmpl %r15d, %r12d
jne 0x6cd29
incl %r14d
decl %r12d
cmpl $0x9, %r14d
jne 0x6cd1f
movq (%rsp), %rcx
leal -0x1(%rcx), %eax
testb $0x1, %cl
jne 0x6ccf6
xorpd %xmm0, %xmm0
ucomisd 0x8(%rsp), %xmm0
jb 0x6cda2
movl $0x0, 0x3c(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop