// File: /workspace/github_c_makefile_star2_O0/thegenemyers[P]DAMASKER/tandem.c
// Function: Entwine
static int Entwine(Path *jpath, Path *kpath, Trace_Buffer *tbuf, int *where)
{ int   ac, b2, y2, ae;
  int   i, j, k;
  int   num, den, min;
#ifdef SEE_ENTWINE
  int   strt, iflare, oflare;
#endif

  uint16 *ktrace = tbuf->trace + (uint64) (kpath->trace);
  uint16 *jtrace = tbuf->trace + (uint64) (jpath->trace);

  min   = 10000;
  num   = 0;
  den   = 0;

#ifdef SEE_ENTWINE
  strt = 1;
  printf("\n");
#endif

  y2 = jpath->bbpos;
  j  = jpath->abpos/MR_tspace;

  b2 = kpath->bbpos;
  k  = kpath->abpos/MR_tspace;

  if (jpath->abpos == kpath->abpos)
    { min = abs(y2-b2);
      if (min == 0)
        *where = kpath->abpos;
    }

  if (j < k)
    { ac = k*MR_tspace;

      j = 1 + 2*(k-j);
      k = 1;

      for (i = 1; i < j; i += 2)
        y2 += jtrace[i];
    }
  else
    { ac = j*MR_tspace;

      k = 1 + 2*(j-k);
      j = 1;

      for (i = 1; i < k; i += 2)
        b2 += ktrace[i];
    }

  ae = jpath->aepos;
  if (ae > kpath->aepos)
    ae = kpath->aepos;

  while (1)
    { ac += MR_tspace;
      if (ac >= ae)
        break;
      y2 += jtrace[j];
      b2 += ktrace[k];
      j += 2;
      k += 2;

#ifdef SEE_ENTWINE
      printf("   @ %5d : %5d %5d = %4d\n",ac,y2,b2,abs(b2-y2));
#endif

      i = abs(y2-b2);
      if (i <= min)
        { min = i;
          if (i == 0)
            *where = ac;
        }
      num += i;
      den += 1;
#ifdef SEE_ENTWINE
      if (strt)
        { strt   = 0;
          iflare = i;
        }
      oflare = i;
#endif
    }

  if (jpath->aepos == kpath->aepos)
    { i = abs(jpath->bepos-kpath->bepos);
      if (i <= min)
        { min = i;
          if (i == 0)
            *where = kpath->aepos;
        }
    }

#ifdef SEE_ENTWINE
  if (den == 0)
    printf("Nothing\n");
  else
    printf("MINIM = %d AVERAGE = %d  IFLARE = %d  OFLARE = %d\n",min,num/den,iflare,oflare);
#endif

  if (den == 0)
    return (-1);
  else
    return (min);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movl $0x2710, -0x50(%rbp)    # imm = 0x2710
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
cltd
idivl 0x2782d(%rip)           # 0x2e450
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
cltd
idivl 0x27812(%rip)           # 0x2e450
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x6c76
movl -0x34(%rbp), %eax
subl -0x30(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jne 0x6c74
movq -0x18(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0x6c76
movl -0x40(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x6cce
movl -0x44(%rbp), %eax
imull 0x277c8(%rip), %eax     # 0x2e450
movl %eax, -0x2c(%rbp)
movl -0x44(%rbp), %eax
subl -0x40(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl $0x1, -0x44(%rbp)
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x6ccc
movq -0x60(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x3c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6ca7
jmp 0x6d1e
movl -0x40(%rbp), %eax
imull 0x27778(%rip), %eax     # 0x2e450
movl %eax, -0x2c(%rbp)
movl -0x40(%rbp), %eax
subl -0x44(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl $0x1, -0x40(%rbp)
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x6d1c
movq -0x58(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x3c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6cf7
jmp 0x6d1e
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jle 0x6d3e
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0x6d40
movl 0x2770a(%rip), %eax     # 0x2e450
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x6d56
jmp 0x6dd2
movq -0x60(%rbp), %rax
movslq -0x40(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x58(%rbp), %rax
movslq -0x44(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x40(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x40(%rbp)
movl -0x44(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x44(%rbp)
movl -0x34(%rbp), %eax
subl -0x30(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jg 0x6dbb
movl -0x3c(%rbp), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x6db9
movl -0x2c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0x6dbb
movl -0x3c(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6d40
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jne 0x6e1f
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x1c(%rcx), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jg 0x6e1d
movl -0x3c(%rbp), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x6e1b
movq -0x18(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0x6e1d
jmp 0x6e1f
cmpl $0x0, -0x4c(%rbp)
jne 0x6e2e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6e34
movl -0x50(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)