// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/samtools-0.1.18/bam.c
// Function: bam_header_write
int bam_header_write(bamFile fp, const bam_header_t *header)
{
	char buf[4];
	int32_t i, name_len, x;
	// write "BAM1"
	strncpy(buf, "BAM\001", 4);
	bam_write(fp, buf, 4);
	// write plain text and the number of reference sequences
	if (bam_is_be) {
		x = bam_swap_endian_4(header->l_text);
		bam_write(fp, &x, 4);
		if (header->l_text) bam_write(fp, header->text, header->l_text);
		x = bam_swap_endian_4(header->n_targets);
		bam_write(fp, &x, 4);
	} else {
		bam_write(fp, &header->l_text, 4);
		if (header->l_text) bam_write(fp, header->text, header->l_text);
		bam_write(fp, &header->n_targets, 4);
	}
	// write sequence names and lengths
	for (i = 0; i != header->n_targets; ++i) {
		char *p = header->target_name[i];
		name_len = strlen(p) + 1;
		if (bam_is_be) {
			x = bam_swap_endian_4(name_len);
			bam_write(fp, &x, 4);
		} else bam_write(fp, &name_len, 4);
		bam_write(fp, p, name_len);
		if (bam_is_be) {
			x = bam_swap_endian_4(header->target_len[i]);
			bam_write(fp, &x, 4);
		} else bam_write(fp, &header->target_len[i], 4);
	}
	bgzf_flush(fp);
	return 0;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
leaq 0x14(%rsp), %rdi
leaq 0x237b4a(%rip), %rsi    # 0x59d624
movl $0x4, %edx
callq 0x19330
movq 0x20(%rsp), %rdi
leaq 0x14(%rsp), %rsi
movl $0x4, %edx
callq 0x4f7dd0
leaq 0x2dd549(%rip), %rax    # 0x643048
cmpl $0x0, (%rax)
je 0x365b7c
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rax
movl %eax, %edi
callq 0x365cf0
movl %eax, 0x8(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x4, %edx
callq 0x4f7dd0
movq 0x18(%rsp), %rax
cmpq $0x0, 0x30(%rax)
je 0x365b56
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x40(%rax), %rsi
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rax
movl %eax, %edx
callq 0x4f7dd0
movq 0x18(%rsp), %rax
movl (%rax), %edi
callq 0x365cf0
movl %eax, 0x8(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x4, %edx
callq 0x4f7dd0
jmp 0x365bd2
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
addq $0x30, %rsi
movl $0x4, %edx
callq 0x4f7dd0
movq 0x18(%rsp), %rax
cmpq $0x0, 0x30(%rax)
je 0x365bbe
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x40(%rax), %rsi
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rax
movl %eax, %edx
callq 0x4f7dd0
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl $0x4, %edx
callq 0x4f7dd0
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
movq 0x18(%rsp), %rcx
cmpl (%rcx), %eax
je 0x365cd9
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, (%rsp)
movq (%rsp), %rdi
callq 0x192b0
addq $0x1, %rax
movl %eax, 0xc(%rsp)
leaq 0x2dd42f(%rip), %rax    # 0x643048
cmpl $0x0, (%rax)
je 0x365c41
movl 0xc(%rsp), %edi
callq 0x365cf0
movl %eax, 0x8(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x4, %edx
callq 0x4f7dd0
jmp 0x365c55
movq 0x20(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movl $0x4, %edx
callq 0x4f7dd0
movq 0x20(%rsp), %rdi
movq (%rsp), %rsi
movl 0xc(%rsp), %edx
callq 0x4f7dd0
leaq 0x2dd3da(%rip), %rax    # 0x643048
cmpl $0x0, (%rax)
je 0x365ca3
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x365cf0
movl %eax, 0x8(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x4, %edx
callq 0x4f7dd0
jmp 0x365cc7
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rsi
movslq 0x10(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rsi
movl $0x4, %edx
callq 0x4f7dd0
jmp 0x365cc9
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x365bda
movq 0x20(%rsp), %rdi
callq 0x4f7890
xorl %eax, %eax
addq $0x28, %rsp
retq
nopw (%rax,%rax)