// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x1
popq %r13
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movb $0x1, %al
pushq $0x1
popq %rbp
movzbl %al, %r12d
movl %r12d, %esi
andl $0x1, %esi
movq %rbx, %rdi
callq 0x50950
movl %eax, %r14d
andb $0x1, %r12b
shll $0x3, %r14d
xorl %r15d, %r15d
movl %r12d, 0x4(%rsp)
movzbl %r12b, %r12d
cmpl %r15d, %r14d
je 0x75384
movq %rbx, %rdi
movl %r15d, %esi
movl %ebp, %edx
movl %r12d, %ecx
callq 0x50af0
cmpl %r13d, %eax
jl 0x7537c
movl %ebp, %edx
movl %eax, %ebp
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %ecx
callq 0x506c0
cmpl %r13d, %ebp
jle 0x75356
ucomisd 0x12cdc(%rip), %xmm0    # 0x88030
ja 0x75361
ucomisd 0x8(%rsp), %xmm0
movl %r13d, %ebp
jbe 0x7537c
movl %r15d, 0x38(%rbx)
movl $0x1, 0x3c(%rbx)
movl 0x4(%rsp), %eax
movb %al, 0x34(%rbx)
movsd %xmm0, 0x8(%rsp)
movl %ebp, %r13d
incl %r15d
pushq $0x1
popq %rbp
jmp 0x7531b
xorl %eax, %eax
cmpb $0x0, 0x4(%rsp)
jne 0x752f2
movb $0x1, %al
movzbl %al, %ebp
movl %ebp, %esi
andl $0x1, %esi
movq %rbx, %rdi
callq 0x50950
andb $0x1, %bpl
shll $0x3, %eax
movl %eax, 0x14(%rsp)
movl %ebp, 0x4(%rsp)
movzbl %bpl, %r14d
pushq $0x2
popq %r15
cmpl $0x9, %r15d
je 0x7541d
movl 0x14(%rsp), %ebp
subl %r15d, %ebp
xorl %r12d, %r12d
cmpl %ebp, %r12d
jg 0x75418
movq %rbx, %rdi
movl %r12d, %esi
movl %r15d, %edx
movl %r14d, %ecx
callq 0x50af0
cmpl %r13d, %eax
jl 0x75413
movq %rbx, %rdi
movl %r12d, %esi
movl %r15d, %edx
movl %r14d, %ecx
callq 0x506c0
ucomisd 0x8(%rsp), %xmm0
jbe 0x75413
movl %r12d, 0x38(%rbx)
movl %r15d, 0x3c(%rbx)
movl 0x4(%rsp), %eax
movb %al, 0x34(%rbx)
movsd %xmm0, 0x8(%rsp)
incl %r12d
jmp 0x753ca
incl %r15d
jmp 0x753ba
xorl %eax, %eax
cmpb $0x0, 0x4(%rsp)
jne 0x75393
xorpd %xmm0, %xmm0
ucomisd 0x8(%rsp), %xmm0
jb 0x7543a
andl $0x0, 0x3c(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop