// File: /workspace/github_c_makefile_star2_O1/thegenemyers[P]DASCRUBBER/DB.c
// Function: Load_Subread
char *Load_Subread(DAZZ_DB *db, int i, int beg, int end, char *read, int ascii)
{ FILE      *bases  = (FILE *) db->bases;
  int64      off;
  int        len, clen;
  int        bbeg, bend;
  DAZZ_READ *r = db->reads;

  if (i < 0 || i >= db->nreads)
    { EPRINTF(EPLACE,"%s: Index out of bounds (Load_Read)\n",Prog_Name);
      EXIT(NULL);
    }
    
  if (db->loaded)
    { len = end-beg;
      strncpy(read,(char *) bases + r[i].boff + beg,len);
      if (ascii == 0)
        { if (*read < 4)
            read[-1] = read[len] = 4;
          else
            { read[len] = '\0';
              Number_Read(read);
              read[-1] = 4;
            }
        }
      else
        { if (*read < 4)
            { read[len] = 4;
              if (ascii == 1)
                Lower_Read(read);
              else
                Upper_Read(read);
              read[-1] = '\0';
            }
          else
            { read[len] = '\0';
              if ((ascii == 1) != islower(*read))
                Change_Read(read);
            }
          read[-1] = '\0';
        }
      return (read);
    }

  bbeg = beg/4;
  bend = (end-1)/4+1;

  off = r[i].boff + bbeg;
  len = end - beg;

  if (ftello(bases) != off)
    fseeko(bases,off,SEEK_SET);
  clen = bend-bbeg;
  if (clen > 0)
    { if (fread(read,clen,1,bases) != 1)
        { EPRINTF(EPLACE,"%s: Failed read of .bps file (Load_Read)\n",Prog_Name);
          EXIT(NULL);
        }
    }
  Uncompress_Read(4*clen,read);
  read += beg%4;
  read[len] = 4;
  if (ascii == 1)
    { Lower_Read(read);
      read[-1] = '\0';
    }
  else if (ascii == 2)
    { Upper_Read(read);
      read[-1] = '\0';
    }
  else
    read[-1] = 4;

  return (read);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testl %esi, %esi
js 0x5214
cmpl %esi, 0x30(%rdi)
jle 0x5214
movl %r9d, %ebp
movq %r8, %r13
movl %ecx, %r14d
movl %edx, %r15d
movq 0x58(%rdi), %r12
movq 0x60(%rdi), %rax
cmpl $0x0, 0x50(%rdi)
je 0x500e
movl %esi, %ecx
leaq (%rcx,%rcx,4), %rcx
addq 0x10(%rax,%rcx,8), %r12
subl %r15d, %r14d
movslq %r15d, %rsi
addq %r12, %rsi
movslq %r14d, %r14
movq %r13, %rdi
movq %r14, %rdx
callq 0x1060
movb (%r13), %al
testl %ebp, %ebp
je 0x5102
cmpb $0x3, %al
jg 0x5115
movb $0x4, (%r13,%r14)
movb (%r13), %al
movq %r13, %rdx
cmpl $0x1, %ebp
jne 0x51d5
cmpb $0x4, %al
je 0x51f6
leaq 0x6f97(%rip), %rcx      # 0xbf8a
movq %r13, %rdx
movsbq %al, %rax
movb (%rax,%rcx), %al
movb %al, (%rdx)
movb 0x1(%rdx), %al
incq %rdx
cmpb $0x4, %al
jne 0x4ff6
jmp 0x51f6
movl %ebp, 0xc(%rsp)
movq %r13, 0x10(%rsp)
leal 0x3(%r15), %ebp
testl %r15d, %r15d
cmovnsl %r15d, %ebp
movl %ebp, 0x8(%rsp)
sarl $0x2, %ebp
leal -0x1(%r14), %ecx
leal 0x2(%r14), %ebx
testl %ecx, %ecx
cmovnsl %ecx, %ebx
sarl $0x2, %ebx
movl %esi, %ecx
leaq (%rcx,%rcx,4), %rcx
movslq %ebp, %r13
addq 0x10(%rax,%rcx,8), %r13
movq %r12, %rdi
callq 0x1080
cmpq %r13, %rax
je 0x5061
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x1230
subl %ebp, %ebx
leal 0x1(%rbx), %r13d
testl %ebx, %ebx
movq 0x10(%rsp), %rbx
js 0x508d
movl %r13d, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x5219
movl 0x8(%rsp), %eax
andl $-0x4, %eax
subl %r15d, %r14d
subl %eax, %r15d
shll $0x2, %r13d
movl %r13d, %edi
movq %rbx, %rsi
callq 0x3400
movslq %r15d, %rax
addq %rax, %rbx
movslq %r14d, %rax
movb $0x4, (%rax,%rbx)
movl 0xc(%rsp), %eax
cmpl $0x2, %eax
movq %rbx, %r13
je 0x5171
movb $0x4, %cl
cmpl $0x1, %eax
jne 0x51fe
movb (%r13), %al
movq %r13, %rcx
cmpb $0x4, %al
je 0x5199
leaq 0x6ea3(%rip), %rdx      # 0xbf8a
movq %r13, %rcx
movsbq %al, %rax
movb (%rax,%rdx), %al
movb %al, (%rcx)
movb 0x1(%rcx), %al
incq %rcx
cmpb $0x4, %al
jne 0x50ea
jmp 0x5199
cmpb $0x3, %al
jg 0x51a0
movb $0x4, (%r13,%r14)
jmp 0x51d1
xorl %ebx, %ebx
cmpl $0x1, %ebp
sete %bpl
movb $0x0, (%r13,%r14)
callq 0x12a0
movsbq (%r13), %rdx
xorl %ecx, %ecx
testq %rdx, %rdx
je 0x51fe
movq (%rax), %rax
movzwl (%rax,%rdx,2), %eax
andl $0x200, %eax            # imm = 0x200
movb %bpl, %bl
cmpw %bx, %ax
je 0x51fe
leaq 0x1(%r13), %rax
leaq 0x6f44(%rip), %rcx      # 0xc0a0
movsbq %dl, %rdx
movb (%rdx,%rcx), %dl
movb %dl, -0x1(%rax)
movb (%rax), %dl
incq %rax
testb %dl, %dl
jne 0x515c
jmp 0x519c
movb (%r13), %al
movq %r13, %rcx
cmpb $0x4, %al
je 0x5199
leaq 0x6e0b(%rip), %rdx      # 0xbf8e
movq %r13, %rcx
movsbq %al, %rax
movb (%rax,%rdx), %al
movb %al, (%rcx)
movb 0x1(%rcx), %al
incq %rcx
cmpb $0x4, %al
jne 0x5186
movb $0x0, (%rcx)
xorl %ecx, %ecx
jmp 0x51fe
movb $0x0, (%r13,%r14)
movb (%r13), %al
movq %r13, %rcx
testb %al, %al
je 0x51ce
leaq 0x6de8(%rip), %rdx      # 0xbfa0
movq %r13, %rcx
movsbq %al, %rax
movb (%rax,%rdx), %al
movb %al, (%rcx)
movb 0x1(%rcx), %al
incq %rcx
testb %al, %al
jne 0x51bb
movb $0x4, (%rcx)
movb $0x4, %cl
jmp 0x51fe
cmpb $0x4, %al
je 0x51f6
leaq 0x6dae(%rip), %rcx      # 0xbf8e
movq %r13, %rdx
movsbq %al, %rax
movb (%rax,%rcx), %al
movb %al, (%rdx)
movb 0x1(%rdx), %al
incq %rdx
cmpb $0x4, %al
jne 0x51e3
xorl %ecx, %ecx
movb %cl, (%rdx)
movb %cl, -0x1(%r13)
movb %cl, -0x1(%r13)
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1696
callq 0x166e