// File: 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
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1a8(%rbp)
jmp 0x117c4
movq -0x1a8(%rbp), %rax
movq $-0x1, -0x20(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x28(%rbp)
testb $0x1, 0x9(%rax)
jne 0x117e6
jmp 0x11995
movq -0x1a8(%rbp), %rax
testb $0x1, 0x18(%rax)
je 0x11800
movq $0x0, -0x20(%rbp)
jmp 0x11995
leaq -0x130(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq 0x7c850(%rip), %rsi     # 0x8e066
movb $0x0, %al
callq 0xd100
leaq -0x188(%rbp), %rdi
callq 0x33f30
movq -0x1a8(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, -0x178(%rbp)
movq -0x18(%rbp), %rcx
movq %rcx, -0x170(%rbp)
movq (%rax), %rdi
leaq -0x130(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq -0x188(%rbp), %rcx
movb $0x0, %al
callq 0x14970
cmpq $0x1, %rax
je 0x1186d
jmp 0x11995
movq -0x18(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x198(%rbp)
leaq -0x188(%rbp), %rdi
addq $0x20, %rdi
leaq -0x190(%rbp), %rsi
callq 0x119e0
movq (%rax), %rax
movq %rax, -0x1a0(%rbp)
movq -0x178(%rbp), %rax
cmpq -0x198(%rbp), %rax
je 0x118ce
movq -0x198(%rbp), %rdi
movq -0x178(%rbp), %rsi
movq -0x1a0(%rbp), %rdx
callq 0xd580
movq -0x1a0(%rbp), %rax
addq -0x198(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x1a0(%rbp), %rcx
movq -0x190(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x190(%rbp)
cmpq $0x0, -0x150(%rbp)
je 0x1190f
cmpq $0x0, -0x190(%rbp)
jg 0x11911
jmp 0x11954
movq -0x198(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x190(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0x188(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq *-0x150(%rbp)
cmpq $0x0, %rax
jne 0x11946
jmp 0x11995
jmp 0x11948
movb $0x1, %al
testb $0x1, %al
jne 0x11883
jmp 0x11954
jmp 0x11956
cmpq $0x0, -0x150(%rbp)
je 0x11973
leaq -0x188(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq *-0x150(%rbp)
jmp 0x11956
movq -0x18(%rbp), %rax
subq -0x190(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
subq -0x190(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
jl 0x119c0
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x119b1
movq -0x1a8(%rbp), %rax
movb $0x1, 0x18(%rax)
movq -0x1a8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x119c2
jmp 0x119c4
movq -0x20(%rbp), %rax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)