// File: mh0fm4[P]SCDC/src/components/dataprov/dataprov_fs2.cc
// Function: scdc_dataset_fs2::open_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool, bool)
FILE *open_file(const string &path, bool read, bool write)
    {
      int mode = (read?1:0) + (write?2:0);

#if SCDC_DATASET_FS_LEAVE_PWD_OPEN
      if (pwd_FILE && pwd_FILE_path == path)
      {
        if (mode == 0 || mode == pwd_FILE_mode || pwd_FILE_mode == 3) return pwd_FILE;

        mode |= pwd_FILE_mode;
      }
#endif

#if SCDC_DATASET_FS_LEAVE_PWD_OPEN
      close_pwd_file();
#endif

      const char *m = 0;

      switch (mode)
      {
        case 0: m = "r"; mode = 1; break;
        case 1: m = "r"; break;
        case 2: if (z_fs_exists(path.c_str())) { m = "r+"; mode = 3; } else m = "w"; break;
        case 3: m = (z_fs_exists(path.c_str()))?"r+":"w+"; break;
      }

      FILE *file = fopen(path.c_str(), m);

#if SCDC_DATASET_FS_LEAVE_PWD_OPEN
      if (file)
      {
        pwd_FILE = file;
        pwd_FILE_path = path;
        pwd_FILE_mode = mode;
      }
#endif

      return file;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %cl, %al
movb %dl, %cl
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %cl
movb %cl, -0x19(%rbp)
andb $0x1, %al
movb %al, -0x1a(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movb -0x19(%rbp), %sil
xorl %ecx, %ecx
movl $0x1, %edx
testb $0x1, %sil
cmovnel %edx, %ecx
movb -0x1a(%rbp), %dil
xorl %edx, %edx
movl $0x2, %esi
testb $0x1, %dil
cmovnel %esi, %edx
addl %edx, %ecx
movl %ecx, -0x20(%rbp)
cmpq $0x0, 0x40(%rax)
je 0x775e8
movq -0x38(%rbp), %rdi
addq $0x48, %rdi
movq -0x18(%rbp), %rsi
callq 0x316b0
testb $0x1, %al
jne 0x775ae
jmp 0x775e8
cmpl $0x0, -0x20(%rbp)
je 0x775ca
movq -0x38(%rbp), %rcx
movl -0x20(%rbp), %eax
cmpl 0x68(%rcx), %eax
je 0x775ca
movq -0x38(%rbp), %rax
cmpl $0x3, 0x68(%rax)
jne 0x775db
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x776fb
movq -0x38(%rbp), %rax
movl 0x68(%rax), %eax
orl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x38(%rbp), %rdi
callq 0x77720
movq $0x0, -0x28(%rbp)
movl -0x20(%rbp), %eax
movq %rax, -0x40(%rbp)
subq $0x3, %rax
ja 0x776b0
movq -0x40(%rbp), %rax
leaq 0x30cab(%rip), %rcx     # 0xa82c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x2e1ea(%rip), %rax     # 0xa580f
movq %rax, -0x28(%rbp)
movl $0x1, -0x20(%rbp)
jmp 0x776b0
leaq 0x2e1d6(%rip), %rax     # 0xa580f
movq %rax, -0x28(%rbp)
jmp 0x776b0
movq -0x18(%rbp), %rdi
callq 0xc260
movq %rax, %rdi
callq 0x5d420
cmpq $0x0, %rax
je 0x7766a
leaq 0x30012(%rip), %rax     # 0xa766f
movq %rax, -0x28(%rbp)
movl $0x3, -0x20(%rbp)
jmp 0x77675
leaq 0x30001(%rip), %rax     # 0xa7672
movq %rax, -0x28(%rbp)
jmp 0x776b0
movq -0x18(%rbp), %rdi
callq 0xc260
movq %rax, %rdi
callq 0x5d420
cmpq $0x0, %rax
je 0x7769b
leaq 0x2ffda(%rip), %rax     # 0xa766f
movq %rax, -0x48(%rbp)
jmp 0x776a8
leaq 0x30df2(%rip), %rax     # 0xa8494
movq %rax, -0x48(%rbp)
jmp 0x776a8
movq -0x48(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0xc260
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0xc810
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x776f3
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rax
movq %rax, 0x40(%rdi)
movq -0x18(%rbp), %rsi
addq $0x48, %rdi
callq 0xc070
movq -0x38(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %ecx, 0x68(%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop