// File: /workspace/github_c_makefile_star2_O0/yui0[P]img2vec/./potracelib.h
// Function: pathlist_to_tree
static void pathlist_to_tree(path_t *plist, potrace_bitmap_t *bm) {
  path_t *p, *p1;
  path_t *heap, *heap1;
  path_t *cur;
  path_t *head;
  path_t **plist_hook;          /* for fast appending to linked list */
  path_t **hook_in, **hook_out; /* for fast appending to linked list */
  bbox_t bbox;
  
  bm_clear(bm, 0);
  /* save original "next" pointers */
  list_forall(p, plist) {
    p->sibling = p->next;
    p->childlist = NULL;
  }
  
  heap = plist;
  /* the heap holds a list of lists of paths. Use "childlist" field
     for outer list, "next" field for inner list. Each of the sublists
     is to be turned into a tree. This code is messy, but it is
     actually fast. Each path is rendered exactly once. We use the
     heap to get a tail recursive algorithm: the heap holds a list of
     pathlists which still need to be transformed. */
  while (heap) {
    /* unlink first sublist */
    cur = heap;
    heap = heap->childlist;
    cur->childlist = NULL;
  
    /* unlink first path */
    head = cur;
    cur = cur->next;
    head->next = NULL;
    /* render path */
    xor_path(bm, head);
    setbbox_path(&bbox, head);
    /* now do insideness test for each element of cur; append it to
       head->childlist if it's inside head, else append it to
       head->next. */
    hook_in=&head->childlist;
    hook_out=&head->next;
    list_forall_unlink(p, cur) {
      if (p->priv->pt[0].y <= bbox.y0) {
	list_insert_beforehook(p, hook_out);
	/* append the remainder of the list to hook_out */
	*hook_out = cur;
	break;
      }
      if (BM_GET(bm, p->priv->pt[0].x, p->priv->pt[0].y-1)) {
	list_insert_beforehook(p, hook_in);
      } else {
	list_insert_beforehook(p, hook_out);
      }
    }
    /* clear bm */
    clear_bm_with_bbox(bm, &bbox);
    /* now schedule head->childlist and head->next for further
       processing */
    if (head->next) {
      head->next->childlist = heap;
      heap = head->next;
    }
    if (head->childlist) {
      head->childlist->childlist = heap;
      heap = head->childlist;
    }
  }
  
  /* copy sibling structure from "next" to "sibling" component */
  p = plist;
  while (p) {
    p1 = p->sibling;
    p->sibling = p->next;
    p = p1;
  }
  /* reconstruct a new linked list ("next") structure from tree
     ("childlist", "sibling") structure. This code is slightly messy,
     because we use a heap to make it tail recursive: the heap
     contains a list of childlists which still need to be
     processed. */
  heap = plist;
  if (heap) {
    heap->next = NULL;  /* heap is a linked list of childlists */
  }
  plist = NULL;
  plist_hook = &plist;
  while (heap) {
    heap1 = heap->next;
    for (p=heap; p; p=p->sibling) {
      /* p is a positive path */
      /* append to linked list */
      list_insert_beforehook(p, plist_hook);
      
      /* go through its children */
      for (p1=p->childlist; p1; p1=p1->sibling) {
	/* append to linked list */
	list_insert_beforehook(p1, plist_hook);
	/* append its childlist to heap, if non-empty */
	if (p1->childlist) {
	  list_append(path_t, heap1, p1->childlist);
	}
      }
    }
    heap = heap1;
  }
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x2f380
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xcbb7
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0xcb86
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xce92
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0xca40
movq -0x40(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x2f3d0
movq -0x40(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xcc6d
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, 0x20(%rax)
movl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0xcc74
xorl %eax, %eax
movl %eax, -0x74(%rbp)
jmp 0xcc74
movl -0x74(%rbp), %eax
cmpl $0x0, %eax
je 0xce32
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movslq -0x60(%rbp), %rcx
cmpq %rcx, %rax
jg 0xccd1
jmp 0xcc9b
movq -0x58(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
jmp 0xce32
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
cmpl $0x0, %eax
jl 0xcdc7
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xcdc7
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
subq $0x1, %rax
cmpl $0x0, %eax
jl 0xcdc7
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
subq $0x1, %rax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0xcdc7
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x38(%rcx), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
movq -0x10(%rbp), %rdx
movslq 0x8(%rdx), %rdx
imulq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movl $0x40, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq (%rax,%rcx,8), %rax
movq -0x18(%rbp), %rcx
movq 0x38(%rcx), %rcx
movq 0x8(%rcx), %rcx
movq (%rcx), %rcx
andq $0x3f, %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
shrq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
jne 0xcdcf
jmp 0xcdf9
xorl %eax, %eax
testb $0x1, %al
jne 0xcdcf
jmp 0xcdf9
jmp 0xcdd1
movq -0x50(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x50(%rbp)
jmp 0xce23
jmp 0xcdfb
movq -0x58(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x58(%rbp)
jmp 0xce23
jmp 0xce25
movq -0x38(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0xcc44
movq -0x10(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x2f4d0
movq -0x40(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0xce66
movq -0x28(%rbp), %rcx
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq %rcx, 0x28(%rax)
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x40(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0xce8d
movq -0x28(%rbp), %rcx
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq %rcx, 0x28(%rax)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0xcbbf
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xcec7
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0xce9a
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xcee2
movq -0x28(%rbp), %rax
movq $0x0, 0x20(%rax)
movq $0x0, -0x8(%rbp)
leaq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xd010
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xd003
jmp 0xcf1e
movq -0x48(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xcff0
jmp 0xcf5d
movq -0x48(%rbp), %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0xcfdd
jmp 0xcf90
leaq -0x30(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq $0x0, (%rax)
je 0xcfb5
jmp 0xcfa4
movq -0x70(%rbp), %rax
movq (%rax), %rax
addq $0x20, %rax
movq %rax, -0x70(%rbp)
jmp 0xcf98
jmp 0xcfb7
movq -0x70(%rbp), %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x70(%rbp), %rax
movq %rcx, (%rax)
jmp 0xcfdb
jmp 0xcfdd
jmp 0xcfdf
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0xcf50
jmp 0xcff2
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0xcf11
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0xcef2
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)