// File: 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 %rbp
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x238(%rbp)
jmp 0x124d6
movq $0x0, -0x20(%rbp)
movl -0x14(%rbp), %edi
movl $0x8, %esi
callq 0x11060
movl %eax, %ecx
movq -0x238(%rbp), %rax
cmpl $0x0, %ecx
setne %cl
andb $0x1, %cl
movb %cl, 0x9(%rax)
movl -0x14(%rbp), %edi
movl $0x10, %esi
callq 0x11060
movl %eax, %ecx
movq -0x238(%rbp), %rax
cmpl $0x0, %ecx
setne %cl
andb $0x1, %cl
movb %cl, 0xa(%rax)
movl -0x14(%rbp), %edi
movl $0x20, %esi
callq 0x11060
movl %eax, %ecx
movq -0x238(%rbp), %rax
cmpl $0x0, %ecx
setne %cl
andb $0x1, %cl
movb %cl, 0xb(%rax)
movq $0x0, 0x10(%rax)
movb $0x0, 0x18(%rax)
movq -0x10(%rbp), %rdi
movl $0x2f, %esi
callq 0xd820
movq %rax, -0x128(%rbp)
cmpq $0x0, -0x128(%rbp)
je 0x125bf
movq -0x128(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
addq $0x1, %rax
movl %eax, -0x12c(%rbp)
leaq -0x120(%rbp), %rdi
movq -0x10(%rbp), %rsi
movslq -0x12c(%rbp), %rdx
callq 0xd360
movslq -0x12c(%rbp), %rax
movb $0x0, -0x120(%rbp,%rax)
movq -0x128(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x128(%rbp)
leaq 0xa71e6(%rip), %rdi     # 0xb97ac
callq 0x12790
leaq -0x120(%rbp), %rdi
movb $0x0, %al
callq 0x13ae0
movq %rax, %rcx
movq -0x238(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, (%rax)
jne 0x125f1
jmp 0x126dc
movq -0x238(%rbp), %rax
testb $0x1, 0xb(%rax)
je 0x12646
movq -0x238(%rbp), %rax
testb $0x1, 0xa(%rax)
je 0x12646
leaq -0x230(%rbp), %rdi
movq -0x128(%rbp), %rdx
leaq 0x7bb65(%rip), %rsi     # 0x8e185
movb $0x0, %al
callq 0xd100
movq -0x238(%rbp), %rax
movq (%rax), %rdi
leaq -0x230(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
movb $0x0, %al
callq 0x14970
movq -0x238(%rbp), %rax
testb $0x1, 0xa(%rax)
je 0x1268e
leaq -0x230(%rbp), %rdi
movq -0x128(%rbp), %rdx
leaq 0x7bb23(%rip), %rsi     # 0x8e18b
movb $0x0, %al
callq 0xd100
movq -0x238(%rbp), %rax
movq (%rax), %rdi
leaq -0x230(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
movb $0x0, %al
callq 0x14970
leaq -0x230(%rbp), %rdi
movq -0x128(%rbp), %rdx
leaq 0x7baef(%rip), %rsi     # 0x8e192
movb $0x0, %al
callq 0xd100
movq -0x238(%rbp), %rax
movq (%rax), %rdi
leaq -0x230(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
movb $0x0, %al
callq 0x14970
cmpq $0x1, %rax
je 0x126d1
jmp 0x126dc
movq -0x238(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x12700
movq -0x238(%rbp), %rax
movq (%rax), %rdi
callq 0x13bb0
movq -0x238(%rbp), %rax
movq $0x0, (%rax)
movq -0x238(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x12719
leaq 0xa7098(%rip), %rdi     # 0xb97ac
callq 0xee60
movq -0x20(%rbp), %rax
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
nopw %cs:(%rax,%rax)