// File: /workspace/github_cpp_makefile_star2_O1/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 0xe763
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 0xe766
xorl %r14d, %r14d
leaq 0x6be9f(%rip), %rdi     # 0x7a60c
callq 0xe85e
xorl %r15d, %r15d
leaq 0x100(%rsp), %rdi
xorl %eax, %eax
callq 0xf6fe
movq %rax, (%rbx)
testq %rax, %rax
je 0xe825
cmpb $0x1, 0xb(%rbx)
jne 0xe7c4
cmpb $0x1, 0xa(%rbx)
jne 0xe7c4
leaq 0x4ea0c(%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 0x102fc
cmpb $0x1, 0xa(%rbx)
jne 0xe7f2
leaq 0x4e9e4(%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 0x102fc
leaq 0x4e9c3(%rip), %rsi     # 0x5d1bc
xorl %r15d, %r15d
movq %rsp, %r12
movq %r12, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xb0e0
movq (%rbx), %rdi
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x102fc
cmpq $0x1, %rax
cmoveq %rbx, %r15
testq %r15, %r15
jne 0xe839
movq (%rbx), %rdi
callq 0xf7f0
movq $0x0, (%rbx)
cmpq $0x0, (%rbx)
jne 0xe84b
leaq 0x6bdc6(%rip), %rdi     # 0x7a60c
callq 0xcb04
movq %r15, %rax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop