// File: /workspace/github_c_makefile_star2_O2/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 0x3fb5
cmpl %esi, 0x30(%rdi)
jle 0x3fb5
movl %r9d, %r13d
movq %r8, %rbx
movl %ecx, %r14d
movl %edx, %r15d
movq 0x58(%rdi), %r12
movq 0x60(%rdi), %rcx
cmpl $0x0, 0x50(%rdi)
je 0x3e9a
movl %esi, %eax
imulq $0x28, %rax, %rax
addq 0x10(%rcx,%rax), %r12
subl %r15d, %r14d
movslq %r15d, %rsi
addq %r12, %rsi
movslq %r14d, %r14
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1060
movb (%rbx), %al
testl %r13d, %r13d
je 0x3f47
cmpb $0x3, %al
jg 0x3f5c
movb $0x4, (%rbx,%r14)
cmpl $0x1, %r13d
je 0x3f3d
jmp 0x3f52
movl %r13d, 0x10(%rsp)
pushq $0x4
popq %rdi
movl %r15d, %eax
cltd
idivl %edi
movl %eax, %r8d
movl %edx, 0xc(%rsp)
leal -0x1(%r14), %eax
cltd
idivl %edi
movl %eax, %ebp
movl %esi, %eax
imulq $0x28, %rax, %rax
movl %r8d, 0x14(%rsp)
movslq %r8d, %r13
addq 0x10(%rcx,%rax), %r13
movq %r12, %rdi
callq 0x1080
cmpq %r13, %rax
je 0x3ee5
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x1230
subl 0x14(%rsp), %ebp
leal 0x1(%rbp), %r13d
testl %ebp, %ebp
js 0x3f0c
movl %r13d, %esi
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r12, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x3fdc
subl %r15d, %r14d
shll $0x2, %r13d
movl %r13d, %edi
movq %rbx, %rsi
callq 0x2337
movslq 0xc(%rsp), %rax
addq %rax, %rbx
movslq %r14d, %rax
movb $0x4, (%rax,%rbx)
movl 0x10(%rsp), %ecx
cmpl $0x2, %ecx
je 0x3f52
movb $0x4, %al
cmpl $0x1, %ecx
jne 0x3fa0
movq %rbx, %rdi
callq 0x2395
jmp 0x3f8d
cmpb $0x3, %al
jg 0x3f91
movb $0x4, (%rbx,%r14)
jmp 0x3f9e
movq %rbx, %rdi
callq 0x23b4
jmp 0x3f8d
xorl %ebp, %ebp
cmpl $0x1, %r13d
sete %bpl
movb $0x0, (%rbx,%r14)
callq 0x12a0
movq (%rax), %rax
movsbq (%rbx), %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x200, %eax            # imm = 0x200
cmpw %bp, %ax
je 0x3f8d
movq %rbx, %rdi
callq 0x242e
xorl %eax, %eax
jmp 0x3fa0
movb $0x0, (%rbx,%r14)
movq %rbx, %rdi
callq 0x23f2
movb $0x4, %al
movb %al, -0x1(%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa03c(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0xc922(%rip), %rdx      # 0x108e8
leaq 0x5685(%rip), %rsi      # 0x9652
xorl %eax, %eax
callq 0x11a0
pushq $0x1
popq %rdi
callq 0x1270
movq 0xa015(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0xc8fb(%rip), %rdx      # 0x108e8
leaq 0x5683(%rip), %rsi      # 0x9677
jmp 0x3fcd