// File: mh0fm4[P]SCDC/src/components/compcoup/compcoup_transport.cc
// Function: scdc_compcoup_transport::dataset_output_incoming_recv(scdc_transport_connection_t*, _scdc_dataset_inout_t*, bool*)
bool scdc_compcoup_transport::dataset_output_incoming_recv(scdc_transport_connection_t *conn, scdc_dataset_output_t *output, bool *next)
{
  SCDC_TRACE("dataset_output_incoming_recv:");

  SCDC_ASSERT(conn->current_incoming_output_size >= 0);

  /* empty output */
  SCDC_DATASET_INOUT_BUF_CURRENT(output) = 0;

  bool cont_recv = true;

  do
  {
    if (conn->current_incoming_output_size <= 0)
    {
      if (!scdc_dataset_transport::read_output_info(conn, &conn->current_incoming_output, conn->current_incoming_output_next))
      {
        SCDC_FAIL("dataset_output_incoming_recv: read output info failed");
        return false;
      }

      conn->current_incoming_output_size = SCDC_DATASET_INOUT_BUF_CURRENT(&conn->current_incoming_output);

      SCDC_TRACE("dataset_output_incoming_recv: current_incoming_output_next/size: " << conn->current_incoming_output_next << " / " << conn->current_incoming_output_size);
    }

    strncpy(output->format, conn->current_incoming_output.format, SCDC_FORMAT_MAX_SIZE);
    output->total_size = conn->current_incoming_output.total_size;
    output->total_size_given = conn->current_incoming_output.total_size_given;

    scdcint_t prev_current = SCDC_DATASET_INOUT_BUF_CURRENT(output);

    if (!conn->transport->recv_incoming_dataset_output(conn, output, conn->current_incoming_output_size, cont_recv))
    {
      SCDC_FAIL("dataset_output_incoming_recv: receive dataset output failed");
      return false;
    }

    conn->current_incoming_output_size -= SCDC_DATASET_INOUT_BUF_CURRENT(output) - prev_current;

    *next = (conn->current_incoming_output_next || conn->current_incoming_output_size > 0);

    SCDC_TRACE("dataset_output_incoming_recv: cont: '" << cont_recv << "', next: '" << *next << "', buf: " << SCDC_DATASET_INOUT_BUF_CURRENT(output) << " of " << SCDC_DATASET_INOUT_BUF_SIZE(output));
 
  } while (cont_recv && *next && SCDC_DATASET_INOUT_BUF_CURRENT(output) < SCDC_DATASET_INOUT_BUF_SIZE(output));

  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
jmp 0xa2346
jmp 0xa2348
movq -0x10(%rbp), %rax
cmpq $0x0, 0x2c8(%rax)
jge 0xa240d
jmp 0xa235c
leaq 0x32345(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
cmpq $0x0, %rax
je 0xa2409
leaq 0x3232c(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e900
leaq 0x3231d(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
movq %rax, %rdi
leaq 0x41cc(%rip), %rsi      # 0xa6569
callq 0xc670
movq %rax, %rdi
leaq 0x7ad9(%rip), %rsi      # 0xa9e85
callq 0xc670
movq %rax, %rdi
leaq 0x3fa9(%rip), %rsi      # 0xa6364
callq 0xc670
movq %rax, %rdi
movl $0x3f0, %esi            # imm = 0x3F0
callq 0xcb80
movq %rax, %rdi
leaq 0x7dd8(%rip), %rsi      # 0xaa1af
callq 0xc670
movq %rax, %rdi
leaq 0x5b26(%rip), %rsi      # 0xa7f0c
callq 0xc670
movq %rax, %rdi
movq 0x31bcb(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
leaq 0x322a7(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e920
jmp 0xa240b
jmp 0xa240d
jmp 0xa240f
movq -0x18(%rbp), %rax
movq $0x0, 0x20(%rax)
movb $0x1, -0x21(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x2c8(%rax)
jg 0xa24fd
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x268, %rsi            # imm = 0x268
movq -0x10(%rbp), %rdx
addq $0x2d1, %rdx            # imm = 0x2D1
callq 0xa36d0
testb $0x1, %al
jne 0xa24e3
jmp 0xa245a
leaq 0x32247(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x257e0
cmpq $0x0, %rax
je 0xa24d8
leaq 0x32232(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x25800
leaq 0x32223(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x257e0
movq %rax, %rdi
leaq 0x3d19(%rip), %rsi      # 0xa61b0
callq 0xc670
movq %rax, %rdi
leaq 0x79a1(%rip), %rsi      # 0xa9e47
callq 0xc670
movq %rax, %rdi
leaq 0x7d25(%rip), %rsi      # 0xaa1da
callq 0xc670
movq %rax, %rdi
movq 0x31afc(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
leaq 0x321d8(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x25820
jmp 0xa24da
movb $0x0, -0x1(%rbp)
jmp 0xa2693
movq -0x10(%rbp), %rax
movq 0x288(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x2c8(%rax)
jmp 0xa24fb
jmp 0xa24fd
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x268, %rsi            # imm = 0x268
movl $0x10, %edx
callq 0xc320
movq -0x10(%rbp), %rax
movq 0x290(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movb 0x298(%rax), %cl
movq -0x18(%rbp), %rax
movb %cl, 0x30(%rax)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x2c8(%rax), %rcx
movq (%rdi), %rax
leaq -0x21(%rbp), %r8
callq *0xb0(%rax)
testb $0x1, %al
jne 0xa2600
jmp 0xa2577
leaq 0x3212a(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x257e0
cmpq $0x0, %rax
je 0xa25f5
leaq 0x32115(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x25800
leaq 0x32106(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x257e0
movq %rax, %rdi
leaq 0x3bfc(%rip), %rsi      # 0xa61b0
callq 0xc670
movq %rax, %rdi
leaq 0x7884(%rip), %rsi      # 0xa9e47
callq 0xc670
movq %rax, %rdi
leaq 0x7c3e(%rip), %rsi      # 0xaa210
callq 0xc670
movq %rax, %rdi
movq 0x319df(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
leaq 0x320bb(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x25820
jmp 0xa25f7
movb $0x0, -0x1(%rbp)
jmp 0xa2693
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdx
subq -0x30(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x2c8(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x2c8(%rax)
movq -0x10(%rbp), %rcx
movb $0x1, %al
testb $0x1, 0x2d1(%rcx)
movb %al, -0x31(%rbp)
jne 0xa2645
movq -0x10(%rbp), %rax
cmpq $0x0, 0x2c8(%rax)
setg %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %cl
movq -0x20(%rbp), %rax
andb $0x1, %cl
movb %cl, (%rax)
jmp 0xa2653
jmp 0xa2655
xorl %eax, %eax
testb $0x1, -0x21(%rbp)
movb %al, -0x32(%rbp)
je 0xa2684
movq -0x20(%rbp), %rcx
xorl %eax, %eax
testb $0x1, (%rcx)
movb %al, -0x32(%rbp)
je 0xa2684
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x18(%rcx), %rax
setl %al
movb %al, -0x32(%rbp)
movb -0x32(%rbp), %al
testb $0x1, %al
jne 0xa241f
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq
nop