// File: /workspace/github_cpp_makefile_star2_O3/mh0fm4[P]SCDC/test/demos/fstream/../../../src/lib/redirect/fstream/basic_file_scdc.h
// Function: scdc::__basic_file_scdc<char>::open(char const*, std::_Ios_Openmode, int)
__basic_file* 
      open(const char* __name, ios_base::openmode __mode, int __prot = 0664)
      {
        TRACE(__class__, __func__, __name);

        __basic_file* ret = 0;

        do_read = __mode & std::ios_base::in;
        do_write = __mode & std::ios_base::out;
        do_truncate = __mode & std::ios_base::trunc;
#if BASIC_FILE_SCDC_APPEND
        do_append = __mode & std::ios_base::app;
#endif
        offset = 0;
        eof = false;

        char p[256];
        const char *f = strrchr(__name, '/');

        if (f)
        {
          int pn = f - __name + 1;
          strncpy(p, __name, pn);
          p[pn] = '\0';
          ++f;
        }

        the_fstream_scdc_env.init();

        // open path without file and fail if it fails (i.e., does not exist)
        _M_dataset = scdc_dataset_open(p);
        if (_M_dataset == SCDC_DATASET_NULL) goto do_return;

        char cmd[256];

        // if trunc and out then 'rm file'
        if (do_truncate && do_write)
        {
          sprintf(cmd, "rm %s", f);
          scdc_dataset_cmd(_M_dataset, cmd, NULL, NULL);
        }

        // if out then 'put file' without input -> create empty file if it does not exist, yet
        if (do_write)
        {
          sprintf(cmd, "put %s", f);
          scdc_dataset_cmd(_M_dataset, cmd, NULL, NULL);
        }

        //* 'cd file' and fail if it does not exist */
        sprintf(cmd, "cd %s", f);
        if (scdc_dataset_cmd(_M_dataset, cmd, NULL, NULL) != SCDC_SUCCESS) goto do_return;

        ret = this;

do_return:
        if (!ret)
        {
          scdc_dataset_close(_M_dataset);

          _M_dataset = SCDC_DATASET_NULL;
        }

        if (_M_dataset == SCDC_DATASET_NULL) the_fstream_scdc_env.release();

        return ret;
      }

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rsi, %r15
movq %rdi, %rbx
movl %edx, %eax
shrb $0x3, %al
andb $0x1, %al
movb %al, 0x9(%rdi)
movl %edx, %eax
shrb $0x4, %al
andb $0x1, %al
movb %al, 0xa(%rdi)
shrb $0x5, %dl
andb $0x1, %dl
movb %dl, 0xb(%rdi)
movq $0x0, 0x10(%rdi)
movb $0x0, 0x18(%rdi)
movq %rsi, %rdi
movl $0x2f, %esi
callq 0xb600
testq %rax, %rax
je 0xe84d
movq %rax, %r14
subl %r15d, %eax
incl %eax
movslq %eax, %r12
leaq 0x100(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xb2c0
movb $0x0, 0x100(%rsp,%r12)
incq %r14
jmp 0xe850
xorl %r14d, %r14d
leaq 0x6bdb5(%rip), %rdi     # 0x7a60c
callq 0xe946
xorl %r15d, %r15d
leaq 0x100(%rsp), %rdi
xorl %eax, %eax
callq 0xf7cd
movq %rax, (%rbx)
testq %rax, %rax
je 0xe916
movb 0xa(%rbx), %al
cmpb $0x1, 0xb(%rbx)
jne 0xe8b2
testb $0x1, %al
je 0xe8b2
leaq 0x4e921(%rip), %rsi     # 0x5d1af
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xb0e0
movq (%rbx), %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x103cb
movb 0xa(%rbx), %al
testb $0x1, %al
je 0xe8de
leaq 0x4e8f8(%rip), %rsi     # 0x5d1b5
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xb0e0
movq (%rbx), %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x103cb
leaq 0x4e8d7(%rip), %rsi     # 0x5d1bc
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xb0e0
movq (%rbx), %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x103cb
movq (%rbx), %r15
cmpq $0x1, %rax
jne 0xe916
testq %r15, %r15
jne 0xe933
jmp 0xe927
movq %r15, %rdi
callq 0xf8bf
movq $0x0, (%rbx)
xorl %ebx, %ebx
leaq 0x6bcde(%rip), %rdi     # 0x7a60c
callq 0xcb04
movq %rbx, %rax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop