// File: /workspace/github_c_makefile_star2_O0/thegenemyers[P]DASCRUBBER/align.c
// Function: Find_Extension
int Find_Extension(Alignment *align, Work_Data *ework, Align_Spec *espec,
                   int diag, int anti, int lbord, int hbord, int prefix)
{ _Work_Data  *work = ( _Work_Data *) ework;
  _Align_Spec *spec = (_Align_Spec *) espec;

  Path *apath;
  int   minp, maxp;

  { int alen, blen;
    int maxtp, wsize;

    alen = align->alen;
    blen = align->blen;

    wsize = VectorEn*10000;
    if (wsize >= work->vecmax)
      if (enlarge_vector(work,wsize))
        EXIT(1);

    if (alen < blen)
      maxtp = 2*(blen/spec->trace_space+2);
    else
      maxtp = 2*(alen/spec->trace_space+2);
    wsize = 2*maxtp*sizeof(uint16);
    if (wsize > work->pntmax)
      if (enlarge_points(work,wsize))
        EXIT(1);

    apath = align->path;
    apath->trace = ((uint16 *) work->points) + maxtp;
  }

#ifdef DEBUG_PASSES
  printf("\n");
#endif

  if (lbord < 0)
    minp = -INT32_MAX;
  else
    minp = diag-lbord;
  if (hbord < 0)
    maxp = INT32_MAX;
  else
    maxp = diag+hbord;

  if (prefix)
    { if (reverse_extend(work,spec,align,diag,anti,minp,maxp))
        EXIT(1);
      apath->aepos = (anti+diag)/2;
      apath->bepos = (anti-diag)/2;
#ifdef DEBUG_PASSES
      printf("E1 (%d,%d) => (%d,%d) %d\n",
             (anti+diag)/2,(anti-diag)/2,apath->abpos,apath->bbpos,apath->diffs);
#endif
    }
  else
    { if (forward_extend(work,spec,align,diag,anti,minp,maxp))
        EXIT(1);
      apath->abpos = (anti+diag)/2;
      apath->bbpos = (anti-diag)/2;
#ifdef DEBUG_PASSES
      printf("F1 (%d,%d) => (%d,%d) %d\n",
             (anti+diag)/2,(anti-diag)/2,apath->aepos,apath->bepos,apath->diffs);
#endif
     }

#ifdef DEBUG_POINTS
  { uint16 *trace = (uint16 *) apath->trace;
    int     a, h;

    printf("\nA-path (%d,%d)->(%d,%d)",apath->abpos,apath->bbpos,apath->aepos,apath->bepos);
    printf(" %c\n",(COMP(align->flags) ? 'c' : 'n'));
    a = apath->bbpos;
    for (h = 1; h < apath->tlen; h += 2)
      { int dif = trace[h-1];
        int del = trace[h];
        a += del;
        printf("      %d / %d (%d)\n",dif,del,a);
      }
  }
#endif

  return (0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x50(%rbp)
imull $0x2710, 0x21121(%rip), %eax # imm = 0x2710
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl (%rcx), %eax
jl 0xa0fe
movq -0x30(%rbp), %rdi
movl -0x58(%rbp), %esi
callq 0x5220
cmpl $0x0, %eax
je 0xa0fc
movl $0x1, %edi
callq 0x2290
jmp 0xa0fe
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jge 0xa11b
movl -0x50(%rbp), %eax
movq -0x38(%rbp), %rcx
cltd
idivl 0x8(%rcx)
addl $0x2, %eax
shll %eax
movl %eax, -0x54(%rbp)
jmp 0xa12e
movl -0x4c(%rbp), %eax
movq -0x38(%rbp), %rcx
cltd
idivl 0x8(%rcx)
addl $0x2, %eax
shll %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
shll %eax
cltq
shlq %rax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jle 0xa164
movq -0x30(%rbp), %rdi
movl -0x58(%rbp), %esi
callq 0x52a0
cmpl $0x0, %eax
je 0xa162
movl $0x1, %edi
callq 0x2290
jmp 0xa164
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rcx
movslq -0x54(%rbp), %rax
shlq %rax
addq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
cmpl $0x0, -0x24(%rbp)
jge 0xa197
movl $0x80000001, -0x44(%rbp) # imm = 0x80000001
jmp 0xa1a0
movl -0x1c(%rbp), %eax
subl -0x24(%rbp), %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, 0x10(%rbp)
jge 0xa1af
movl $0x7fffffff, -0x48(%rbp) # imm = 0x7FFFFFFF
jmp 0xa1b8
movl -0x1c(%rbp), %eax
addl 0x10(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, 0x18(%rbp)
je 0xa21f
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x8(%rbp), %rdx
movl -0x1c(%rbp), %ecx
movl -0x20(%rbp), %r8d
movl -0x44(%rbp), %r9d
movl -0x48(%rbp), %eax
movl %eax, (%rsp)
callq 0xa290
cmpl $0x0, %eax
je 0xa1ef
movl $0x1, %edi
callq 0x2290
movl -0x20(%rbp), %eax
addl -0x1c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x18(%rax)
movl -0x20(%rbp), %eax
subl -0x1c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x1c(%rax)
jmp 0xa27e
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x8(%rbp), %rdx
movl -0x1c(%rbp), %ecx
movl -0x20(%rbp), %r8d
movl -0x44(%rbp), %r9d
movl -0x48(%rbp), %eax
movl %eax, (%rsp)
callq 0xbe40
cmpl $0x0, %eax
je 0xa250
movl $0x1, %edi
callq 0x2290
movl -0x20(%rbp), %eax
addl -0x1c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x20(%rbp), %eax
subl -0x1c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x14(%rax)
xorl %eax, %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)