// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x29888
cmpq $0x0, -0x18(%rbp)
je 0x29888
cmpq $0x0, -0x20(%rbp)
je 0x29888
cmpl $0x0, -0x24(%rbp)
jle 0x29888
cmpq $0x0, -0x30(%rbp)
je 0x29888
cmpq $0x0, -0x38(%rbp)
jne 0x29894
movl $0xffffffef, -0x4(%rbp) # imm = 0xFFFFFFEF
jmp 0x29ad3
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x2150
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x24(%rbp), %eax
je 0x298bb
movl $0xfffffff3, -0x4(%rbp) # imm = 0xFFFFFFF3
jmp 0x29ad3
movq $0x1, -0x48(%rbp)
movq $0x8, -0x50(%rbp)
movq -0x48(%rbp), %rax
imulq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x868(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x890(%rcx), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq *%rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x2990f
movl $0xfffffff4, -0x4(%rbp) # imm = 0xFFFFFFF4
jmp 0x29ad3
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rax
movl %eax, %edx
callq 0x2170
movl %eax, -0x64(%rbp)
movslq -0x64(%rbp), %rax
cmpq -0x58(%rbp), %rax
je 0x29954
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0x54c0
movq $0x0, -0x60(%rbp)
movl $0xfffffff3, -0x4(%rbp) # imm = 0xFFFFFFF3
jmp 0x29ad3
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0x48f0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x4, %rcx
movq %rcx, 0x8(%rax)
movl $0x0, -0x68(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x12af0
movq -0x10(%rbp), %rdi
callq 0x48b0
movl -0x68(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jle 0x299d3
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0x54c0
movq $0x0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x48f0
movl $0xfffffff2, -0x4(%rbp) # imm = 0xFFFFFFF2
jmp 0x29ad3
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x48f0
movq -0x10(%rbp), %rax
movq 0x870(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x890(%rcx), %rdi
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movslq -0x68(%rbp), %rcx
addq %rcx, %rdx
callq *%rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x70(%rbp), %rax
je 0x29a20
movq -0x70(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x888(%rax), %rax
movq -0x60(%rbp), %rdi
addq -0x58(%rbp), %rdi
movslq -0x68(%rbp), %rdx
xorl %esi, %esi
callq *%rax
movslq -0x68(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
imulq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
addq $0x8, %rsi
movl -0x68(%rbp), %edx
callq 0x2170
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x68(%rbp), %eax
je 0x29aa5
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0x54c0
movq $0x0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x48f0
movl $0xfffffff3, -0x4(%rbp) # imm = 0xFFFFFFF3
jmp 0x29ad3
movq -0x58(%rbp), %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x60(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x48f0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)