// 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>::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 $0x168, %rsp            # imm = 0x168
movq %rdx, %r14
movq %rdi, %rbx
movq 0x10(%rdi), %r15
movq $-0x1, %r12
cmpb $0x1, 0x9(%rdi)
jne 0xe1a5
cmpb $0x0, 0x18(%rbx)
je 0xe0b4
xorl %r12d, %r12d
jmp 0xe1a5
movq %rsi, %r13
leaq 0x4efd2(%rip), %rsi     # 0x5d090
leaq 0x60(%rsp), %rdi
movq %r15, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0xb0e0
leaq 0x8(%rsp), %rbp
movq %rbp, %rdi
callq 0x20754
movq %r13, 0x10(%rbp)
movq %r14, 0x18(%rbp)
movq (%rbx), %rdi
leaq 0x60(%rsp), %rsi
xorl %edx, %edx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x102fc
cmpq $0x1, %rax
jne 0xe1a5
movq %r15, (%rsp)
movq %r14, %r15
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rbp
cmpq %rbp, %r15
cmovlq %r15, %rbp
cmpq %r13, %rsi
je 0xe12b
movq %r13, %rdi
movq %rbp, %rdx
callq 0xb420
addq %rbp, %r13
subq %rbp, %r15
movq 0x40(%rsp), %rax
testq %rax, %rax
sete %cl
testq %r15, %r15
setle %dl
orb %cl, %dl
movl $0x5, %ecx
jne 0xe169
movq %r13, 0x18(%rsp)
movq %r15, 0x20(%rsp)
leaq 0x8(%rsp), %rdi
xorl %esi, %esi
callq *%rax
xorl %ecx, %ecx
testq %rax, %rax
sete %cl
shll $0x2, %ecx
testl %ecx, %ecx
je 0xe10a
cmpl $0x5, %ecx
jne 0xe1a1
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0xe192
leaq 0x8(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
callq *%rax
movq 0x40(%rsp), %rax
testq %rax, %rax
jne 0xe181
movq %r14, %r12
subq %r15, %r12
movq (%rsp), %r15
addq %r12, %r15
jmp 0xe1a5
movq (%rsp), %r15
testq %r12, %r12
js 0xe1b7
cmpq %r14, %r12
jge 0xe1b3
movb $0x1, 0x18(%rbx)
movq %r15, 0x10(%rbx)
movq %r12, %rax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq