// File: /workspace/github_c_makefile_star2_O3/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
movl $0xffffffef, %r13d      # imm = 0xFFFFFFEF
jne 0x1f490
movq %r9, %r15
movq %r8, %r14
movq %rdi, %rbx
movq %r12, %rdi
movq %rdx, %rsi
movl %ebp, %edx
callq 0x2150
movl $0xfffffff3, %r13d      # imm = 0xFFFFFFF3
cmpl %ebp, %eax
jne 0x1f490
movq 0x890(%rbx), %rdi
movl $0x1, %esi
movl $0x8, %edx
callq *0x868(%rbx)
testq %rax, %rax
je 0x1f3e4
movq %rax, %rbp
movq %r12, %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0x2180
movl $0x8, %edx
cmpl $0x8, %eax
jne 0x1f3ef
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3a80
addq $0x4, 0x8(%rbx)
leaq 0x4(%rsp), %r13
movl $0x0, (%r13)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xbd58
movq %rbx, %rdi
callq 0x3a2d
movl (%r13), %eax
cmpl 0x1c(%rbx), %eax
jle 0x1f3ff
movl $0x8, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3fa0
movl $0xfffffff2, %r13d      # imm = 0xFFFFFFF2
jmp 0x1f484
movl $0xfffffff4, %r13d      # imm = 0xFFFFFFF4
jmp 0x1f490
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3fa0
jmp 0x1f490
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3a80
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 0x1f46e
movl %ebp, (%r15)
movq 0x8(%rsp), %rax
movq %rax, (%r14)
jmp 0x1f484
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0x3fa0
movl $0xfffffff3, %r13d      # imm = 0xFFFFFFF3
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3a80
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq