// File: /workspace/github_c_makefile_star2_O0/DReichLab[P]adna/sam.c
// Function: bam_hdr_write
int bam_hdr_write(BGZF *fp, const bam_hdr_t *h)
{
	char buf[4];
	int32_t i, name_len, x;
	// write "BAM1"
	strncpy(buf, "BAM\1", 4);
	bgzf_write(fp, buf, 4);
	// write plain text and the number of reference sequences
	if (fp->is_be) {
		x = ed_swap_4(h->l_text);
		bgzf_write(fp, &x, 4);
		if (h->l_text) bgzf_write(fp, h->text, h->l_text);
		x = ed_swap_4(h->n_targets);
		bgzf_write(fp, &x, 4);
	} else {
		bgzf_write(fp, &h->l_text, 4);
		if (h->l_text) bgzf_write(fp, h->text, h->l_text);
		bgzf_write(fp, &h->n_targets, 4);
	}
	// write sequence names and lengths
	for (i = 0; i != h->n_targets; ++i) {
		char *p = h->target_name[i];
		name_len = strlen(p) + 1;
		if (fp->is_be) {
			x = ed_swap_4(name_len);
			bgzf_write(fp, &x, 4);
		} else bgzf_write(fp, &name_len, 4);
		bgzf_write(fp, p, name_len);
		if (fp->is_be) {
			x = ed_swap_4(h->target_len[i]);
			bgzf_write(fp, &x, 4);
		} else bgzf_write(fp, &h->target_len[i], 4);
	}
	bgzf_flush(fp);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x14(%rbp), %rdi
leaq 0x68ed(%rip), %rsi      # 0x13438
movl $0x4, %edx
callq 0x2070
movq -0x8(%rbp), %rdi
leaq -0x14(%rbp), %rsi
movl $0x4, %edx
callq 0x57d0
movq -0x8(%rbp), %rax
movl (%rax), %eax
shll $0xc, %eax
sarl $0x1e, %eax
cmpl $0x0, %eax
je 0xcbdf
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edi
callq 0xcd40
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
movl $0x4, %edx
callq 0x57d0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0xcbbd
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %edx
callq 0x57d0
movq -0x10(%rbp), %rax
movl (%rax), %edi
callq 0xcd40
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
movl $0x4, %edx
callq 0x57d0
jmp 0xcc2b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
movl $0x4, %edx
callq 0x57d0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0xcc19
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %edx
callq 0x57d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x4, %edx
callq 0x57d0
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
je 0xcd25
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x2150
addq $0x1, %rax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
shll $0xc, %eax
sarl $0x1e, %eax
cmpl $0x0, %eax
je 0xcc95
movl -0x1c(%rbp), %edi
callq 0xcd40
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
movl $0x4, %edx
callq 0x57d0
jmp 0xcca7
movq -0x8(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
movl $0x4, %edx
callq 0x57d0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0x57d0
movq -0x8(%rbp), %rax
movl (%rax), %eax
shll $0xc, %eax
sarl $0x1e, %eax
cmpl $0x0, %eax
je 0xccf4
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0xcd40
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
movl $0x4, %edx
callq 0x57d0
jmp 0xcd15
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movslq -0x18(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
movl $0x4, %edx
callq 0x57d0
jmp 0xcd17
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xcc32
movq -0x8(%rbp), %rdi
callq 0x53e0
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)