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

  long int i;         /* index variable used for looping */
  long int size;      /* track the size of the matrix    */
  long int mindex = 0;/* track the index to the minimum  */
  float curval;       /* track value of current transformed distance  */
  float vmin;         /* the index to the smallest "vertical" minimum */

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

  /* values used in stochastically breaking ties */
  float p, x;
  long int smallcnt;

  /* initialize the vertical min to something really big */
  vmin = (float)HUGE_VAL;

  /* save off some values to limit dereferencing later */
  r2       = dmat->r2;
  val      = dmat->val;
  size     = dmat->size;

  p        = 1.0;
  smallcnt = 0;

  /* start on the first row and work down */
  ptr = &(val[NJ_MAP(0, a, size)]);  
  for(i=0;i<a;i++) {

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

      p = 1.0/(float)smallcnt;
      x = genrand_real2();

      /* break ties stochastically to avoid systematic bias */
      if( x < p ) {
	mindex = i;
      }

    } else if (curval < vmin) {

      smallcnt = 1;
      vmin = curval;
      mindex = i;
    }

    /* increment our working pointer to the next row down */
    ptr += size-i-1;
  }

  /* pass back the index to the minimum found so far (by reference) */
  *min = mindex;
  
  /* pass back the number of minima along the vertical */
  *vmincount = smallcnt;

  /* return the value of the smallest transformed distance */
  return(vmin);
}

// 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)
movq $0x0, -0x38(%rbp)
movss 0x6ba8(%rip), %xmm0     # 0xb020
movss %xmm0, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movss 0x6b7f(%rip), %xmm0     # 0xb028
movss %xmm0, -0x5c(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
xorl %eax, %eax
movl %eax, %edi
callq 0x4b70
movq %rax, %rcx
movq -0x70(%rbp), %rax
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x10(%rbp), %rax
jge 0x45dc
movq -0x48(%rbp), %rax
movss (%rax), %xmm0
movq -0x50(%rbp), %rax
movq -0x28(%rbp), %rcx
movss (%rax,%rcx,4), %xmm1
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
addss (%rax,%rcx,4), %xmm1
subss %xmm1, %xmm0
movss %xmm0, -0x3c(%rbp)
movss -0x3c(%rbp), %xmm0
movss -0x40(%rbp), %xmm1
callq 0x4600
cmpl $0x0, %eax
je 0x4588
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
cvtsi2ssq -0x68(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x6ab4(%rip), %xmm0     # 0xb008
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x5c(%rbp)
callq 0x9320
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x60(%rbp)
movss -0x60(%rbp), %xmm1
movss -0x5c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x4586
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x45b3
movss -0x3c(%rbp), %xmm1
movss -0x40(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x45b1
movq $0x1, -0x68(%rbp)
movss -0x3c(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x45b3
movq -0x30(%rbp), %rax
subq -0x28(%rbp), %rax
subq $0x1, %rax
shlq $0x2, %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x44e9
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x68(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movss -0x40(%rbp), %xmm0
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)