// File: mh0fm4[P]SCDC/src/components/transport/transport.cc
// Function: recv_incoming_dataset_inout_extern(scdc_transport_connection_t*, _scdc_dataset_inout_t*, long long, bool&)
static bool recv_incoming_dataset_inout_extern(scdc_transport_connection_t *conn, scdc_dataset_inout_t *inout, scdcint_t max_recv, bool &cont_recv)
{
  bool ret = true;

  char *dst = static_cast<char *>(SCDC_DATASET_INOUT_BUF_PTR(inout));
  scdcint_t dst_size = SCDC_DATASET_INOUT_BUF_SIZE(inout);

  dst += SCDC_DATASET_INOUT_BUF_CURRENT(inout);
  dst_size -= SCDC_DATASET_INOUT_BUF_CURRENT(inout);

  if (max_recv > 0)
  {
    /* 1st: copy from incoming to inout */
    const char *src = conn->incoming.get_read_pos_buf();
    scdcint_t src_size = conn->incoming.get_read_pos_buf_size();

    scdcint_t n = min(src_size, min(dst_size, max_recv));

    memcpy(dst, src, n);

    conn->incoming.inc_read_pos(n);

    dst += n;
    dst_size -= n;

    max_recv -= n;
    SCDC_DATASET_INOUT_BUF_CURRENT(inout) += n;
  }

  if (max_recv > 0)
  {
    /* 2nd: receive in inout */

    scdcint_t n;

    while (1)
    {
      n = min(dst_size, max_recv);

      if (n <= 0) break;

      n = conn->transport->receive(conn, dst, n);

/*      SCDC_INFO("conn->transport->receive: " << n);*/

      if (n < 0) break;

      conn->total_receive += n;

      dst += n;
      dst_size -= n;

      max_recv -= n;
      SCDC_DATASET_INOUT_BUF_CURRENT(inout) += n;
    }

    ret = ret && (n >= 0);
  }

  cont_recv = true;

  return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movb $0x1, -0x21(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x18(%rbp)
jle 0x99820
movq -0x8(%rbp), %rdi
addq $0x30, %rdi
callq 0x2ebe0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
addq $0x30, %rdi
callq 0x2ec00
movq %rax, -0x48(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x2b080
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x2b080
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0xc530
movq -0x8(%rbp), %rdi
addq $0x30, %rdi
movq -0x50(%rbp), %rsi
callq 0x2ec60
movq -0x50(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rcx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x50(%rbp), %rcx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
cmpq $0x0, -0x18(%rbp)
jle 0x998e0
jmp 0x9982d
leaq -0x38(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x2b080
movq (%rax), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jg 0x9984a
jmp 0x998c2
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq (%rdi), %rax
callq *0x80(%rax)
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jge 0x99873
jmp 0x998c2
movq -0x58(%rbp), %rcx
movq -0x8(%rbp), %rax
addq 0x28(%rax), %rcx
movq %rcx, 0x28(%rax)
movq -0x58(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %rcx
movq -0x38(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x58(%rbp), %rcx
movq -0x18(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x58(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
jmp 0x9982d
xorl %eax, %eax
testb $0x1, -0x21(%rbp)
movb %al, -0x59(%rbp)
je 0x998d8
cmpq $0x0, -0x58(%rbp)
setge %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x20(%rbp), %rax
movb $0x1, (%rax)
movb -0x21(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)