// 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>::xsgetn(char*, long)
streamsize 
      xsgetn(char* __s, streamsize __n)
      {
        TRACE(__class__, __func__, "n: %lld", (long long) __n);

        streamsize ret = -1;
        streamsize noffset = offset;

        if (!do_read) goto do_return;

        if (eof)
        {
          ret = 0;
          goto do_return;
        }

        char cmd[256];
        sprintf(cmd, "get %" scdcint_fmt "F:%" scdcint_fmt, noffset, __n);

        scdc_dataset_output_t output;

        scdc_dataset_output_unset(&output);
        SCDC_DATASET_INOUT_BUF_PTR(&output) = __s;
        SCDC_DATASET_INOUT_BUF_SIZE(&output) = __n;

        if (scdc_dataset_cmd(_M_dataset, cmd, NULL, &output) != SCDC_SUCCESS) goto do_return;

        {
          scdcint_t size_left = __n;
          char *buf = __s;

          do
          {
            scdcint_t n = std::min(SCDC_DATASET_INOUT_BUF_CURRENT(&output), size_left);

            if (SCDC_DATASET_INOUT_BUF_PTR(&output) != buf) memcpy(buf, SCDC_DATASET_INOUT_BUF_PTR(&output), n);

            /* inc. dest. */
            buf += n;
            size_left -= n;

            if (!output.next || size_left <= 0) break;

            SCDC_DATASET_INOUT_BUF_PTR(&output) = buf;
            SCDC_DATASET_INOUT_BUF_SIZE(&output) = size_left;

            if (output.next(&output, 0) == SCDC_FAILURE) goto do_return;

          } while (1);

          while (output.next) output.next(&output, 0);

          ret = __n - size_left;
          noffset += __n - size_left;
        }

do_return:
        if (ret >= 0)
        {
          if (ret < __n) eof = true;

          offset = noffset;
        }

        TRACE(__class__, __func__, "return: %lld, offset: %lld, eof: %d", (long long) ret, (long long) offset, (int) eof);

        return ret;
      }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
pushq $-0x1
popq %r12
cmpb $0x1, 0x9(%rdi)
jne 0xdaa7
movq %rdx, %r14
movq %rdi, %rbx
movq 0x10(%rdi), %rdx
cmpb $0x0, 0x18(%rdi)
je 0xd9cc
xorl %r12d, %r12d
cmpq %r14, %r12
jge 0xd9c3
movb $0x1, 0x18(%rbx)
movq %rdx, 0x10(%rbx)
jmp 0xdaa7
movq %rsi, %r13
leaq 0x386ba(%rip), %rsi     # 0x46090
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %rdx, 0x10(%rsp)
movq %r14, %rcx
xorl %eax, %eax
callq 0xb0d0
leaq 0x18(%rsp), %rbp
movq %rbp, %rdi
callq 0x1b110
movq %r13, 0x10(%rbp)
movq %r14, 0x18(%rbp)
movq (%rbx), %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xf574
cmpq $0x1, %rax
jne 0xdaa7
leaq 0x18(%rsp), %rbp
movq %r14, 0x8(%rsp)
movq 0x28(%rsp), %rsi
movq 0x38(%rsp), %r15
cmpq %r15, %r14
cmovlq %r14, %r15
cmpq %r13, %rsi
je 0xda49
movq %r13, %rdi
movq %r15, %rdx
callq 0xb460
subq %r15, %r14
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0xda86
testq %r14, %r14
jle 0xda86
addq %r15, %r13
movq %r13, 0x28(%rsp)
movq %r14, 0x30(%rsp)
movq %rbp, %rdi
xorl %esi, %esi
callq *%rax
testq %rax, %rax
jne 0xda28
jmp 0xdaa7
leaq 0x18(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq *%rax
movq 0x38(%r15), %rax
testq %rax, %rax
jne 0xda76
movq 0x8(%rsp), %r12
subq %r14, %r12
js 0xdaa7
movq 0x10(%rsp), %rdx
addq %r12, %rdx
movq 0x8(%rsp), %r14
jmp 0xd9ba
movq %r12, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq