// File: /workspace/github_c_makefile_star2_O1/DReichLab[P]adna/sam.c
// Function: sam_hdr_write
int sam_hdr_write(htsFile *fp, const bam_hdr_t *h)
{
	if (!fp->is_bin) {
		char *p;
		fputs(h->text, (FILE*)fp->fp);
		p = strstr(h->text, "@SQ\t"); // FIXME: we need a loop to make sure "@SQ\t" does not match something unwanted!!!
		if (p == 0) {
			int i;
			for (i = 0; i < h->n_targets; ++i) {
				fp->line.l = 0;
				kputsn("@SQ\tSN:", 7, &fp->line); kputs(h->target_name[i], &fp->line);
				kputsn("\tLN:", 4, &fp->line); kputw(h->target_len[i], &fp->line); kputc('\n', &fp->line);
				fwrite(fp->line.s, 1, fp->line.l, (FILE*)fp->fp);
			}
		}
		fflush((FILE*)fp->fp);
	} else bam_hdr_write((BGZF*)fp->fp, h);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
testb $0x1, (%rdi)
jne 0x9bb3
movq 0x28(%rbx), %rdi
movq 0x38(%r14), %rsi
callq 0x2190
movq 0x28(%rbx), %rdi
leaq 0x4bce(%rip), %rsi      # 0xe55a
callq 0x23f0
testq %rax, %rax
jne 0x9ba8
cmpl $0x0, (%rbx)
jle 0x9ba8
leaq 0x10(%r14), %r15
xorl %ebp, %ebp
movq $0x0, 0x10(%r14)
cmpq $0x8, 0x18(%r14)
ja 0x99d2
movq $0x10, 0x18(%r14)
movq 0x20(%r14), %rdi
movl $0x10, %esi
callq 0x22e0
movq %rax, 0x20(%r14)
movq 0x10(%r14), %rax
movq 0x20(%r14), %rcx
movl $0x3a4e5309, 0x3(%rcx,%rax) # imm = 0x3A4E5309
movl $0x9515340, (%rcx,%rax) # imm = 0x9515340
movq 0x10(%r14), %rax
movq 0x20(%r14), %rcx
leaq 0x7(%rax), %rdx
movq %rdx, 0x10(%r14)
movb $0x0, 0x7(%rcx,%rax)
movq 0x20(%rbx), %rax
movq (%rax,%rbp,8), %r12
movq %r12, %rdi
callq 0x2150
movq 0x10(%r14), %rcx
movslq %eax, %r13
leaq (%rcx,%r13), %rax
incq %rax
cmpq 0x18(%r14), %rax
jb 0x9a67
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 %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x18(%r14)
movq 0x20(%r14), %rdi
callq 0x22e0
movq %rax, 0x20(%r14)
movq 0x20(%r14), %rdi
addq 0x10(%r14), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x2240
addq 0x10(%r14), %r13
movq %r13, 0x10(%r14)
movq 0x20(%r14), %rax
movb $0x0, (%rax,%r13)
movq 0x10(%r14), %rax
addq $0x5, %rax
cmpq 0x18(%r14), %rax
jb 0x9ade
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 %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x18(%r14)
movq 0x20(%r14), %rdi
callq 0x22e0
movq %rax, 0x20(%r14)
movq 0x10(%r14), %rax
movq 0x20(%r14), %rcx
movl $0x3a4e4c09, (%rcx,%rax) # imm = 0x3A4E4C09
movq 0x10(%r14), %rax
movq 0x20(%r14), %rcx
leaq 0x4(%rax), %rdx
movq %rdx, 0x10(%r14)
movb $0x0, 0x4(%rcx,%rax)
movq 0x10(%rbx), %rax
movl (%rax,%rbp,4), %edi
movq %r15, %rsi
callq 0x9bd0
movq 0x10(%r14), %rax
incq %rax
cmpq 0x18(%r14), %rax
jb 0x9b63
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 %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x18(%r14)
movq 0x20(%r14), %rdi
callq 0x22e0
movq %rax, 0x20(%r14)
movq 0x10(%r14), %rax
movq 0x20(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x10(%r14)
movb $0xa, (%rcx,%rax)
movq 0x10(%r14), %rax
movq 0x20(%r14), %rcx
movb $0x0, (%rcx,%rax)
movq 0x10(%r14), %rdx
movq 0x20(%r14), %rdi
movq 0x38(%r14), %rcx
movl $0x1, %esi
callq 0x23b0
incq %rbp
movslq (%rbx), %rax
cmpq %rax, %rbp
jl 0x99a9
movq 0x38(%r14), %rdi
callq 0x22b0
jmp 0x9bbf
movq 0x38(%r14), %rdi
movq %rbx, %rsi
callq 0x8b81
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq