// File: /workspace/github_c_makefile_star2_O0/thegenemyers[P]DASCRUBBER/DASedit.c
// Function: Load_Model
static int Load_Model(int *patch, char *target, int depth)
{ int   bread, bbeg, bend;
  int   lend, rend;
  int   gb, ge, pb;
  int   tlen, plen;
  char *bseq;

  if (BSTACK[depth] == NULL)
    BSTACK[depth] = New_Read_Buffer(DB);

  bread = patch[0];
  if (bread < 0)
    bread = - (bread+1);
  else
    bread -= 1;
  bbeg   = patch[1];
  bend   = patch[2];

#ifdef DEBUG_PATCHING
  printf("%*sPatching %d%c[%d,%d]->[%d,%d]\n",
         2*depth,"",bread,(patch[0]<0?'c':'n'),patch[1],patch[2],bbeg,bend);
#endif

  bseq = Load_Subread(DB,bread,bbeg,bend,BSTACK[depth],0) - bbeg;

  gb = TRIM_IDX[bread];
  ge = TRIM_IDX[bread+1];
  pb = PATCH_IDX[bread];

  tlen = 0;
  rend = -1;
  for (; gb < ge; gb += 3)
    { lend = TRIM[gb];
      if (lend > bbeg)
        { if (rend < bbeg || lend > bend || PATCH[pb] == 0)
            return (-1);
          plen = Load_Model(PATCH+pb,target+tlen,depth+1);
          if (plen < 0)
            return (-1);
          tlen += plen;

          rend = TRIM[gb+1];
          if (rend > bend)
            rend = bend;
          memmove(target+tlen,bseq+lend,rend-lend);
          tlen += rend-lend; 
#ifdef DEBUG_PATCHING
          printf("%*s  Piece %d,%d\n",2*depth,"",lend,rend);
#endif
#ifdef SHOW_PIECES
          Print_Seq(bseq+lend,rend-lend);
#endif
          pb += 3;
        }
      else // lend <= bbeg
        { rend = TRIM[gb+1];
          if (rend > bbeg)
            { if (rend > bend)
                rend = bend;
              memmove(target+tlen,bseq+bbeg,rend-bbeg);
              tlen += rend-bbeg;
#ifdef DEBUG_PATCHING
              printf("%*s  Piece %d,%d\n",2*depth,"",bbeg,rend);
#endif
#ifdef SHOW_PIECES
              Print_Seq(bseq+bbeg,rend-bbeg);
#endif
            }
          else
            pb += 3;
	}
      if (rend >= bend)
        break;
    }
  if (gb >= ge)
    fprintf(stderr,"Fatal: Should not happen\n");
 
  if (patch[0] < 0)
    Complement_Seq(target,tlen);

  return (tlen);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x270e2(%rip), %rax     # 0x2b410
cmpq $0x0, (%rax,%rcx,8)
jne 0x4353
movq 0x26e4c(%rip), %rdi     # 0x2b188
callq 0x1dff0
movq %rax, %rdx
movslq -0x1c(%rbp), %rcx
leaq 0x270c1(%rip), %rax     # 0x2b410
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x4371
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x20(%rbp)
jmp 0x437a
movl -0x20(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x28(%rbp)
movq 0x26df3(%rip), %rdi     # 0x2b188
movl -0x20(%rbp), %esi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
movslq -0x1c(%rbp), %r8
leaq 0x27067(%rip), %rax     # 0x2b410
movq (%rax,%r8,8), %r8
xorl %r9d, %r9d
callq 0x1e2e0
movslq -0x24(%rbp), %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq 0x27024(%rip), %rax     # 0x2b3f0
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x34(%rbp)
movq 0x27012(%rip), %rax     # 0x2b3f0
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x38(%rbp)
movq 0x2700b(%rip), %rax     # 0x2b400
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x458c
movq 0x26fd7(%rip), %rax     # 0x2b3f8
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x4509
movl -0x30(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0x4458
movl -0x2c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jg 0x4458
movq 0x26fba(%rip), %rax     # 0x2b408
movslq -0x3c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x4464
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x45c7
movq 0x26f9d(%rip), %rdi     # 0x2b408
movslq -0x3c(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movslq -0x40(%rbp), %rax
addq %rax, %rsi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
callq 0x4310
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jge 0x44a1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x45c7
movl -0x44(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movq 0x26f47(%rip), %rax     # 0x2b3f8
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x28(%rbp), %eax
jle 0x44ce
movl -0x28(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x40(%rbp), %rax
addq %rax, %rdi
movq -0x50(%rbp), %rsi
movslq -0x2c(%rbp), %rax
addq %rax, %rsi
movl -0x30(%rbp), %eax
subl -0x2c(%rbp), %eax
movslq %eax, %rdx
callq 0x2230
movl -0x30(%rbp), %eax
subl -0x2c(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4572
movq 0x26ee8(%rip), %rax     # 0x2b3f8
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x4567
movl -0x30(%rbp), %eax
cmpl -0x28(%rbp), %eax
jle 0x4535
movl -0x28(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x40(%rbp), %rax
addq %rax, %rdi
movq -0x50(%rbp), %rsi
movslq -0x24(%rbp), %rax
addq %rax, %rsi
movl -0x30(%rbp), %eax
subl -0x24(%rbp), %eax
movslq %eax, %rdx
callq 0x2230
movl -0x30(%rbp), %eax
subl -0x24(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x4570
movl -0x3c(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4572
movl -0x30(%rbp), %eax
cmpl -0x28(%rbp), %eax
jl 0x457c
jmp 0x458c
jmp 0x457e
movl -0x34(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x34(%rbp)
jmp 0x440e
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x45ac
movq 0x26a5d(%rip), %rax     # 0x2aff8
movq (%rax), %rdi
leaq 0x21f0a(%rip), %rsi     # 0x264af
movb $0x0, %al
callq 0x2190
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jge 0x45c1
movq -0x18(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0xe430
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq