// File: /workspace/github_c_makefile_star2_O3/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 0x5252
cmpl %esi, 0x30(%rdi)
jle 0x5252
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 0x5051
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 0x5145
cmpb $0x3, %al
jg 0x5158
movb $0x4, (%r13,%r14)
movb (%r13), %al
movq %r13, %rcx
cmpl $0x1, %ebp
jne 0x5216
cmpb $0x4, %al
je 0x5237
leaq 0x6fb4(%rip), %rdx      # 0xbfea
movq %r13, %rcx
movsbq %al, %rax
movb (%rax,%rdx), %al
movb %al, (%rcx)
movb 0x1(%rcx), %al
incq %rcx
cmpb $0x4, %al
jne 0x5039
jmp 0x5237
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 0x50a4
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 0x50d0
movl %r13d, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x5257
movl 0x8(%rsp), %eax
andl $-0x4, %eax
subl %r15d, %r14d
subl %eax, %r15d
shll $0x2, %r13d
movl %r13d, %edi
movq %rbx, %rsi
callq 0x330c
movslq %r15d, %rax
addq %rax, %rbx
movslq %r14d, %rax
movb $0x4, (%rax,%rbx)
movl 0xc(%rsp), %eax
cmpl $0x2, %eax
movq %rbx, %r13
je 0x51b7
movb $0x4, %cl
cmpl $0x1, %eax
jne 0x523c
movb (%r13), %al
movq %r13, %rcx
cmpb $0x4, %al
je 0x5237
leaq 0x6ec0(%rip), %rdx      # 0xbfea
movq %r13, %rcx
movsbq %al, %rax
movb (%rax,%rdx), %al
movb %al, (%rcx)
movb 0x1(%rcx), %al
incq %rcx
cmpb $0x4, %al
jne 0x512d
jmp 0x5237
cmpb $0x3, %al
jg 0x51e1
movb $0x4, (%r13,%r14)
jmp 0x5212
xorl %ebx, %ebx
cmpl $0x1, %ebp
sete %bpl
movb $0x0, (%r13,%r14)
callq 0x12a0
movsbq (%r13), %rdx
xorl %ecx, %ecx
testq %rdx, %rdx
je 0x523c
movq (%rax), %rax
movzwl (%rax,%rdx,2), %eax
andl $0x200, %eax            # imm = 0x200
movb %bpl, %bl
cmpw %bx, %ax
je 0x523c
leaq 0x1(%r13), %rax
leaq 0x6f61(%rip), %rcx      # 0xc100
movsbq %dl, %rdx
movb (%rdx,%rcx), %dl
movb %dl, -0x1(%rax)
movb (%rax), %dl
incq %rax
testb %dl, %dl
jne 0x519f
jmp 0x523a
movb (%r13), %al
movq %r13, %rcx
cmpb $0x4, %al
je 0x5237
leaq 0x6e25(%rip), %rdx      # 0xbfee
movq %r13, %rcx
movsbq %al, %rax
movb (%rax,%rdx), %al
movb %al, (%rcx)
movb 0x1(%rcx), %al
incq %rcx
cmpb $0x4, %al
jne 0x51cc
jmp 0x5237
movb $0x0, (%r13,%r14)
movb (%r13), %al
movq %r13, %rcx
testb %al, %al
je 0x520f
leaq 0x6e07(%rip), %rdx      # 0xc000
movq %r13, %rcx
movsbq %al, %rax
movb (%rax,%rdx), %al
movb %al, (%rcx)
movb 0x1(%rcx), %al
incq %rcx
testb %al, %al
jne 0x51fc
movb $0x4, (%rcx)
movb $0x4, %cl
jmp 0x523c
cmpb $0x4, %al
je 0x5237
leaq 0x6dcd(%rip), %rdx      # 0xbfee
movq %r13, %rcx
movsbq %al, %rax
movb (%rax,%rdx), %al
movb %al, (%rcx)
movb 0x1(%rcx), %al
incq %rcx
cmpb $0x4, %al
jne 0x5224
movb $0x0, (%rcx)
xorl %ecx, %ecx
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