// File: /workspace/github_cpp_makefile_star2_O2/mh0fm4[P]SCDC/src/lib/redirect/redirect/redirect_call.cc
// Function: void redirect_call_get_output_param_blocks_val<float>(_redirect_call_t*, char const*, float**, long, long, long*)
void redirect_call_get_output_param_blocks_val(redirect_call_t *rc, const char *id, T **b, rdint_t count, rdint_t size, rdint_t *stride)
{
  TRACE_F("rc: %p, id: '%s', b: %p, count: %" rdint_fmt ", size: %" rdint_fmt ", stride: %" rdint_fmt, rc, id, *b, count, size, *stride);

  if (rc->client) /* client */
  {
    bool transfer_dense = false;
    rdint_t transfer_stride;

    redirect_call_get_output_conf_rdint(rc, "stride", &transfer_stride);
    TRACE_F("transfer stride: %" rdint_fmt, transfer_stride);

    if (*stride == 0) *stride = transfer_stride;

    rdint_t alloc_stride, recv_stride;

#if REDIRECT_CALL_OUTPUT_PARAM_BLOCKS == REDIRECT_CALL_BLOCKS_PLAIN
    transfer_dense = true;
    alloc_stride = transfer_stride;
    recv_stride = transfer_stride;
#elif REDIRECT_CALL_OUTPUT_PARAM_BLOCKS == REDIRECT_CALL_BLOCKS_PACK_IP
    transfer_dense = true;
    alloc_stride = z_max(*stride, transfer_stride);
    recv_stride = transfer_stride;
#elif REDIRECT_CALL_OUTPUT_PARAM_BLOCKS == REDIRECT_CALL_BLOCKS_PACK_OP
    transfer_dense = true;
    alloc_stride = *stride;
    recv_stride = transfer_stride;
#elif REDIRECT_CALL_OUTPUT_PARAM_BLOCKS == REDIRECT_CALL_BLOCKS_PIECES
    transfer_dense = false;
    alloc_stride = *stride;
    recv_stride = *stride;
#endif

    TRACE_F("alloc stride: %" rdint_fmt ", recv stride: %" rdint_fmt, alloc_stride, recv_stride);

    if (*b == NULL) *b = static_cast<T *>(redirect_call_alloc_buf(rc, get_blocks_cont_size(count, size, alloc_stride) * sizeof(T)));

    T* b_recv = *b;

#if REDIRECT_CALL_INPUT_PARAM_BLOCKS == REDIRECT_CALL_BLOCKS_PACK_OP
    T *b_tmp = 0;
    if (recv_stride != *stride) b_recv = b_tmp = static_cast<T *>(malloc(get_blocks_cont_size(count, size, transfer_stride) * sizeof(T)));
#endif

    if (recv_stride == transfer_stride || transfer_dense)
    {
      TRACE_F("consume dense: %" rdint_fmt, get_blocks_cont_size(count, size, recv_stride));
      consume_output_dense<T>(rc, b_recv, get_blocks_cont_size(count, size, recv_stride));

    } else
    {
      TRACE_F("consume blocks: %" rdint_fmt " x %" rdint_fmt " / %" rdint_fmt, count, size, recv_stride);
      consume_output_blocks<T>(rc, b_recv, count, size, recv_stride);
    }

    if (recv_stride != *stride)
    {
#if REDIRECT_CALL_INPUT_PARAM_BLOCKS == REDIRECT_CALL_BLOCKS_PLAIN
      TRACE_F("set stride %" rdint_fmt, recv_stride);
      *stride = recv_stride;
#elif REDIRECT_CALL_INPUT_PARAM_BLOCKS == REDIRECT_CALL_BLOCKS_PACK_IP
      TRACE_F("transform in-place to stride %" rdint_fmt, *stride);
      redirect_data_blocks_transform_val<T>(count, size, recv_stride, b_recv, *stride, NULL);
#elif REDIRECT_CALL_INPUT_PARAM_BLOCKS == REDIRECT_CALL_BLOCKS_PACK_OP
      TRACE_F("transform out-of-place to stride: %" rdint_fmt, *stride);
      redirect_data_blocks_transform_val<T>(count, size, recv_stride, b_recv, *stride, *b);
      free(b_tmp);
#elif REDIRECT_CALL_INPUT_PARAM_BLOCKS == REDIRECT_CALL_BLOCKS_PIECES
      /* this should never occur, because pieces are received with the correct stride */
      ASSERT(false);
#endif
    }

  } else /* server */
  {
    if (*b == NULL)
    {
      /* default stride is size */
      if (*stride == 0) *stride = size;

      /* FIXME: use output instead of allocation */

      /* allocate buffer */
      *b = static_cast<T *>(redirect_call_alloc_buf(rc, get_blocks_cont_size(count, size, *stride) * sizeof(T)));
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x8(%rsp)
movq %r8, %rbp
movq %rcx, %r13
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
movq 0x5dba1(%rip), %r12     # 0x74fb8
movq (%r12), %rdi
leaq 0x393e7(%rip), %rsi     # 0x50809
leaq 0x39ac8(%rip), %rdx     # 0x50ef1
xorl %eax, %eax
callq 0xb7c0
movq (%r12), %rdi
movq (%r14), %r8
leaq 0x39921(%rip), %rsi     # 0x50d5f
movq %r15, %rdx
movq %rbx, %rcx
movq %r13, 0x18(%rsp)
movq %r13, %r9
movq %r12, %r13
movq %rbp, %r12
movq 0x8(%rsp), %rbp
xorl %eax, %eax
pushq (%rbp)
pushq %r12
callq 0xb7c0
popq %rcx
popq %rdx
movq (%r13), %rsi
pushq $0xa
popq %rdi
callq 0xb6b0
cmpl $0x0, (%r15)
je 0x1760a
leaq 0x20(%rsp), %rbx
movq %r15, 0x10(%rsp)
movq %r15, %rdi
movq %rbx, %rdx
callq 0xf4b3
movq (%r13), %rdi
leaq 0x3936e(%rip), %rsi     # 0x50809
leaq 0x39a4f(%rip), %rdx     # 0x50ef1
xorl %eax, %eax
callq 0xb7c0
movq (%r13), %rdi
movq (%rbx), %rdx
leaq 0x39905(%rip), %rsi     # 0x50dbc
xorl %eax, %eax
callq 0xb7c0
movq (%r13), %rsi
pushq $0xa
popq %rdi
callq 0xb6b0
cmpq $0x0, (%rbp)
movq (%rbx), %rbp
jne 0x174dc
movq 0x8(%rsp), %rax
movq %rbp, (%rax)
movq (%r13), %rdi
leaq 0x39322(%rip), %rsi     # 0x50809
leaq 0x39a03(%rip), %rdx     # 0x50ef1
xorl %eax, %eax
callq 0xb7c0
movq (%r13), %rdi
leaq 0x3992a(%rip), %rsi     # 0x50e2a
movq %rbp, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xb7c0
movq (%r13), %rsi
pushq $0xa
popq %rdi
callq 0xb6b0
movq (%r14), %rbx
testq %rbx, %rbx
movq 0x18(%rsp), %r15
jne 0x17553
leaq -0x1(%r15), %rsi
imulq %rbp, %rsi
addq %r12, %rsi
shlq $0x2, %rsi
testq %r12, %r12
cmoveq %r12, %rsi
testq %r15, %r15
cmoveq %r15, %rsi
movq 0x10(%rsp), %rdi
callq 0x114ce
movq %rax, %rbx
movq %rax, (%r14)
leaq -0x1(%r15), %rax
imulq %rbp, %rax
addq %r12, %rax
testq %r12, %r12
cmoveq %r12, %rax
cmpq $0x1, %r15
movq (%r13), %rdi
leaq 0x3997d(%rip), %rdx     # 0x50ef1
leaq 0x3928e(%rip), %rsi     # 0x50809
movl $0x0, %r15d
cmovaeq %rax, %r15
xorl %eax, %eax
callq 0xb7c0
movq (%r13), %rdi
leaq 0x398b7(%rip), %rsi     # 0x50e4e
movq %r15, %rdx
xorl %eax, %eax
callq 0xb7c0
movq (%r13), %rsi
pushq $0xa
popq %rdi
callq 0xb6b0
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x11aec
movq 0x8(%rsp), %rbx
cmpq (%rbx), %rbp
je 0x1764d
movq (%r13), %rdi
leaq 0x39233(%rip), %rsi     # 0x50809
leaq 0x39914(%rip), %rdx     # 0x50ef1
xorl %eax, %eax
callq 0xb7c0
movq (%r13), %rdi
leaq 0x3992c(%rip), %rsi     # 0x50f1b
movq %rbp, %rdx
xorl %eax, %eax
callq 0xb7c0
movq (%r13), %rsi
pushq $0xa
popq %rdi
callq 0xb6b0
movq %rbp, (%rbx)
jmp 0x1764d
cmpq $0x0, (%r14)
jne 0x1764d
movq (%rbp), %rax
testq %rax, %rax
jne 0x17620
movq %r12, (%rbp)
movq %r12, %rax
movq 0x18(%rsp), %rcx
leaq -0x1(%rcx), %rsi
imulq %rax, %rsi
addq %r12, %rsi
shlq $0x2, %rsi
testq %r12, %r12
cmoveq %r12, %rsi
testq %rcx, %rcx
cmoveq %rcx, %rsi
movq %r15, %rdi
callq 0x114ce
movq %rax, (%r14)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq