// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/cram/mFILE.c
// Function: mfreopen
mFILE *mfreopen(const char *path, const char *mode_str, FILE *fp) {
    mFILE *mf;
    int r = 0, w = 0, a = 0, b = 0, x = 0, mode = 0;

    /* Parse mode:
     * r = read file contents (if truncated => don't read)
     * w = write on close
     * a = position at end of buffer
     * x = position at same location as the original fp, don't seek on flush
     * + = for update (read and write)
     * m = mmap (read only)
     */
    if (strchr(mode_str, 'r'))
        r = 1, mode |= MF_READ;
    if (strchr(mode_str, 'w'))
        w = 1, mode |= MF_WRITE | MF_TRUNC;
    if (strchr(mode_str, 'a'))
        w = a = 1, mode |= MF_WRITE | MF_APPEND;
    if (strchr(mode_str, 'b'))
        b = 1, mode |= MF_BINARY;
    if (strchr(mode_str, 'x'))
        x = 1;
    if (strchr(mode_str, '+')) {
        w = 1, mode |= MF_READ | MF_WRITE;
        if (a)
            r = 1;
    }
#ifdef HAVE_MMAP
    if (strchr(mode_str, 'm'))
        if (!w) mode |= MF_MMAP;
#endif

    if (r) {
        mf = mfcreate(NULL, 0);
        if (NULL == mf) return NULL;
        if (!(mode & MF_TRUNC)) {
#ifdef HAVE_MMAP
            if (mode & MF_MMAP) {
                if (mfmmap(mf, fp, path) == -1) {
                    mf->data = NULL;
                    mode &= ~MF_MMAP;
                }
            }
#endif
            if (!mf->data) {
                mf->data = mfload(fp, path, &mf->size, b);
                if (!mf->data) {
                    free(mf);
                    return NULL;
                }
                mf->alloced = mf->size;
                if (!a)
                    fseek(fp, 0, SEEK_SET);
            }
        }
    } else if (w) {
        /* Write - initialise the data structures */
        mf = mfcreate(NULL, 0);
        if (NULL == mf) return NULL;
    } else {
        hts_log_error("Must specify either r, w or a for mode");
        return NULL;
    }
    mf->fp = fp;
    mf->mode = mode;

    if (x) {
        mf->mode |= MF_MODEX;
    }

    if (a) {
        mf->flush_pos = mf->size;
        fseek(fp, 0, SEEK_END);
    }

    return mf;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movl $0x72, %esi
callq 0x4170
cmpq $0x0, %rax
je 0x80112
movl $0x1, -0x2c(%rbp)
movl -0x40(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movl $0x77, %esi
callq 0x4170
cmpq $0x0, %rax
je 0x80136
movl $0x1, -0x30(%rbp)
movl -0x40(%rbp), %eax
orl $0x12, %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movl $0x61, %esi
callq 0x4170
cmpq $0x0, %rax
je 0x80161
movl $0x1, -0x34(%rbp)
movl $0x1, -0x30(%rbp)
movl -0x40(%rbp), %eax
orl $0x6, %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movl $0x62, %esi
callq 0x4170
cmpq $0x0, %rax
je 0x80185
movl $0x1, -0x38(%rbp)
movl -0x40(%rbp), %eax
orl $0x8, %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movl $0x78, %esi
callq 0x4170
cmpq $0x0, %rax
je 0x801a0
movl $0x1, -0x3c(%rbp)
movq -0x18(%rbp), %rdi
movl $0x2b, %esi
callq 0x4170
cmpq $0x0, %rax
je 0x801d3
movl $0x1, -0x30(%rbp)
movl -0x40(%rbp), %eax
orl $0x3, %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x801d1
movl $0x1, -0x2c(%rbp)
jmp 0x801d3
cmpl $0x0, -0x2c(%rbp)
je 0x80286
xorl %eax, %eax
movl %eax, %edi
xorl %esi, %esi
callq 0x7fe30
movq %rax, -0x28(%rbp)
xorl %eax, %eax
cmpq -0x28(%rbp), %rax
jne 0x80201
movq $0x0, -0x8(%rbp)
jmp 0x80330
movl -0x40(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x80284
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x80282
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
addq $0x20, %rdx
movl -0x38(%rbp), %ecx
callq 0x80340
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x8025b
movq -0x28(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x80330
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
cmpl $0x0, -0x34(%rbp)
jne 0x80280
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x4520
jmp 0x80282
jmp 0x80284
jmp 0x802d8
cmpl $0x0, -0x30(%rbp)
je 0x802b2
xorl %eax, %eax
movl %eax, %edi
xorl %esi, %esi
callq 0x7fe30
movq %rax, -0x28(%rbp)
xorl %eax, %eax
cmpq -0x28(%rbp), %rax
jne 0x802b0
movq $0x0, -0x8(%rbp)
jmp 0x80330
jmp 0x802d6
movl $0x1, %edi
leaq 0x75e49(%rip), %rsi     # 0xf6107
leaq 0x75e4b(%rip), %rdx     # 0xf6110
movb $0x0, %al
callq 0x1b030
movq $0x0, -0x8(%rbp)
jmp 0x80330
jmp 0x802d8
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl -0x40(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x1c(%rax)
cmpl $0x0, -0x3c(%rbp)
je 0x80300
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %ecx
orl $0x20, %ecx
movl %ecx, 0x1c(%rax)
cmpl $0x0, -0x34(%rbp)
je 0x80328
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x4520
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)