// File: /workspace/github_c_makefile_star2_O3/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 0x9d9c
movq 0x28(%rbx), %rdi
movq 0x38(%r14), %rsi
callq 0x2190
movq 0x28(%rbx), %rdi
leaq 0x4a6f(%rip), %rsi      # 0xe5d6
callq 0x23f0
testq %rax, %rax
jne 0x9d91
cmpl $0x0, (%rbx)
jle 0x9d91
leaq 0x10(%r14), %r15
xorl %ebp, %ebp
movq $0x0, 0x10(%r14)
cmpq $0x9, 0x18(%r14)
jb 0x9b9b
movq 0x20(%r14), %rax
xorl %ecx, %ecx
jmp 0x9bb9
movq $0x10, 0x18(%r14)
movq 0x20(%r14), %rdi
movl $0x10, %esi
callq 0x22e0
movq %rax, 0x20(%r14)
movq 0x10(%r14), %rcx
movl $0x3a4e5309, 0x3(%rax,%rcx) # imm = 0x3A4E5309
movl $0x9515340, (%rax,%rcx) # 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), %rdi
movslq %eax, %r13
leaq (%rdi,%r13), %rax
incq %rax
cmpq 0x18(%r14), %rax
jae 0x9c07
movq 0x20(%r14), %rax
jmp 0x9c50
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), %rdi
addq %rax, %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), %rcx
leaq 0x5(%rcx), %rax
cmpq 0x18(%r14), %rax
jae 0x9c83
movq 0x20(%r14), %rax
jmp 0x9ccc
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), %rcx
movl $0x3a4e4c09, (%rax,%rcx) # 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 0x9db9
movq 0x10(%r14), %rdx
leaq 0x1(%rdx), %rcx
cmpq 0x18(%r14), %rcx
jae 0x9d0b
movq 0x20(%r14), %rax
jmp 0x9d58
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x18(%r14)
movq 0x20(%r14), %rdi
callq 0x22e0
movq %rax, 0x20(%r14)
movq 0x10(%r14), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, 0x10(%r14)
movb $0xa, (%rax,%rdx)
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 0x9b84
movq 0x38(%r14), %rdi
callq 0x22b0
jmp 0x9da8
movq 0x38(%r14), %rdi
movq %rbx, %rsi
callq 0x8d94
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq