// File: /workspace/github_c_makefile_star2_O0/yui0[P]img2vec/./potracelib.h
// Function: bestpolygon
static int bestpolygon(privpath_t *pp)
{
  int i, j, m, k;     
  int n = pp->len;
  double *pen = NULL; /* pen[n+1]: penalty vector */
  int *prev = NULL;   /* prev[n+1]: best path pointer vector */
  int *clip0 = NULL;  /* clip0[n]: longest segment pointer, non-cyclic */
  int *clip1 = NULL;  /* clip1[n+1]: backwards segment pointer, non-cyclic */
  int *seg0 = NULL;    /* seg0[m+1]: forward segment bounds, m<=n */
  int *seg1 = NULL;   /* seg1[m+1]: backward segment bounds, m<=n */
  double thispen;
  double best;
  int c;
  SAFE_CALLOC(pen, n+1, double);
  SAFE_CALLOC(prev, n+1, int);
  SAFE_CALLOC(clip0, n, int);
  SAFE_CALLOC(clip1, n+1, int);
  SAFE_CALLOC(seg0, n+1, int);
  SAFE_CALLOC(seg1, n+1, int);
  /* calculate clipped paths */
  for (i=0; i<n; i++) {
    c = mod(pp->lon[mod(i-1,n)]-1,n);
    if (c == i) {
      c = mod(i+1,n);
    }
    if (c < i) {
      clip0[i] = n;
    } else {
      clip0[i] = c;
    }
  }
  /* calculate backwards path clipping, non-cyclic. j <= clip0[i] iff
     clip1[j] <= i, for i,j=0..n. */
  j = 1;
  for (i=0; i<n; i++) {
    while (j <= clip0[i]) {
      clip1[j] = i;
      j++;
    }
  }
  /* calculate seg0[j] = longest path from 0 with j segments */
  i = 0;
  for (j=0; i<n; j++) {
    seg0[j] = i;
    i = clip0[i];
  }
  seg0[j] = n;
  m = j;
  /* calculate seg1[j] = longest path to n with m-j segments */
  i = n;
  for (j=m; j>0; j--) {
    seg1[j] = i;
    i = clip1[i];
  }
  seg1[0] = 0;
  /* now find the shortest path with m segments, based on penalty3 */
  /* note: the outer 2 loops jointly have at most n iterations, thus
     the worst-case behavior here is quadratic. In practice, it is
     close to linear since the inner loop tends to be short. */
  pen[0]=0;
  for (j=1; j<=m; j++) {
    for (i=seg1[j]; i<=seg0[j]; i++) {
      best = -1;
      for (k=seg0[j-1]; k>=clip1[i]; k--) {
	thispen = penalty3(pp, k, i) + pen[k];
	if (best < 0 || thispen < best) {
	  prev[i] = k;
	  best = thispen;
	}
      }
      pen[i] = best;
    }
  }
  pp->m = m;
  SAFE_CALLOC(pp->po, m, int);
  /* read off shortest path */
  for (i=n, j=m-1; i>0; j--) {
    i = prev[i];
    pp->po[j] = i;
  }
  free(pen);
  free(prev);
  free(clip0);
  free(clip1);
  free(seg0);
  free(seg1);
  return 0;
  
 calloc_error:
  free(pen);
  free(prev);
  free(clip0);
  free(clip1);
  free(seg0);
  free(seg1);
  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movl $0x8, %esi
callq 0x1120
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x992a
jmp 0x9cee
movl -0x24(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x1120
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x994c
jmp 0x9cee
movslq -0x24(%rbp), %rdi
movl $0x4, %esi
callq 0x1120
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jne 0x9969
jmp 0x9cee
movl -0x24(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x1120
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
jne 0x998b
jmp 0x9cee
movl -0x24(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x1120
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
jne 0x99ad
jmp 0x9cee
movl -0x24(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x1120
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
jne 0x99cf
jmp 0x9cee
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x9a65
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
movl -0x14(%rbp), %edi
subl $0x1, %edi
movl -0x24(%rbp), %esi
callq 0x2ca20
movl %eax, %ecx
movq -0x78(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edi
subl $0x1, %edi
movl -0x24(%rbp), %esi
callq 0x2ca20
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x9a2f
movl -0x14(%rbp), %edi
addl $0x1, %edi
movl -0x24(%rbp), %esi
callq 0x2ca20
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x9a47
movl -0x24(%rbp), %edx
movq -0x40(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x9a55
movl -0x6c(%rbp), %edx
movq -0x40(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x9a57
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x99d6
movl $0x1, -0x18(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x9ab3
jmp 0x9a7d
movl -0x18(%rbp), %eax
movq -0x40(%rbp), %rcx
movslq -0x14(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jg 0x9aa6
movl -0x14(%rbp), %edx
movq -0x48(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x9a7d
jmp 0x9aa8
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x9a73
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x9af0
movl -0x14(%rbp), %edx
movq -0x50(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x9ac1
movl -0x24(%rbp), %edx
movq -0x50(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jle 0x9b3d
movl -0x14(%rbp), %edx
movq -0x58(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x48(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x9b10
movq -0x58(%rbp), %rax
movl $0x0, (%rax)
movq -0x30(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movl $0x1, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jg 0x9c47
movq -0x58(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x50(%rbp), %rcx
movslq -0x18(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jg 0x9c37
movsd 0x28491(%rip), %xmm0    # 0x32020
movsd %xmm0, -0x68(%rbp)
movq -0x50(%rbp), %rax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x48(%rbp), %rcx
movslq -0x14(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jl 0x9c17
movq -0x10(%rbp), %rdi
movl -0x20(%rbp), %esi
movl -0x14(%rbp), %edx
callq 0x2cb60
movq -0x30(%rbp), %rax
movslq -0x20(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x60(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x68(%rbp), %xmm0
ja 0x9bf2
movsd -0x60(%rbp), %xmm1
movsd -0x68(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x9c0a
movl -0x20(%rbp), %edx
movq -0x38(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x9c0c
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x9ba7
movsd -0x68(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x14(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x9b73
jmp 0x9c39
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x9b59
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movslq -0x1c(%rbp), %rdi
movl $0x4, %esi
callq 0x1120
movq -0x10(%rbp), %rcx
movq %rax, 0x30(%rcx)
cmpq $0x0, %rax
jne 0x9c6f
jmp 0x9cee
movl -0x24(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x9caf
movq -0x38(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x9c7e
movq -0x30(%rbp), %rdi
callq 0x1030
movq -0x38(%rbp), %rdi
callq 0x1030
movq -0x40(%rbp), %rdi
callq 0x1030
movq -0x48(%rbp), %rdi
callq 0x1030
movq -0x50(%rbp), %rdi
callq 0x1030
movq -0x58(%rbp), %rdi
callq 0x1030
movl $0x0, -0x4(%rbp)
jmp 0x9d2b
movq -0x30(%rbp), %rdi
callq 0x1030
movq -0x38(%rbp), %rdi
callq 0x1030
movq -0x40(%rbp), %rdi
callq 0x1030
movq -0x48(%rbp), %rdi
callq 0x1030
movq -0x50(%rbp), %rdi
callq 0x1030
movq -0x58(%rbp), %rdi
callq 0x1030
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)