// File: /workspace/github_c_makefile_star2_O2/thegenemyers[P]DASCRUBBER/DASrealign.c
// Function: make_a_pass
static int make_a_pass(FILE *input, void (*ACTION)(int, Overlap *, int), int trace)
{ static Overlap *ovls  = NULL;
  static int      omax  = 500;
  static uint16  *paths = NULL;
  static int      pmax  = 100000;

  int64 i, j, novl;
  int   n, a;
  int   pcur;
  int   max;

  if (ovls == NULL)
    { ovls = (Overlap *) Malloc(sizeof(Overlap)*omax,"Allocating overlap buffer");
      if (ovls == NULL)
        exit (1);
    }
  if (trace && paths == NULL)
    { paths = (uint16 *) Malloc(sizeof(uint16)*pmax,"Allocating path buffer");
      if (paths == NULL)
        exit (1);
    }

  rewind(input);
  fread(&novl,sizeof(int64),1,input);
  fread(&TRACE_SPACING,sizeof(int),1,input);
  if (TRACE_SPACING <= TRACE_XOVR)
    { TBYTES = sizeof(uint8);
      SMALL  = 1;
    }
  else
    { TBYTES = sizeof(uint16);
      SMALL  = 0;
    }

  if (Read_Overlap(input,ovls) != 0)
    ovls[0].aread = INT32_MAX;
  else if (trace)
    { if (ovls[0].path.tlen > pmax)
        { pmax = 1.2*(ovls[0].path.tlen)+10000;
          paths = (uint16 *) Realloc(paths,sizeof(uint16)*pmax,"Expanding path buffer");
          if (paths == NULL) exit (1);
        }
      fread(paths,TBYTES,ovls[0].path.tlen,input);
      if (TBYTES == 1)
        { ovls[0].path.trace = paths;
          Decompress_TraceTo16(ovls);
        }
    }
  else
    fseek(input,TBYTES*ovls[0].path.tlen,SEEK_CUR);

  pcur = 0;
  n = max = 0;
  for (j = ovls[0].aread; j < ADB_olast; j++)
    { ovls[0] = ovls[n];
      a = ovls[0].aread;
      if (a != j)
        n = 0;
      else
        { if (trace)
            memmove(paths,paths+pcur,sizeof(uint16)*ovls[0].path.tlen);
          n = 1;
          pcur = ovls[0].path.tlen;
          while (1)
            { if (Read_Overlap(input,ovls+n) != 0)
                { ovls[n].aread = INT32_MAX;
                  break;
                }
              if (trace)
                { if (pcur + ovls[n].path.tlen > pmax)
                    { pmax = 1.2*(pcur+ovls[n].path.tlen)+10000;
                      paths = (uint16 *) Realloc(paths,sizeof(uint16)*pmax,"Expanding path buffer");
                      if (paths == NULL) exit (1);
                    }
                  fread(paths+pcur,TBYTES,ovls[n].path.tlen,input);
                  if (TBYTES == 1)
                    { ovls[n].path.trace = paths+pcur;
                      Decompress_TraceTo16(ovls+n);
                    }
                }
              else
                fseek(input,TBYTES*ovls[n].path.tlen,SEEK_CUR);
              if (ovls[n].aread != a)
                break;
              pcur += ovls[n].path.tlen;
              n    += 1;
              if (n >= omax)
                { omax = 1.2*n + 100;
                  ovls = (Overlap *) Realloc(ovls,sizeof(Overlap)*omax,"Expanding overlap buffer");
                  if (ovls == NULL) exit (1);
                }
            }

          if (n >= max)
            max = n;
          pcur = 0;
          for (i = 0; i < n; i++)
            { ovls[i].path.trace = paths+pcur;
              pcur += ovls[i].path.tlen;
            }
        }

      if (j >= ADB_ofirst)
        ACTION(j,ovls,n);
    }

  if (ovls[n].aread < INT32_MAX)
    { fprintf(stderr,"%s: .las file overlaps don't correspond to reads in block %d of DB\n",
                     Prog_Name,ADB->part);
      exit (1);
    }

  return (max);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
cmpq $0x0, 0x1d7c0(%rip)     # 0x1f2d8
jne 0x1b41
movslq 0x1d64f(%rip), %rax     # 0x1f170
imulq $0x30, %rax, %rdi
leaq 0x17708(%rip), %rsi     # 0x19234
callq 0x114c9
movq %rax, 0x1d7a0(%rip)     # 0x1f2d8
testq %rax, %rax
je 0x1ede
cmpq $0x0, 0x1d797(%rip)     # 0x1f2e0
jne 0x1b71
movslq 0x1d622(%rip), %rdi     # 0x1f174
addq %rdi, %rdi
leaq 0x176f2(%rip), %rsi     # 0x1924e
callq 0x114c9
movq %rax, 0x1d778(%rip)     # 0x1f2e0
testq %rax, %rax
je 0x1ede
movq %rbx, %rdi
callq 0x1110
leaq 0x10(%rsp), %rdi
pushq $0x8
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
movq %rbx, %rcx
callq 0x10b0
leaq 0x1d601(%rip), %rdi     # 0x1f198
pushq $0x4
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x10b0
xorl %eax, %eax
cmpl $0x7e, 0x1d5ea(%rip)    # 0x1f198
setge %al
incl %eax
movl %eax, 0x1d72f(%rip)     # 0x1f2e8
movq 0x1d718(%rip), %rsi     # 0x1f2d8
movq %rbx, %rdi
callq 0x8ad5
movq 0x1d709(%rip), %rdi     # 0x1f2d8
testl %eax, %eax
je 0x1bdf
movl $0x7fffffff, 0x24(%rdi) # imm = 0x7FFFFFFF
jmp 0x1c75
movl 0x8(%rdi), %eax
movq 0x1d6f7(%rip), %rdi     # 0x1f2e0
cmpl 0x1d585(%rip), %eax     # 0x1f174
jle 0x1c3e
cvtsi2sd %eax, %xmm0
mulsd 0x1740b(%rip), %xmm0    # 0x19008
addsd 0x1740b(%rip), %xmm0    # 0x19010
cvttsd2si %xmm0, %eax
movl %eax, 0x1d565(%rip)     # 0x1f174
movslq %eax, %rsi
addq %rsi, %rsi
leaq 0x17649(%rip), %rdx     # 0x19265
callq 0x11521
movq %rax, 0x1d6b8(%rip)     # 0x1f2e0
testq %rax, %rax
je 0x1ede
movq %rax, %rdi
movq 0x1d69d(%rip), %rax     # 0x1f2d8
movl 0x8(%rax), %eax
movl 0x1d6a4(%rip), %esi     # 0x1f2e8
movslq %eax, %rdx
movq %rbx, %rcx
callq 0x10b0
cmpl $0x1, 0x1d692(%rip)     # 0x1f2e8
movq 0x1d67b(%rip), %rdi     # 0x1f2d8
jne 0x1c75
movq 0x1d67a(%rip), %rax     # 0x1f2e0
movq %rax, (%rdi)
callq 0x8be7
movq 0x1d663(%rip), %rdi     # 0x1f2d8
movslq 0x24(%rdi), %r12
xorl %ebp, %ebp
xorl %r15d, %r15d
movl $0x0, 0x4(%rsp)
movslq 0x1d52f(%rip), %rcx     # 0x1f1bc
movq 0x1d644(%rip), %r14     # 0x1f2d8
movslq %ebp, %rax
imulq $0x30, %rax, %rax
cmpq %rcx, %r12
jge 0x1e9c
movupd (%r14,%rax), %xmm0
movups 0x10(%r14,%rax), %xmm1
movups 0x20(%r14,%rax), %xmm2
movups %xmm2, 0x20(%r14)
movups %xmm1, 0x10(%r14)
movupd %xmm0, (%r14)
movslq 0x24(%r14), %r13
xorl %ebp, %ebp
cmpq %r13, %r12
jne 0x1e7b
movq %r12, 0x8(%rsp)
movq 0x1d600(%rip), %rdi     # 0x1f2e0
movslq %r15d, %rax
leaq (%rdi,%rax,2), %rsi
movslq 0x8(%r14), %rdx
addq %rdx, %rdx
callq 0x1220
movl 0x8(%r14), %r12d
xorl %r15d, %r15d
pushq $0x1
popq %rbp
leaq (%r14,%r15), %rsi
addq $0x30, %rsi
movq %rbx, %rdi
callq 0x8ad5
movq 0x1d5c4(%rip), %r14     # 0x1f2d8
testl %eax, %eax
jne 0x1e35
movl 0x38(%r14,%r15), %ecx
leal (%rcx,%r12), %edx
movq 0x1d5b4(%rip), %rax     # 0x1f2e0
cmpl 0x1d442(%rip), %edx     # 0x1f174
jle 0x1d83
cvtsi2sd %edx, %xmm0
mulsd 0x172c8(%rip), %xmm0    # 0x19008
addsd 0x172c8(%rip), %xmm0    # 0x19010
cvttsd2si %xmm0, %ecx
movl %ecx, 0x1d422(%rip)     # 0x1f174
movslq %ecx, %rsi
addq %rsi, %rsi
movq %rax, %rdi
leaq 0x17503(%rip), %rdx     # 0x19265
callq 0x11521
movq %rax, 0x1d572(%rip)     # 0x1f2e0
testq %rax, %rax
je 0x1ede
movq 0x1d55a(%rip), %rcx     # 0x1f2d8
movl 0x38(%rcx,%r15), %ecx
movslq %r12d, %r14
leaq (%rax,%r14,2), %rdi
movl 0x1d558(%rip), %esi     # 0x1f2e8
movslq %ecx, %rdx
movq %rbx, %rcx
callq 0x10b0
cmpl $0x1, 0x1d546(%rip)     # 0x1f2e8
jne 0x1dc5
addq %r14, %r14
addq 0x1d532(%rip), %r14     # 0x1f2e0
movq 0x1d523(%rip), %rax     # 0x1f2d8
leaq (%rax,%r15), %rdi
addq $0x30, %rdi
movq %r14, (%rdi)
callq 0x8be7
movq 0x1d50c(%rip), %r14     # 0x1f2d8
cmpl %r13d, 0x54(%r14,%r15)
jne 0x1e3e
addl 0x38(%r14,%r15), %r12d
leal 0x1(%rbp), %eax
cmpl %eax, 0x1d38f(%rip)     # 0x1f170
jg 0x1e29
cvtsi2sd %eax, %xmm0
mulsd 0x17219(%rip), %xmm0    # 0x19008
addsd 0x17221(%rip), %xmm0    # 0x19018
cvttsd2si %xmm0, %eax
movl %eax, 0x1d36f(%rip)     # 0x1f170
cltq
imulq $0x30, %rax, %rsi
movq %r14, %rdi
leaq 0x1746a(%rip), %rdx     # 0x1927b
callq 0x11521
movq %rax, %r14
movq %rax, 0x1d4b8(%rip)     # 0x1f2d8
testq %rax, %rax
je 0x1ede
incq %rbp
addq $0x30, %r15
jmp 0x1cfd
movl $0x7fffffff, 0x54(%r14,%r15) # imm = 0x7FFFFFFF
movq 0x1d49b(%rip), %rax     # 0x1f2e0
leaq 0x8(%r14), %rcx
xorl %r15d, %r15d
movq %rbp, %rdx
movq 0x8(%rsp), %r12
subq $0x1, %rdx
jb 0x1e6e
movslq %r15d, %r15
leaq (%rax,%r15,2), %rsi
movq %rsi, -0x8(%rcx)
addl (%rcx), %r15d
addq $0x30, %rcx
jmp 0x1e54
movl 0x4(%rsp), %eax
cmpl %eax, %ebp
cmovgl %ebp, %eax
movl %eax, 0x4(%rsp)
movslq 0x1d336(%rip), %rax     # 0x1f1b8
cmpq %rax, %r12
jl 0x1e94
movl %r12d, %edi
movq %r14, %rsi
movl %ebp, %edx
callq 0x1ee6
incq %r12
jmp 0x1c86
cmpl $0x7fffffff, 0x24(%r14,%rax) # imm = 0x7FFFFFFF
jne 0x1eb6
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1d13b(%rip), %rax     # 0x1eff8
movq (%rax), %rdi
leaq 0x1d511(%rip), %rax     # 0x1f3d8
movq (%rax), %rdx
movl 0x1d360(%rip), %ecx     # 0x1f230
leaq 0x173bd(%rip), %rsi     # 0x19294
xorl %eax, %eax
callq 0x11a0
pushq $0x1
popq %rdi
callq 0x1270