// File: /workspace/github_c_makefile_star2_O0/PoulinV[P]AxiCLASS/build/../tools/quadrature.c
// Function: sort_x_and_w
int sort_x_and_w(double *x, double *w, double *workx, double *workw, int startidx, int endidx){
  int i,top=endidx,bot=startidx;
  double pivot;
  /* End recursion if only one element left in array: */
  if ((endidx-startidx)<1){
    return _SUCCESS_;
  }
  else{
    /*Copy x and w to workarray: */
    for (i=startidx; i<=endidx; i++){
      workx[i] = x[i];
      workw[i] = w[i];
    }
    pivot = x[endidx];
    //printf("pivot chosen: x[%d] = %g\n",endidx,pivot);
    for (i=startidx; i<endidx; i++){
      if (workx[i]<=pivot){
	//printf("<--%g  ",workx[i]);
	x[bot] = workx[i];
	w[bot++] = workw[i];
      }
      else{
	//printf("  %g-->",workx[i]);
	x[top] = workx[i];
	w[top--] = workw[i];
      }
    }
    //printf("\n top=%d, bot=%d, left=%d, right=%d\n",top,bot,startidx,endidx);
    x[top] = pivot;
    w[top] = workw[endidx];
    /* Recursive call: */
    sort_x_and_w(x,w,workx,workw,startidx,bot-1);
    sort_x_and_w(x,w,workx,workw,top+1,endidx);
    return _SUCCESS_;
  }

}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movl %r8d, 0x1c(%rsp)
movl %r9d, 0x18(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0x18(%rsp), %eax
subl 0x1c(%rsp), %eax
cmpl $0x1, %eax
jge 0x3d44c
movl $0x0, 0x44(%rsp)
jmp 0x3d615
movl 0x1c(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x18(%rsp), %eax
jg 0x3d4a7
movq 0x38(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x28(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x30(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x20(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x3d454
movq 0x38(%rsp), %rax
movslq 0x18(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x18(%rsp), %eax
jge 0x3d58d
movq 0x28(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd (%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x3d534
movq 0x28(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x38(%rsp), %rax
movslq 0xc(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x20(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x30(%rsp), %rax
movl 0xc(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0xc(%rsp)
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x3d57b
movq 0x28(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x38(%rsp), %rax
movslq 0x10(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x20(%rsp), %rax
movslq 0x14(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x30(%rsp), %rax
movl 0x10(%rsp), %ecx
movl %ecx, %edx
addl $-0x1, %edx
movl %edx, 0x10(%rsp)
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x3d57d
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x3d4c3
movsd (%rsp), %xmm0
movq 0x38(%rsp), %rax
movslq 0x10(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x20(%rsp), %rax
movslq 0x18(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x30(%rsp), %rax
movslq 0x10(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rcx
movl 0x1c(%rsp), %r8d
movl 0xc(%rsp), %r9d
subl $0x1, %r9d
callq 0x3d400
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rcx
movl 0x10(%rsp), %r8d
addl $0x1, %r8d
movl 0x18(%rsp), %r9d
callq 0x3d400
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x48, %rsp
retq
nop