// File: /workspace/github_c_makefile_star2_O2/OpenKMIP[P]libkmip/src/kmip_bio.c
// Function: kmip_bio_send_request_encoding
int kmip_bio_send_request_encoding(KMIP *ctx, BIO *bio,
                                   char *request, int request_size,
                                   char **response, int *response_size)
{
    if(ctx == NULL || bio == NULL || request == NULL || request_size <= 0 || response == NULL || response_size == NULL)
    {
        return(KMIP_ARG_INVALID);
    }
    
    /* Send the request message. */
    int sent = BIO_write(bio, request, request_size);
    if(sent != request_size)
    {
        return(KMIP_IO_FAILURE);
    }
    
    /* Read the response message. Dynamically resize the receiving buffer */
    /* to align with the message size advertised by the message encoding. */
    /* Reject the message if the message size is too large.               */
    size_t buffer_blocks = 1;
    size_t buffer_block_size = 8;
    size_t buffer_total_size = buffer_blocks * buffer_block_size;
    
    uint8 *encoding = ctx->calloc_func(ctx->state, buffer_blocks,
                                       buffer_block_size);
    if(encoding == NULL)
    {
        return(KMIP_MEMORY_ALLOC_FAILED);
    }
    
    int recv = BIO_read(bio, encoding, buffer_total_size);
    if((size_t)recv != buffer_total_size)
    {
        kmip_free_buffer(ctx, encoding, buffer_total_size);
        encoding = NULL;
        return(KMIP_IO_FAILURE);
    }
    
    kmip_set_buffer(ctx, encoding, buffer_total_size);
    ctx->index += 4;
    int length = 0;
    
    kmip_decode_int32_be(ctx, &length);
    kmip_rewind(ctx);
    if(length > ctx->max_message_size)
    {
        kmip_free_buffer(ctx, encoding, buffer_total_size);
        encoding = NULL;
        kmip_set_buffer(ctx, NULL, 0);
        return(KMIP_EXCEED_MAX_MESSAGE_SIZE);
    }
    
    kmip_set_buffer(ctx, NULL, 0);
    uint8 *extended = ctx->realloc_func(ctx->state, encoding,
                                        buffer_total_size + length);
    if(encoding != extended)
    {
        encoding = extended;
    }
    ctx->memset_func(encoding + buffer_total_size, 0, length);
    
    buffer_block_size += length;
    buffer_total_size = buffer_blocks * buffer_block_size;
    
    recv = BIO_read(bio, encoding + 8, length);
    if(recv != length)
    {
        kmip_free_buffer(ctx, encoding, buffer_total_size);
        encoding = NULL;
        kmip_set_buffer(ctx, NULL, 0);
        return(KMIP_IO_FAILURE);
    }
    
    *response_size = buffer_total_size;
    *response = (char *)encoding;
    
    kmip_set_buffer(ctx, NULL, 0);
    
    return(KMIP_OK);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebp
movq %rsi, %r12
movq %rsi, %xmm0
movq %rdi, %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movq %r8, %xmm0
movq %rdx, %xmm2
punpcklqdq %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0]
pxor %xmm0, %xmm0
testl %ecx, %ecx
setle %al
testq %r9, %r9
sete %cl
pcmpeqd %xmm0, %xmm2
pcmpeqd %xmm0, %xmm1
movdqa %xmm1, %xmm0
shufps $0xdd, %xmm2, %xmm0     # xmm0 = xmm0[1,3],xmm2[1,3]
shufps $0x88, %xmm2, %xmm1     # xmm1 = xmm1[0,2],xmm2[0,2]
andps %xmm0, %xmm1
movmskps %xmm1, %esi
testl %esi, %esi
setne %sil
orb %al, %cl
orb %sil, %cl
je 0x1803b
pushq $-0x11
popq %r13
jmp 0x1817f
movq %r9, %r15
movq %r8, %r14
movq %rdi, %rbx
movq %r12, %rdi
movq %rdx, %rsi
movl %ebp, %edx
callq 0x2150
pushq $-0xd
popq %r13
cmpl %ebp, %eax
jne 0x1817f
movq 0x890(%rbx), %rdi
pushq $0x1
popq %rsi
pushq $0x8
popq %rdx
callq *0x868(%rbx)
testq %rax, %rax
je 0x180d9
movq %rax, %rbp
pushq $0x8
popq %rdx
movq %r12, %rdi
movq %rax, %rsi
callq 0x2180
pushq $0x8
popq %rdx
cmpl $0x8, %eax
jne 0x180e0
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3681
addq $0x4, 0x8(%rbx)
leaq 0x4(%rsp), %r13
andl $0x0, (%r13)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xaaec
movq %rbx, %rdi
callq 0x366f
movl (%r13), %eax
cmpl 0x1c(%rbx), %eax
jle 0x180f0
pushq $0x8
popq %rdx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3ae1
pushq $-0xe
jmp 0x18171
pushq $-0xc
jmp 0x18034
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3ae1
jmp 0x1817f
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3681
movq 0x890(%rbx), %rdi
movslq 0x4(%rsp), %rdx
addq $0x8, %rdx
movq %rbp, %rsi
callq *0x870(%rbx)
movq %rax, 0x8(%rsp)
leaq 0x8(%rax), %rdi
movq %rdi, 0x10(%rsp)
movslq 0x4(%rsp), %rdx
xorl %esi, %esi
callq *0x888(%rbx)
movslq 0x4(%rsp), %rdx
movq %rdx, %rbp
addq $0x8, %rbp
movq %r12, %rdi
movq 0x10(%rsp), %rsi
callq 0x2180
cmpl 0x4(%rsp), %eax
jne 0x1815f
movl %ebp, (%r15)
movq 0x8(%rsp), %rax
movq %rax, (%r14)
jmp 0x18173
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0x3ae1
pushq $-0xd
popq %r13
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3681
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq