// File: /workspace/github_c_makefile_star2_O3/sasairc[P]clangsay/src/cow.c
// Function: open_cow
static
int open_cow(COW** cow, char* file)
{
    char*   path    = NULL;

    int     status  = 0;

    struct  stat st;

    if (check_cowfile_exists(file, &path) < 0) {
        status = -1; goto ERR;
    }

    if (stat(path, &st) < 0) {
        status = -2; goto ERR;
    }

    if ((st.st_mode & S_IFMT) == S_IFDIR) {
        status = -3; goto ERR;
    }

    if ((st.st_mode & S_IREAD) == 0) {
        status = -4; goto ERR;
    }

    if (((*cow)->fp = fopen(path, "r")) == NULL) {
        status = -5; goto ERR;
    }

    if (path != NULL) {
        free(path);
        path = NULL;
    }

    return 0;

ERR:
    switch (status) {
        case    -1:
            break;
        case    -2:
            fprintf(stderr, "%s: %s: %s\n",
                    PROGNAME, path, strerror(ENOENT));
            break;
        case    -3:
            fprintf(stderr, "%s: %s: %s\n",
                    PROGNAME, path, strerror(EISDIR));
            break;
        case    -4:
            fprintf(stderr, "%s: %s: %s\n",
                    PROGNAME, path, strerror(EACCES));
            break;
        case    -5:
            fprintf(stderr, "%s: %s\n",
                    PROGNAME, strerror(errno));
            break;
    }
    if (path != NULL) {
        free(path);
        path = NULL;
    }

    return status;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %r14
movq %rdi, 0x10(%rsp)
leaq 0x8(%rsp), %rbx
movq $0x0, (%rbx)
leaq 0x1fb5(%rip), %rdi      # 0xc29c
callq 0x2380
testq %rax, %rax
leaq 0x1fae(%rip), %rdi      # 0xc2a4
cmovneq %rax, %rdi
movq %rbx, %rsi
callq 0x3c18
testl %eax, %eax
js 0xa51f
movq 0x8(%rsp), %rax
xorl %r12d, %r12d
movq 0x8(%rax), %rax
movq (%rax,%r12,8), %rdi
callq 0x21c0
testq %rax, %rax
je 0xa3e0
movq %rax, %r13
movl $0x2, %edi
movq %r14, %rsi
leaq 0x1f3f(%rip), %rdx      # 0xc279
xorl %eax, %eax
callq 0x5bb2
testq %rax, %rax
je 0xa390
movq %rax, %rbp
movq %r13, %rdi
callq 0x21f0
testq %rax, %rax
je 0xa39a
movq %rax, %rbx
addq $0x13, %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x23a0
testl %eax, %eax
je 0xa3a1
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x23a0
xorl %r15d, %r15d
testl %eax, %eax
je 0xa3a9
movq %r13, %rdi
callq 0x21f0
movq %rax, %rbx
testq %rax, %rax
jne 0xa359
jmp 0xa39d
movq %r13, %rdi
callq 0x23f0
jmp 0xa3e0
xorl %r15d, %r15d
movb $0x1, %bl
jmp 0xa3b1
movl $0x2, %r15d
jmp 0xa3af
movl $0x3, %r15d
xorl %ebx, %ebx
movq %r13, %rdi
callq 0x23f0
movq %rbp, %rdi
callq 0x21a0
testb %bl, %bl
je 0xa3db
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x2460
xorl %r15d, %r15d
testl %eax, %eax
sete %r15b
testl %r15d, %r15d
jne 0xa41b
incq %r12
movq 0x8(%rsp), %rax
movslq (%rax), %rcx
cmpq %rcx, %r12
jl 0xa312
movq 0x6be5(%rip), %rax      # 0x10fe0
movq (%rax), %rdi
leaq 0x1eed(%rip), %rsi      # 0xc2f2
leaq 0x1e4d(%rip), %rdx      # 0xc259
movq %r14, %rcx
xorl %eax, %eax
callq 0x2450
jmp 0xa50e
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax,%r12,8), %rsi
cmpl $0x3, %r15d
je 0xa44c
cmpl $0x2, %r15d
jne 0xa47b
leaq 0x1e87(%rip), %rdx      # 0xc2c2
movl $0x3, %edi
movq %r14, %rcx
xorl %eax, %eax
callq 0x5bb2
jmp 0xa469
leaq 0x1e6f(%rip), %rdx      # 0xc2c2
leaq 0x1e1f(%rip), %r8       # 0xc279
movl $0x4, %edi
movq %r14, %rcx
xorl %eax, %eax
callq 0x5bb2
movq %rax, %r15
testq %rax, %rax
jne 0xa4ae
callq 0x2696
jmp 0xa50e
movq %r14, %rdi
callq 0x21b0
movq %rax, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x4b00
testq %rax, %rax
je 0xa50e
movq %rax, %r15
movq %r14, %rdi
callq 0x21b0
leaq 0x1(%rax), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x2470
movq 0x8(%rsp), %rdi
callq 0x3d43
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x2460
testl %eax, %eax
js 0xa52b
movl 0x30(%rsp), %eax
movl %eax, %ecx
andl $0xf000, %ecx           # imm = 0xF000
cmpl $0x4000, %ecx           # imm = 0x4000
je 0xa53a
btl $0x8, %eax
jae 0xa549
leaq 0x2372(%rip), %rsi      # 0xc85c
movq %r15, %rdi
callq 0x20f0
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
movq %rax, (%rcx)
testq %rax, %rax
je 0xa558
movq %r15, %rdi
callq 0x21a0
xorl %ebx, %ebx
jmp 0xa56a
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xa524
callq 0x3d43
jmp 0xa524
callq 0x27ac
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xa56a
movq %r15, %rdi
callq 0x276d
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
jmp 0xa562
movq %r15, %rdi
callq 0x272e
movl $0xfffffffd, %ebx       # imm = 0xFFFFFFFD
jmp 0xa562
movq %r15, %rdi
callq 0x26ef
movl $0xfffffffc, %ebx       # imm = 0xFFFFFFFC
jmp 0xa562
callq 0x26bb
movl $0xfffffffb, %ebx       # imm = 0xFFFFFFFB
movq %r15, %rdi
callq 0x21a0
movl %ebx, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq