// 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>::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
movq $-0x1, %r12
cmpb $0x1, 0x9(%rdi)
jne 0xe2a9
movq %rdx, %r14
movq %rdi, %rbx
movq 0x10(%rdi), %rdx
cmpb $0x0, 0x18(%rdi)
je 0xe1c3
xorl %r12d, %r12d
cmpq %r14, %r12
jge 0xe1ba
movb $0x1, 0x18(%rbx)
movq %rdx, 0x10(%rbx)
jmp 0xe2a9
movq %rsi, %r13
leaq 0x4eec3(%rip), %rsi     # 0x5d090
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %rdx, 0x10(%rsp)
movq %r14, %rcx
xorl %eax, %eax
callq 0xb0e0
leaq 0x18(%rsp), %rbp
movq %rbp, %rdi
callq 0x20692
movq %r13, 0x10(%rbp)
movq %r14, 0x18(%rbp)
movq (%rbx), %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x103cb
cmpq $0x1, %rax
jne 0xe2a9
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 0xe240
movq %r13, %rdi
movq %r15, %rdx
callq 0xb420
subq %r15, %r14
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0xe26d
testq %r14, %r14
jle 0xe26d
addq %r15, %r13
movq %r13, 0x28(%rsp)
movq %r14, 0x30(%rsp)
movq %rbp, %rdi
xorl %esi, %esi
callq *%rax
testq %rax, %rax
jne 0xe21f
jmp 0xe2a9
movq 0x50(%rsp), %rax
testq %rax, %rax
je 0xe28d
leaq 0x18(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq *%rax
movq 0x50(%rsp), %rax
testq %rax, %rax
jne 0xe27c
movq 0x8(%rsp), %r12
subq %r14, %r12
js 0xe2a9
movq 0x10(%rsp), %rdx
addq %r12, %rdx
movq 0x8(%rsp), %r14
jmp 0xe1b1
movq %r12, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq