// File: /workspace/github_c_makefile_star2_O3/sc932[P]ALE/src/ALElike.c
// Function: getPlacementWinner
alignSet_t *getPlacementWinner(alignSet_t *head, double likeNormalizer, int *winner) {
  assert(head != NULL && winner != NULL);
  assert(head->likelihood >= 0.0);

  *winner = -1;
  if(likeNormalizer == 0.0){ // no real placement
    return NULL;
  }

  // instead of purely random choice, choose a consistent, but still random choice
  unsigned int iseed = JSHash(head->name);
  srand(iseed); // instead of: srand ((unsigned int) time(NULL));

  double tRand = ( likeNormalizer * rand() / ( RAND_MAX + 1.0 ) );
  double soFar = 0.0;

  int i = 0;
  alignSet_t *current = head;
  if(head->likelihood*head->likelihoodInsert > tRand){
    *winner = 0;
  }else{
    assert(head->likelihood >= 0.0);
    soFar += head->likelihood*head->likelihoodInsert;
    while(current->nextAlignment != NULL){
      current = current->nextAlignment;
      assert(current->likelihood >= 0.0);
      i++;
      if(current->likelihood*current->likelihoodInsert + soFar > tRand){
        *winner = i;
        break;
      }else{
        soFar += current->likelihood*current->likelihoodInsert;
      }
    }
  }
  assert(current->likelihood >= 0.0);
  if(current->likelihood*current->likelihoodInsert > 0.0){
    return current;
  }else{ // not a real placement
    return NULL;
  }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x7440
movq %rsi, %r14
testq %rsi, %rsi
je 0x7440
movq %rdi, %rbx
movsd (%rdi), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
jb 0x745f
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
ucomisd %xmm2, %xmm0
jne 0x7345
jp 0x7345
xorl %eax, %eax
jmp 0x7419
movq 0x28(%rbx), %rax
movl $0x4e67c6a7, %edi       # imm = 0x4E67C6A7
testq %rax, %rax
movsd %xmm0, (%rsp)
je 0x737d
movb (%rax), %cl
testb %cl, %cl
je 0x737d
incq %rax
movsbl %cl, %ecx
movl %edi, %edx
shll $0x5, %edx
movl %edi, %esi
shrl $0x2, %esi
addl %edx, %esi
addl %ecx, %esi
xorl %esi, %edi
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x7361
callq 0x32e0
callq 0x3690
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd (%rsp), %xmm1
mulsd 0x166b5(%rip), %xmm1    # 0x1da50
movsd (%rbx), %xmm0
movsd 0x8(%rbx), %xmm2
mulsd %xmm0, %xmm2
xorl %eax, %eax
ucomisd %xmm1, %xmm2
jbe 0x73b5
movl %eax, (%r14)
jmp 0x7400
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm0
jb 0x749d
movq 0x48(%rbx), %rcx
testq %rcx, %rcx
je 0x7400
addsd %xmm3, %xmm2
movl $0x1, %eax
movsd (%rcx), %xmm0
ucomisd %xmm3, %xmm0
jb 0x7421
movq %rcx, %rbx
movsd 0x8(%rcx), %xmm4
mulsd %xmm0, %xmm4
addsd %xmm4, %xmm2
ucomisd %xmm1, %xmm2
ja 0x73b0
movq 0x48(%rbx), %rcx
incl %eax
testq %rcx, %rcx
jne 0x73d5
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x747e
mulsd 0x8(%rbx), %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
cmovaq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
leaq 0x1ad46(%rip), %rdi     # 0x2216e
leaq 0x1a936(%rip), %rsi     # 0x21d65
leaq 0x1ace4(%rip), %rcx     # 0x2211a
movl $0x433, %edx            # imm = 0x433
callq 0x3230
leaq 0x1acb4(%rip), %rdi     # 0x220fb
leaq 0x1a917(%rip), %rsi     # 0x21d65
leaq 0x1acc5(%rip), %rcx     # 0x2211a
movl $0x41b, %edx            # imm = 0x41B
callq 0x3230
leaq 0x1acf0(%rip), %rdi     # 0x22156
leaq 0x1a8f8(%rip), %rsi     # 0x21d65
leaq 0x1aca6(%rip), %rcx     # 0x2211a
movl $0x41c, %edx            # imm = 0x41C
callq 0x3230
leaq 0x1ace9(%rip), %rdi     # 0x2216e
leaq 0x1a8d9(%rip), %rsi     # 0x21d65
leaq 0x1ac87(%rip), %rcx     # 0x2211a
movl $0x43d, %edx            # imm = 0x43D
callq 0x3230
leaq 0x1acb2(%rip), %rdi     # 0x22156
leaq 0x1a8ba(%rip), %rsi     # 0x21d65
leaq 0x1ac68(%rip), %rcx     # 0x2211a
movl $0x42f, %edx            # imm = 0x42F
callq 0x3230