// File: /workspace/github_c_makefile_star2_O0/skoren[P]bacValidation/bamcat.c
// Function: samopen
samfile_t *samopen(const char *fn, const char *mode, const void *aux)
{
	samfile_t *fp;
	fp = (samfile_t*)calloc(1, sizeof(samfile_t));
	if (strchr(mode, 'r')) { // read
		fp->type |= TYPE_READ;
		if (strchr(mode, 'b')) { // binary
			fp->type |= TYPE_BAM;
			fp->x.bam = strcmp(fn, "-")? bam_open(fn, "r") : bam_dopen(fileno(stdin), "r");
			if (fp->x.bam == 0) goto open_err_ret;
			fp->header = bam_header_read(fp->x.bam);
		} else { // text
			fp->x.tamr = sam_open(fn);
			if (fp->x.tamr == 0) goto open_err_ret;
			fp->header = sam_header_read(fp->x.tamr);
			if (fp->header->n_targets == 0) { // no @SQ fields
				if (aux) { // check if aux is present
					bam_header_t *textheader = fp->header;
					fp->header = sam_header_read2((const char*)aux);
					if (fp->header == 0) goto open_err_ret;
					append_header_text(fp->header, textheader->text, textheader->l_text);
					bam_header_destroy(textheader);
				}
				if (fp->header->n_targets == 0 && bam_verbose >= 1)
					fprintf(stderr, "[samopen] no @SQ lines in the header.\n");
			} else if (bam_verbose >= 2) fprintf(stderr, "[samopen] SAM header is present: %d sequences.\n", fp->header->n_targets);
		}
	} else if (strchr(mode, 'w')) { // write
    fprintf(stderr, "Write not supported here.\n");
    exit(1);
  }

	return fp;

open_err_ret:
	free(fp);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x1, %edi
movl $0x18, %esi
callq 0x3210
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
movl $0x72, %esi
callq 0x3110
cmpq $0x0, %rax
je 0x3bcc
movq -0x28(%rbp), %rax
movl (%rax), %ecx
orl $0x2, %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rdi
movl $0x62, %esi
callq 0x3110
cmpq $0x0, %rax
je 0x3ac2
movq -0x28(%rbp), %rax
movl (%rax), %ecx
orl $0x1, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rdi
leaq 0xe5e8(%rip), %rsi      # 0x12030
callq 0x3570
cmpl $0x0, %eax
je 0x3a68
movq -0x10(%rbp), %rdi
leaq 0xe85a(%rip), %rsi      # 0x122b7
callq 0x3c30
movq %rax, -0x38(%rbp)
jmp 0x3a89
movq 0x13551(%rip), %rax     # 0x16fc0
movq (%rax), %rdi
callq 0x3400
movl %eax, %edi
leaq 0xe837(%rip), %rsi      # 0x122b7
callq 0x3d70
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x3aa5
jmp 0x3c0e
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3ea0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x3bca
movq -0x10(%rbp), %rdi
callq 0x4110
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x3ae6
jmp 0x3c0e
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x41f0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
cmpl $0x0, (%rax)
jne 0x3b9b
cmpq $0x0, -0x20(%rbp)
je 0x3b6b
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
callq 0x4300
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x3b46
jmp 0x3c0e
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x30(%rbp), %rax
movl 0x30(%rax), %edx
callq 0x4530
movq -0x30(%rbp), %rdi
callq 0x4670
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
cmpl $0x0, (%rax)
jne 0x3b99
cmpl $0x1, 0x13841(%rip)     # 0x173c0
jl 0x3b99
movq 0x13448(%rip), %rax     # 0x16fd0
movq (%rax), %rdi
leaq 0xe4a0(%rip), %rsi      # 0x12032
movb $0x0, %al
callq 0x3590
jmp 0x3bc8
cmpl $0x2, 0x1381e(%rip)     # 0x173c0
jl 0x3bc6
movq 0x13425(%rip), %rax     # 0x16fd0
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl (%rax), %edx
leaq 0xe49a(%rip), %rsi      # 0x12059
movb $0x0, %al
callq 0x3590
jmp 0x3bc8
jmp 0x3bca
jmp 0x3c04
movq -0x18(%rbp), %rdi
movl $0x77, %esi
callq 0x3110
cmpq $0x0, %rax
je 0x3c02
movq 0x133e9(%rip), %rax     # 0x16fd0
movq (%rax), %rdi
leaq 0xe498(%rip), %rsi      # 0x12089
movb $0x0, %al
callq 0x3590
movl $0x1, %edi
callq 0x34b0
jmp 0x3c04
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3c1f
movq -0x28(%rbp), %rdi
callq 0x3490
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)