// File: /workspace/github_c_makefile_star2_O0/OpenKMIP[P]libkmip/src/kmip_bio.c
// Function: kmip_bio_create_symmetric_key
int kmip_bio_create_symmetric_key(BIO *bio,
                                  TemplateAttribute *template_attribute,
                                  char **id, int *id_size)
{
    if(bio == NULL || template_attribute == NULL || id == NULL || id_size == NULL)
        return(KMIP_ARG_INVALID);
    
    /* Set up the KMIP context and the initial encoding buffer. */
    KMIP ctx = {0};
    kmip_init(&ctx, NULL, 0, KMIP_1_0);
    
    size_t buffer_blocks = 1;
    size_t buffer_block_size = 1024;
    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)
    {
        kmip_destroy(&ctx);
        return(KMIP_MEMORY_ALLOC_FAILED);
    }
    kmip_set_buffer(&ctx, encoding, buffer_total_size);
    
    /* Build the request message. */
    ProtocolVersion pv = {0};
    kmip_init_protocol_version(&pv, ctx.version);
    
    RequestHeader rh = {0};
    kmip_init_request_header(&rh);
    
    rh.protocol_version = &pv;
    rh.maximum_response_size = ctx.max_message_size;
    rh.time_stamp = time(NULL);
    rh.batch_count = 1;
    
    CreateRequestPayload crp = {0};
    crp.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
    crp.template_attribute = template_attribute;
    
    RequestBatchItem rbi = {0};
    kmip_init_request_batch_item(&rbi);
    rbi.operation = KMIP_OP_CREATE;
    rbi.request_payload = &crp;
    
    RequestMessage rm = {0};
    rm.request_header = &rh;
    rm.batch_items = &rbi;
    rm.batch_count = 1;
    
    /* Encode the request message. Dynamically resize the encoding buffer */
    /* if it's not big enough. Once encoding succeeds, send the request   */
    /* message.                                                           */
    int encode_result = kmip_encode_request_message(&ctx, &rm);
    while(encode_result == KMIP_ERROR_BUFFER_FULL)
    {
        kmip_reset(&ctx);
        ctx.free_func(ctx.state, encoding);
        
        buffer_blocks += 1;
        buffer_total_size = buffer_blocks * buffer_block_size;
        
        encoding = ctx.calloc_func(ctx.state, buffer_blocks,
                                   buffer_block_size);
        if(encoding == NULL)
        {
            kmip_destroy(&ctx);
            return(KMIP_MEMORY_ALLOC_FAILED);
        }
        
        kmip_set_buffer(
            &ctx,
            encoding,
            buffer_total_size);
        encode_result = kmip_encode_request_message(&ctx, &rm);
    }
    
    if(encode_result != KMIP_OK)
    {
        kmip_free_buffer(&ctx, encoding, buffer_total_size);
        encoding = NULL;
        kmip_destroy(&ctx);
        return(encode_result);
    }
    
    int sent = BIO_write(bio, ctx.buffer, ctx.index - ctx.buffer);
    if(sent != ctx.index - ctx.buffer)
    {
        kmip_free_buffer(&ctx, encoding, buffer_total_size);
        encoding = NULL;
        kmip_destroy(&ctx);
        return(KMIP_IO_FAILURE);
    }
    
    kmip_free_buffer(&ctx, encoding, buffer_total_size);
    encoding = NULL;
    
    /* Read the response message. Dynamically resize the encoding buffer  */
    /* to align with the message size advertised by the message encoding. */
    /* Reject the message if the message size is too large.               */
    buffer_blocks = 1;
    buffer_block_size = 8;
    buffer_total_size = buffer_blocks * buffer_block_size;
    
    encoding = ctx.calloc_func(ctx.state, buffer_blocks, buffer_block_size);
    if(encoding == NULL)
    {
        kmip_destroy(&ctx);
        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;
        kmip_destroy(&ctx);
        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_destroy(&ctx);
        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_destroy(&ctx);
        return(KMIP_IO_FAILURE);
    }
    
    kmip_set_buffer(&ctx, encoding, buffer_block_size);
    
    /* Decode the response message and retrieve the operation results. */
    ResponseMessage resp_m = {0};
    int decode_result = kmip_decode_response_message(&ctx, &resp_m);
    if(decode_result != KMIP_OK)
    {
        kmip_free_response_message(&ctx, &resp_m);
        kmip_free_buffer(&ctx, encoding, buffer_total_size);
        encoding = NULL;
        kmip_destroy(&ctx);
        return(decode_result);
    }

    if(resp_m.batch_count != 1 || resp_m.batch_items == NULL)
    {
        kmip_free_response_message(&ctx, &resp_m);
        kmip_free_buffer(&ctx, encoding, buffer_total_size);
        encoding = NULL;
        kmip_destroy(&ctx);
        return(KMIP_MALFORMED_RESPONSE);
    }
    
    ResponseBatchItem resp_item = resp_m.batch_items[0];
    enum result_status result = resp_item.result_status;

    if(result != KMIP_STATUS_SUCCESS)
    {
        kmip_free_response_message(&ctx, &resp_m);
        kmip_free_buffer(&ctx, encoding, buffer_total_size);
        encoding = NULL;
        kmip_set_buffer(&ctx, NULL, 0);
        kmip_destroy(&ctx);
        return(result);
    }
    
    CreateResponsePayload *pld = (CreateResponsePayload *)resp_item.response_payload;
    TextString *unique_identifier = pld->unique_identifier;
    
    /* KMIP text strings are not null-terminated by default. Add an extra */
    /* character to the end of the UUID copy to make space for the null   */
    /* terminator.                                                        */
    char *result_id = ctx.calloc_func(
        ctx.state,
        1,
        unique_identifier->size + 1);
    *id_size = unique_identifier->size;
    for(int i = 0; i < *id_size; i++)
        result_id[i] = unique_identifier->value[i];
    *id = result_id;
    
    /* Clean up the response message, the encoding buffer, and the KMIP */
    /* context. */
    kmip_free_response_message(&ctx, &resp_m);
    kmip_free_buffer(&ctx, encoding, buffer_total_size);
    encoding = NULL;
    kmip_set_buffer(&ctx, NULL, 0);
    kmip_destroy(&ctx);
    
    return(result);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa20, %rsp            # imm = 0xA20
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x26397
cmpq $0x0, -0x18(%rbp)
je 0x26397
cmpq $0x0, -0x20(%rbp)
je 0x26397
cmpq $0x0, -0x28(%rbp)
jne 0x263a3
movl $0xffffffef, -0x4(%rbp) # imm = 0xFFFFFFEF
jmp 0x26c68
leaq -0x8c0(%rbp), %rdi
xorl %esi, %esi
movl $0x898, %edx            # imm = 0x898
callq 0x20e0
leaq -0x8c0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
movq %rdx, %rsi
callq 0x4570
movq $0x1, -0x8c8(%rbp)
movq $0x400, -0x8d0(%rbp) # imm = 0x400
movq -0x8c8(%rbp), %rax
imulq -0x8d0(%rbp), %rax
movq %rax, -0x8d8(%rbp)
movq -0x58(%rbp), %rax
movq -0x30(%rbp), %rdi
movq -0x8c8(%rbp), %rsi
movq -0x8d0(%rbp), %rdx
callq *%rax
movq %rax, -0x8e0(%rbp)
cmpq $0x0, -0x8e0(%rbp)
jne 0x26438
leaq -0x8c0(%rbp), %rdi
callq 0x4940
movl $0xfffffff4, -0x4(%rbp) # imm = 0xFFFFFFF4
jmp 0x26c68
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rdx
leaq -0x8c0(%rbp), %rdi
callq 0x48f0
leaq -0x8e8(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x20e0
movl -0x8a8(%rbp), %esi
leaq -0x8e8(%rbp), %rdi
callq 0x50f0
leaq -0x938(%rbp), %rdi
xorl %esi, %esi
movl $0x50, %edx
callq 0x20e0
leaq -0x938(%rbp), %rdi
callq 0x5350
leaq -0x8e8(%rbp), %rax
movq %rax, -0x938(%rbp)
movl -0x8a4(%rbp), %eax
movl %eax, -0x930(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x2130
movq %rax, -0x918(%rbp)
movl $0x1, -0x910(%rbp)
leaq -0x958(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x20e0
movl $0x2, -0x958(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x950(%rbp)
leaq -0x978(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x20e0
leaq -0x978(%rbp), %rdi
callq 0x5480
movl $0x1, -0x978(%rbp)
leaq -0x958(%rbp), %rax
movq %rax, -0x968(%rbp)
leaq -0x990(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x20e0
leaq -0x938(%rbp), %rax
movq %rax, -0x990(%rbp)
leaq -0x978(%rbp), %rax
movq %rax, -0x988(%rbp)
movq $0x1, -0x980(%rbp)
leaq -0x8c0(%rbp), %rdi
leaq -0x990(%rbp), %rsi
callq 0x12680
movl %eax, -0x994(%rbp)
cmpl $-0x2, -0x994(%rbp)
jne 0x26647
leaq -0x8c0(%rbp), %rdi
callq 0x4850
movq -0x48(%rbp), %rax
movq -0x30(%rbp), %rdi
movq -0x8e0(%rbp), %rsi
callq *%rax
movq -0x8c8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8c8(%rbp)
movq -0x8c8(%rbp), %rax
imulq -0x8d0(%rbp), %rax
movq %rax, -0x8d8(%rbp)
movq -0x58(%rbp), %rax
movq -0x30(%rbp), %rdi
movq -0x8c8(%rbp), %rsi
movq -0x8d0(%rbp), %rdx
callq *%rax
movq %rax, -0x8e0(%rbp)
cmpq $0x0, -0x8e0(%rbp)
jne 0x2660f
leaq -0x8c0(%rbp), %rdi
callq 0x4940
movl $0xfffffff4, -0x4(%rbp) # imm = 0xFFFFFFF4
jmp 0x26c68
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rdx
leaq -0x8c0(%rbp), %rdi
callq 0x48f0
leaq -0x8c0(%rbp), %rdi
leaq -0x990(%rbp), %rsi
callq 0x12680
movl %eax, -0x994(%rbp)
jmp 0x2657c
cmpl $0x0, -0x994(%rbp)
je 0x2668f
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rdx
leaq -0x8c0(%rbp), %rdi
callq 0x54c0
movq $0x0, -0x8e0(%rbp)
leaq -0x8c0(%rbp), %rdi
callq 0x4940
movl -0x994(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x26c68
movq -0x10(%rbp), %rdi
movq -0x8c0(%rbp), %rsi
movq -0x8b8(%rbp), %rax
movq -0x8c0(%rbp), %rcx
subq %rcx, %rax
movl %eax, %edx
callq 0x2150
movl %eax, -0x998(%rbp)
movslq -0x998(%rbp), %rax
movq -0x8b8(%rbp), %rcx
movq -0x8c0(%rbp), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
je 0x26712
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rdx
leaq -0x8c0(%rbp), %rdi
callq 0x54c0
movq $0x0, -0x8e0(%rbp)
leaq -0x8c0(%rbp), %rdi
callq 0x4940
movl $0xfffffff3, -0x4(%rbp) # imm = 0xFFFFFFF3
jmp 0x26c68
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rdx
leaq -0x8c0(%rbp), %rdi
callq 0x54c0
movq $0x0, -0x8e0(%rbp)
movq $0x1, -0x8c8(%rbp)
movq $0x8, -0x8d0(%rbp)
movq -0x8c8(%rbp), %rax
imulq -0x8d0(%rbp), %rax
movq %rax, -0x8d8(%rbp)
movq -0x58(%rbp), %rax
movq -0x30(%rbp), %rdi
movq -0x8c8(%rbp), %rsi
movq -0x8d0(%rbp), %rdx
callq *%rax
movq %rax, -0x8e0(%rbp)
cmpq $0x0, -0x8e0(%rbp)
jne 0x267a4
leaq -0x8c0(%rbp), %rdi
callq 0x4940
movl $0xfffffff4, -0x4(%rbp) # imm = 0xFFFFFFF4
jmp 0x26c68
movq -0x10(%rbp), %rdi
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rax
movl %eax, %edx
callq 0x2170
movl %eax, -0x99c(%rbp)
movslq -0x99c(%rbp), %rax
cmpq -0x8d8(%rbp), %rax
je 0x26810
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rdx
leaq -0x8c0(%rbp), %rdi
callq 0x54c0
movq $0x0, -0x8e0(%rbp)
leaq -0x8c0(%rbp), %rdi
callq 0x4940
movl $0xfffffff3, -0x4(%rbp) # imm = 0xFFFFFFF3
jmp 0x26c68
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rdx
leaq -0x8c0(%rbp), %rdi
callq 0x48f0
movq -0x8b8(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x8b8(%rbp)
movl $0x0, -0x9a0(%rbp)
leaq -0x8c0(%rbp), %rdi
leaq -0x9a0(%rbp), %rsi
callq 0x12af0
leaq -0x8c0(%rbp), %rdi
callq 0x48b0
movl -0x9a0(%rbp), %eax
cmpl -0x8a4(%rbp), %eax
jle 0x268b0
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rdx
leaq -0x8c0(%rbp), %rdi
callq 0x54c0
movq $0x0, -0x8e0(%rbp)
leaq -0x8c0(%rbp), %rdi
callq 0x4940
movl $0xfffffff2, -0x4(%rbp) # imm = 0xFFFFFFF2
jmp 0x26c68
leaq -0x8c0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x48f0
movq -0x50(%rbp), %rax
movq -0x30(%rbp), %rdi
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rdx
movslq -0x9a0(%rbp), %rcx
addq %rcx, %rdx
callq *%rax
movq %rax, -0x9a8(%rbp)
movq -0x8e0(%rbp), %rax
cmpq -0x9a8(%rbp), %rax
je 0x2690a
movq -0x9a8(%rbp), %rax
movq %rax, -0x8e0(%rbp)
movq -0x38(%rbp), %rax
movq -0x8e0(%rbp), %rdi
addq -0x8d8(%rbp), %rdi
movslq -0x9a0(%rbp), %rdx
xorl %esi, %esi
callq *%rax
movslq -0x9a0(%rbp), %rax
addq -0x8d0(%rbp), %rax
movq %rax, -0x8d0(%rbp)
movq -0x8c8(%rbp), %rax
imulq -0x8d0(%rbp), %rax
movq %rax, -0x8d8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8e0(%rbp), %rsi
addq $0x8, %rsi
movl -0x9a0(%rbp), %edx
callq 0x2170
movl %eax, -0x99c(%rbp)
movl -0x99c(%rbp), %eax
cmpl -0x9a0(%rbp), %eax
je 0x269bd
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rdx
leaq -0x8c0(%rbp), %rdi
callq 0x54c0
movq $0x0, -0x8e0(%rbp)
leaq -0x8c0(%rbp), %rdi
callq 0x4940
movl $0xfffffff3, -0x4(%rbp) # imm = 0xFFFFFFF3
jmp 0x26c68
movq -0x8e0(%rbp), %rsi
movq -0x8d0(%rbp), %rdx
leaq -0x8c0(%rbp), %rdi
callq 0x48f0
leaq -0x9c0(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x20e0
leaq -0x8c0(%rbp), %rdi
leaq -0x9c0(%rbp), %rsi
callq 0x1ed90
movl %eax, -0x9c4(%rbp)
cmpl $0x0, -0x9c4(%rbp)
je 0x26a5e
leaq -0x8c0(%rbp), %rdi
leaq -0x9c0(%rbp), %rsi
callq 0x7820
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rdx
leaq -0x8c0(%rbp), %rdi
callq 0x54c0
movq $0x0, -0x8e0(%rbp)
leaq -0x8c0(%rbp), %rdi
callq 0x4940
movl -0x9c4(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x26c68
cmpq $0x1, -0x9b0(%rbp)
jne 0x26a72
cmpq $0x0, -0x9b8(%rbp)
jne 0x26ac2
leaq -0x8c0(%rbp), %rdi
leaq -0x9c0(%rbp), %rsi
callq 0x7820
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rdx
leaq -0x8c0(%rbp), %rdi
callq 0x54c0
movq $0x0, -0x8e0(%rbp)
leaq -0x8c0(%rbp), %rdi
callq 0x4940
movl $0xfffffff1, -0x4(%rbp) # imm = 0xFFFFFFF1
jmp 0x26c68
movq -0x9b8(%rbp), %rsi
leaq -0x9f8(%rbp), %rdi
movl $0x30, %edx
callq 0x2100
movl -0x9e8(%rbp), %eax
movl %eax, -0x9fc(%rbp)
cmpl $0x0, -0x9fc(%rbp)
je 0x26b54
leaq -0x8c0(%rbp), %rdi
leaq -0x9c0(%rbp), %rsi
callq 0x7820
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rdx
leaq -0x8c0(%rbp), %rdi
callq 0x54c0
movq $0x0, -0x8e0(%rbp)
leaq -0x8c0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x48f0
leaq -0x8c0(%rbp), %rdi
callq 0x4940
movl -0x9fc(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x26c68
movq -0x9d0(%rbp), %rax
movq %rax, -0xa08(%rbp)
movq -0xa08(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xa10(%rbp)
movq -0x58(%rbp), %rax
movq -0x30(%rbp), %rdi
movq -0xa10(%rbp), %rcx
movq 0x8(%rcx), %rdx
addq $0x1, %rdx
movl $0x1, %esi
callq *%rax
movq %rax, -0xa18(%rbp)
movq -0xa10(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0xa1c(%rbp)
movl -0xa1c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x26bfa
movq -0xa10(%rbp), %rax
movq (%rax), %rax
movslq -0xa1c(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0xa18(%rbp), %rax
movslq -0xa1c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0xa1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa1c(%rbp)
jmp 0x26bb6
movq -0xa18(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
leaq -0x8c0(%rbp), %rdi
leaq -0x9c0(%rbp), %rsi
callq 0x7820
movq -0x8e0(%rbp), %rsi
movq -0x8d8(%rbp), %rdx
leaq -0x8c0(%rbp), %rdi
callq 0x54c0
movq $0x0, -0x8e0(%rbp)
leaq -0x8c0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x48f0
leaq -0x8c0(%rbp), %rdi
callq 0x4940
movl -0x9fc(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa20, %rsp            # imm = 0xA20
popq %rbp
retq
nopw %cs:(%rax,%rax)