// File: /workspace/github_cpp_makefile_star2_O1/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, 0x18(%rsp)
movq %r8, %r15
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %r14
movq 0x73850(%rip), %rbx     # 0x8bfa0
movq (%rbx), %rdi
leaq 0x510af(%rip), %rsi     # 0x69809
leaq 0x51790(%rip), %rdx     # 0x69ef1
xorl %eax, %eax
callq 0xb7a0
movq (%rbx), %rdi
movq (%r12), %r8
leaq 0x515e9(%rip), %rsi     # 0x69d5f
movq %r14, %rdx
movq %rbp, %rcx
movq %r13, 0x10(%rsp)
movq %r13, %r9
movq %r15, %r13
movq 0x18(%rsp), %r15
xorl %eax, %eax
pushq (%r15)
pushq %r13
callq 0xb7a0
addq $0x10, %rsp
movq (%rbx), %rsi
movl $0xa, %edi
callq 0xb690
cmpl $0x0, (%r14)
je 0x1888c
movq %r12, 0x8(%rsp)
movq 0x160(%r14), %rax
leaq (%r14,%rax), %rdi
addq $0x568, %rdi            # imm = 0x568
leaq 0x20(%rsp), %rbp
movq %rbp, %rsi
callq 0x12067
addq %rax, 0x160(%r14)
movq (%rbx), %rdi
leaq 0x51021(%rip), %rsi     # 0x69809
leaq 0x51702(%rip), %rdx     # 0x69ef1
xorl %eax, %eax
callq 0xb7a0
movq (%rbx), %rdi
movq (%rbp), %rdx
leaq 0x515b8(%rip), %rsi     # 0x69dbc
xorl %eax, %eax
callq 0xb7a0
movq (%rbx), %rsi
movl $0xa, %edi
callq 0xb690
cmpq $0x0, (%r15)
jne 0x18826
movq 0x20(%rsp), %rax
movq %rax, (%r15)
movq 0x20(%rsp), %rbp
movq (%rbx), %rdi
leaq 0x50fd4(%rip), %rsi     # 0x69809
leaq 0x516b5(%rip), %rdx     # 0x69ef1
xorl %eax, %eax
callq 0xb7a0
movq (%rbx), %rdi
leaq 0x515dd(%rip), %rsi     # 0x69e2a
movq %rbp, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xb7a0
movq (%rbx), %rsi
movl $0xa, %edi
callq 0xb690
movq 0x8(%rsp), %rdx
cmpq $0x0, (%rdx)
movq 0x10(%rsp), %r15
jne 0x188fe
movslq 0xb20(%r14), %r12
cmpq $0xf, %r12
jle 0x188c0
xorl %eax, %eax
jmp 0x188fb
cmpq $0x0, (%r12)
jne 0x189eb
movq %r15, %rax
cmpq $0x0, (%r15)
jne 0x188a3
movq %r13, (%rax)
movslq 0xb20(%r14), %rbx
cmpq $0xf, %rbx
movq 0x10(%rsp), %rcx
jle 0x189b3
xorl %eax, %eax
jmp 0x189e7
leaq -0x1(%r15), %rdi
imulq %rbp, %rdi
addq %r13, %rdi
shlq $0x2, %rdi
testq %r13, %r13
cmoveq %r13, %rdi
testq %r15, %r15
cmoveq %r15, %rdi
callq 0xb6f0
movq 0x8(%rsp), %rdx
movq %rax, 0xb28(%r14,%r12,8)
leal 0x1(%r12), %ecx
movl %ecx, 0xb20(%r14)
movq %rax, (%rdx)
leaq -0x1(%r15), %rax
imulq %rbp, %rax
addq %r13, %rax
testq %r13, %r13
cmoveq %r13, %rax
cmpq $0x1, %r15
movq (%rdx), %r15
movq (%rbx), %rdi
leaq 0x515d0(%rip), %rdx     # 0x69ef1
leaq 0x50ee1(%rip), %rsi     # 0x69809
movl $0x0, %r12d
cmovaeq %rax, %r12
xorl %eax, %eax
callq 0xb7a0
movq (%rbx), %rdi
leaq 0x5150b(%rip), %rsi     # 0x69e4e
movq %r12, %rdx
xorl %eax, %eax
callq 0xb7a0
movq (%rbx), %rsi
movl $0xa, %edi
callq 0xb690
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x12a5b
movq 0x18(%rsp), %rcx
cmpq (%rcx), %rbp
je 0x189eb
movq (%rbx), %rdi
leaq 0x50e8d(%rip), %rsi     # 0x69809
leaq 0x5156e(%rip), %rdx     # 0x69ef1
xorl %eax, %eax
movq %rcx, %r14
callq 0xb7a0
movq (%rbx), %rdi
leaq 0x51584(%rip), %rsi     # 0x69f1b
movq %rbp, %rdx
xorl %eax, %eax
callq 0xb7a0
movq (%rbx), %rsi
movl $0xa, %edi
callq 0xb690
movq %rbp, (%r14)
jmp 0x189eb
leaq -0x1(%rcx), %rdi
imulq (%rax), %rdi
addq %r13, %rdi
shlq $0x2, %rdi
testq %r13, %r13
cmoveq %r13, %rdi
testq %rcx, %rcx
cmoveq %rcx, %rdi
callq 0xb6f0
movq %rax, 0xb28(%r14,%rbx,8)
leal 0x1(%rbx), %ecx
movl %ecx, 0xb20(%r14)
movq %rax, (%r12)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq