// File: /workspace/github_c_makefile_star2_O0/sheneman[P]clearcut/clearcut.c
// Function: NJ_find_hmin
static inline
float
NJ_find_hmin(DMAT *dmat,
	     long int a,
	     long int *min,
	     long int *hmincount) {

  long int i;     /* index variable for looping                    */
  int size;       /* current size of distance matrix               */
  int mindex = 0; /* holds the current index to the chosen minimum */
  float curval;   /* used to hold current transformed values       */
  float hmin;     /* the value of the transformed minimum          */

  float *ptr, *r2, *val;  /* pointers used to reduce dereferencing in inner loop */

  /* values used for stochastic selection among multiple minima */
  float p, x;  
  long int smallcnt;

  /* initialize the min to something large */
  hmin = (float)HUGE_VAL;

  /* setup some pointers to limit dereferencing later */
  r2       = dmat->r2;
  val      = dmat->val;
  size     = dmat->size;

  /* initialize values associated with minima tie breaking */
  p        = 1.0;
  smallcnt = 0;
  
  
  ptr = &(val[NJ_MAP(a, a+1, size)]);   /* at the start of the horiz. part */
  for(i=a+1;i<size;i++) {

    curval = *(ptr++) - (r2[a] + r2[i]);  /* compute transformed distance */
    
    if(NJ_FLT_EQ(curval, hmin)) {  /* approx. equal */
      
      smallcnt++;

      p = 1.0/(float)smallcnt;
      x = genrand_real2();
      
      /* select this minimum in a way which is proportional to 
	 the number of minima found along the row so far */
      if( x < p ) {
	mindex = i;
      }

    } else if (curval < hmin) {

      smallcnt = 1;
      hmin = curval;
      mindex = i;
    }
  }
  
  /* save off the the minimum index to be returned via reference */
  *min = mindex;
  
  /* save off the number of minima */
  *hmincount = smallcnt;
  
  /* return the value of the smallest tranformed distance */
  return(hmin);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x30(%rbp)
movss 0x6d59(%rip), %xmm0     # 0xb020
movss %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, -0x2c(%rbp)
movss 0x6d31(%rip), %xmm0     # 0xb028
movss %xmm0, -0x54(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x1, %rsi
movslq -0x2c(%rbp), %rdx
callq 0x4b70
movq %rax, %rcx
movq -0x68(%rbp), %rax
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cmpq %rcx, %rax
jge 0x4428
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x40(%rbp)
movss (%rax), %xmm0
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
movss (%rax,%rcx,4), %xmm1
movq -0x48(%rbp), %rax
movq -0x28(%rbp), %rcx
addss (%rax,%rcx,4), %xmm1
subss %xmm1, %xmm0
movss %xmm0, -0x34(%rbp)
movss -0x34(%rbp), %xmm0
movss -0x38(%rbp), %xmm1
callq 0x4600
cmpl $0x0, %eax
je 0x43eb
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
cvtsi2ssq -0x60(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x6c50(%rip), %xmm0     # 0xb008
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x54(%rbp)
callq 0x9320
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x58(%rbp), %xmm1
movss -0x54(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x43e9
movq -0x28(%rbp), %rax
movl %eax, -0x30(%rbp)
jmp 0x4415
movss -0x34(%rbp), %xmm1
movss -0x38(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x4413
movq $0x1, -0x60(%rbp)
movss -0x34(%rbp), %xmm0
movss %xmm0, -0x38(%rbp)
movq -0x28(%rbp), %rax
movl %eax, -0x30(%rbp)
jmp 0x4415
jmp 0x4417
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x433f
movslq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movss -0x38(%rbp), %xmm0
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)