// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/cram/zfio.c
// Function: zfopen
zfp *zfopen(const char *path, const char *mode) {
    char path2[1024];
    zfp *zf;

    if (!(zf = (zfp *)malloc(sizeof(*zf))))
	return NULL;
    zf->fp = NULL;
    zf->gz = NULL;

    /* Try normal fopen */
    if (mode[0] != 'z' && mode[1] != 'z' &&
	NULL != (zf->fp = fopen(path, mode))) {
	unsigned char magic[2];
	if (2 != fread(magic, 1, 2, zf->fp)) {
	    free(zf);
	    return NULL;
	}
	if (!(magic[0] == 0x1f &&
	      magic[1] == 0x8b)) {
	    fseeko(zf->fp, 0, SEEK_SET);
	    return zf;
	}

	fclose(zf->fp);
	zf->fp = NULL;
    }

#ifdef HAVE_POPEN
    /*
     * I've no idea why, by gzgets is VERY slow, maybe because it handles
     * arbitrary seeks.
     * popen to gzip -cd is 3 times faster though.
     */
    if (*mode == 'w') {
    } else {
	if (access(path, R_OK) == 0) {
	    sprintf(path2, "gzip -cd < %.*s", 1000, path);
	    if (NULL != (zf->fp = popen(path2, "r")))
		return zf;
	}
	
	sprintf(path2, "gzip -cd < %.*s.gz", 1000, path);
	if (NULL != (zf->fp = popen(path2, "r")))
	    return zf;

	printf("Failed on %s\n", path);
    } else {
	sprintf(path2, "gzip > %.*s", 1000, path);
	if (NULL != (zf->fp = popen(path2, "w")))
	    return zf;
	}
	
	printf("Failed on %s\n", path);
    }
#else
    /* Gzopen instead */
    if ((zf->gz = gzopen(path, mode)))
	return zf;

    sprintf(path2, "%.*s.gz", 1020, path);
    if ((zf->gz = gzopen(path2, mode)))
	return zf;
#endif

    perror(path);

    free(zf);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x10, %edi
callq 0x69c0
movq %rax, -0x428(%rbp)
cmpq $0x0, %rax
jne 0x99ea7
movq $0x0, -0x8(%rbp)
jmp 0x9a040
movq -0x428(%rbp), %rax
movq $0x0, (%rax)
movq -0x428(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7a, %eax
je 0x99fac
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x7a, %eax
je 0x99fac
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6860
movq %rax, %rcx
movq -0x428(%rbp), %rax
movq %rcx, (%rax)
xorl %eax, %eax
cmpq %rcx, %rax
je 0x99fac
leaq -0x42a(%rbp), %rdi
movq -0x428(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %esi
movl $0x2, %edx
callq 0x6b20
movq %rax, %rcx
movl $0x2, %eax
cmpq %rcx, %rax
je 0x99f50
movq -0x428(%rbp), %rdi
callq 0x6880
movq $0x0, -0x8(%rbp)
jmp 0x9a040
movzbl -0x42a(%rbp), %eax
cmpl $0x1f, %eax
jne 0x99f6a
movzbl -0x429(%rbp), %eax
cmpl $0x8b, %eax
je 0x99f8f
movq -0x428(%rbp), %rax
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x63f0
movq -0x428(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x9a040
movq -0x428(%rbp), %rax
movq (%rax), %rdi
callq 0x66e0
movq -0x428(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6b00
movq -0x428(%rbp), %rcx
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
je 0x99fd7
movq -0x428(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x9a040
leaq -0x420(%rbp), %rdi
movq -0x10(%rbp), %rcx
leaq 0x49adf(%rip), %rsi     # 0xe3ac8
movl $0x3fc, %edx            # imm = 0x3FC
movb $0x0, %al
callq 0x6160
leaq -0x420(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6b00
movq -0x428(%rbp), %rcx
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
je 0x9a023
movq -0x428(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x9a040
movq -0x10(%rbp), %rdi
callq 0x6590
movq -0x428(%rbp), %rdi
callq 0x6880
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x430, %rsp            # imm = 0x430
popq %rbp
retq
nopl (%rax)