// File: /workspace/github_c_makefile_star2_O0/thegenemyers[P]DASCRUBBER/DASpatch.c
// Function: PATCH_GAPS
static void PATCH_GAPS(int aread, Overlap *ovls, int novl)
{ static Patch dummy = { 0, 0, 0, 0, 0, 0, 0 };

#ifdef DEBUG_SUMMARY
  static char *status_string[4] = { "LOWQ", "SPAN", "SPLIT", "NOPAT" };
#endif

  int       alen;
  Interval  lblock, rblock;
  Patch    *patch = NULL;
  int       status;
  int       tb, te;
  int       val;

  alen = DB->reads[aread].rlen;
  if (alen < HGAP_MIN)
    { fwrite(&PR_INDEX,sizeof(int64),1,PR_AFILE);
      return;
    }

#if defined(DEBUG_GAP_FILL) || defined(DEBUG_SUMMARY)
  printf("\n");
  printf("AREAD %d\n",aread);
#endif

  //  Determine patch for every LOWQ and SPAN gap and output dummy 0-patch
  //    for all SPLIT decisions

  tb = TRIM_IDX[aread];
  te = TRIM_IDX[aread+1];
  if (tb+2 < te)
    { lblock.beg = TRIM[tb];
      lblock.end = TRIM[tb+1];
      for (tb += 3; tb < te; tb += 3)
        { status     = TRIM[tb-1];
          rblock.beg = TRIM[tb];
          rblock.end = TRIM[tb+1];

          if (status == LOWQ)
            { patch = lowq_patch(ovls,novl,&lblock,&rblock);
              if (patch->bread < 0)
                status = SPAN;
            }
          if (status == SPAN)
            patch = span_patch(ovls,novl,&lblock,&rblock);

          if (status == SPLIT)
            { val = 0;
              patch = &dummy;
            }
          else
            { if (patch->bread < 0)
                { val = 0;
                  fpatch += 1;
#ifdef DEBUG_SUMMARY
                  TRIM[tb-1] = NOPAT;
#endif
                }
              else if (patch->comp)
                val = -(patch->bread+1);
              else
                val = patch->bread+1;
              npatch += 1;
            }
          fwrite(&val,sizeof(int),1,PR_DFILE);
          fwrite(&(patch->beg),sizeof(int),1,PR_DFILE);
          fwrite(&(patch->end),sizeof(int),1,PR_DFILE);
          PR_INDEX += 3*sizeof(int);

          lblock = rblock;
        }
    }
  fwrite(&PR_INDEX,sizeof(int64),1,PR_AFILE);

#ifdef DEBUG_SUMMARY
  tb = TRIM_IDX[aread];
  te = TRIM_IDX[aread+1];
#ifdef DEBUG_GAP_FILL
  if (tb+2 < te)
    printf("  FINAL:\n");
#endif
  if (tb < te)
    { printf("    [%d,%d]",TRIM[tb],TRIM[tb+1]);
      for (tb += 3; tb < te; tb += 3)
        printf(" %s [%d,%d]",status_string[TRIM[tb-1]],TRIM[tb],TRIM[tb+1]);
      printf("\n");
    }
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq $0x0, -0x30(%rbp)
movq 0x279c7(%rip), %rax     # 0x2b188
movq 0x60(%rax), %rax
movslq -0x4(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl 0x27c41(%rip), %eax     # 0x2b420
jge 0x3803
movq 0x27c50(%rip), %rcx     # 0x2b438
leaq 0x27c59(%rip), %rdi     # 0x2b448
movl $0x8, %esi
movl $0x1, %edx
callq 0x22a0
jmp 0x3a13
movq 0x27c06(%rip), %rax     # 0x2b410
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x38(%rbp)
movq 0x27bf4(%rip), %rax     # 0x2b410
movl -0x4(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
addl $0x2, %eax
cmpl -0x3c(%rbp), %eax
jge 0x39f6
movq 0x27bd6(%rip), %rax     # 0x2b418
movslq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rbp)
movq 0x27bc5(%rip), %rax     # 0x2b418
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x1c(%rbp)
movl -0x38(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x39f4
movq 0x27b9a(%rip), %rax     # 0x2b418
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
movq 0x27b84(%rip), %rax     # 0x2b418
movslq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
movq 0x27b73(%rip), %rax     # 0x2b418
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x38e4
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq -0x20(%rbp), %rdx
leaq -0x28(%rbp), %rcx
callq 0x3a20
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
jge 0x38e2
movl $0x1, -0x34(%rbp)
jmp 0x38e4
cmpl $0x1, -0x34(%rbp)
jne 0x3902
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq -0x20(%rbp), %rdx
leaq -0x28(%rbp), %rcx
callq 0x3be0
movq %rax, -0x30(%rbp)
cmpl $0x2, -0x34(%rbp)
jne 0x391c
movl $0x0, -0x40(%rbp)
leaq 0x27bca(%rip), %rax     # 0x2b4e0
movq %rax, -0x30(%rbp)
jmp 0x3976
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
jge 0x393d
movl $0x0, -0x40(%rbp)
movl 0x27b2a(%rip), %eax     # 0x2b45c
addl $0x1, %eax
movl %eax, 0x27b21(%rip)     # 0x2b45c
jmp 0x3967
movq -0x30(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x3959
movq -0x30(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x40(%rbp)
jmp 0x3965
movq -0x30(%rbp), %rax
movl (%rax), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x3967
movl 0x27aeb(%rip), %eax     # 0x2b458
addl $0x1, %eax
movl %eax, 0x27ae2(%rip)     # 0x2b458
movq 0x27ac3(%rip), %rcx     # 0x2b440
leaq -0x40(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x22a0
movq -0x30(%rbp), %rdi
addq $0x8, %rdi
movq 0x27aa1(%rip), %rcx     # 0x2b440
movl $0x4, %esi
movl $0x1, %edx
callq 0x22a0
movq -0x30(%rbp), %rdi
addq $0xc, %rdi
movq 0x27a83(%rip), %rcx     # 0x2b440
movl $0x4, %esi
movl $0x1, %edx
callq 0x22a0
movq 0x27a75(%rip), %rax     # 0x2b448
addq $0xc, %rax
movq %rax, 0x27a6a(%rip)     # 0x2b448
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movl -0x38(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x38(%rbp)
jmp 0x386b
jmp 0x39f6
movq 0x27a3b(%rip), %rcx     # 0x2b438
leaq 0x27a44(%rip), %rdi     # 0x2b448
movl $0x8, %esi
movl $0x1, %edx
callq 0x22a0
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)