// File: /workspace/github_cpp_makefile_star2_O2/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)
andq $0x0, 0x10(%rdi)
movb $0x0, 0x18(%rdi)
pushq $0x2f
popq %rsi
movq %r15, %rdi
callq 0xb660
testq %rax, %rax
je 0xdfb2
movq %rax, %r14
subl %r15d, %eax
incl %eax
movslq %eax, %r12
leaq 0x100(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xb2e0
movb $0x0, 0x100(%rsp,%r12)
incq %r14
jmp 0xdfb5
xorl %r14d, %r14d
leaq 0x58680(%rip), %rdi     # 0x6663c
callq 0xe0dc
xorl %r15d, %r15d
leaq 0x100(%rsp), %rdi
xorl %eax, %eax
callq 0xecb3
movq %rax, (%rbx)
testq %rax, %rax
je 0xe07b
movb 0xa(%rbx), %al
cmpb $0x1, 0xb(%rbx)
jne 0xe017
testb $0x1, %al
je 0xe017
leaq 0x381bc(%rip), %rsi     # 0x461af
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xb0d0
movq (%rbx), %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xf574
movb 0xa(%rbx), %al
testb $0x1, %al
je 0xe043
leaq 0x38193(%rip), %rsi     # 0x461b5
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xb0d0
movq (%rbx), %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xf574
leaq 0x38172(%rip), %rsi     # 0x461bc
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xb0d0
movq (%rbx), %rdi
movq %r15, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xf574
movq (%rbx), %r15
cmpq $0x1, %rax
jne 0xe07b
testq %r15, %r15
jne 0xe095
jmp 0xe089
movq %r15, %rdi
callq 0xed6b
andq $0x0, (%rbx)
xorl %ebx, %ebx
leaq 0x585ac(%rip), %rdi     # 0x6663c
callq 0xc5ee
movq %rbx, %rax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop