// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/padding.c
// Function: load_unpadded_ref
int load_unpadded_ref(faidx_t *fai, char *ref_name, int ref_len, kstring_t *seq)
{
	char base;
	char *fai_ref = 0;
	int fai_ref_len = 0, k;

	fai_ref = fai_fetch(fai, ref_name, &fai_ref_len);
	if (fai_ref_len != ref_len) {
		fprintf(stderr, "[depad] ERROR: FASTA sequence %s length %i, expected %i\n", ref_name, fai_ref_len, ref_len);
		free(fai_ref);
		return -1;
	}
	ks_resize(seq, ref_len);
	seq->l = 0;
	for (k = 0; k < ref_len; ++k) {
		base = fai_ref[k];
		if (base == '-' || base == '*') {
			// Map gaps to null to match unpad_seq function
			seq->s[seq->l++] = 0;
		} else {
			int i = bam_nt16_table[(int)base];
			if (i == 0 || i==16) { // Equals maps to 0, anything unexpected to 16
				fprintf(stderr, "[depad] ERROR: Invalid character %c (ASCII %i) in FASTA sequence %s\n", base, (int)base, ref_name);
				free(fai_ref);
				return -1;
			}
			seq->s[seq->l++] = i;
		}
	}
	assert(ref_len == seq->l);
	free(fai_ref);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r15
movl %edx, %ebp
leaq 0x14(%rsp), %r12
movl $0x0, (%r12)
movq %rsi, (%rsp)
movq %r12, %rdx
callq 0x2ef9c
movq %rax, %rbx
movl (%r12), %ecx
cmpl %ebp, %ecx
jne 0x1b6db
movslq %ebp, %r8
cmpq %r8, 0x8(%r15)
jae 0x1b60b
leaq -0x1(%r8), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %r8, %r14
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%r15)
movq 0x10(%r15), %rdi
callq 0x3720
movq %r14, %r8
movq %rax, 0x10(%r15)
movq $0x0, (%r15)
testl %ebp, %ebp
jle 0x1b6b4
movl %ebp, %ebp
leaq 0x347bd(%rip), %r12     # 0x4fde0
leaq 0x25f03(%rip), %rsi     # 0x4152d
xorl %r14d, %r14d
movzbl (%rbx,%r14), %eax
cmpl $0x2d, %eax
je 0x1b63c
cmpl $0x2a, %eax
jne 0x1b650
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
movb $0x0, (%rcx,%rax)
jmp 0x1b678
movsbl %al, %ecx
movslq %ecx, %rax
movb (%r12,%rax), %r13b
testb $-0x11, %r13b
je 0x1b682
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
movb %r13b, (%rcx,%rax)
testb $-0x11, %r13b
je 0x1b6d4
incq %r14
cmpq %r14, %rbp
jne 0x1b62d
jmp 0x1b6b4
movq 0x3395f(%rip), %rax     # 0x4efe8
movq (%rax), %rdi
movq %r8, 0x8(%rsp)
movl %ecx, %edx
movq (%rsp), %r8
xorl %eax, %eax
callq 0x3750
movq %rbx, %rdi
callq 0x3350
leaq 0x25e80(%rip), %rsi     # 0x4152d
movq 0x8(%rsp), %r8
jmp 0x1b672
xorl %ebp, %ebp
cmpq %r8, (%r15)
jne 0x1b701
movq %rbx, %rdi
callq 0x3350
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x1b6c3
movq 0x33906(%rip), %rax     # 0x4efe8
movq (%rax), %rdi
leaq 0x25e08(%rip), %rsi     # 0x414f4
movq (%rsp), %rdx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3750
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x1b6bb
leaq 0x25e6a(%rip), %rdi     # 0x41572
leaq 0x25e75(%rip), %rsi     # 0x41584
leaq 0x25e78(%rip), %rcx     # 0x4158e
movl $0x67, %edx
callq 0x31b0