// File: /workspace/github_c_makefile_star2_O3/OpenKMIP[P]libkmip/demos/demo_query.c
// Function: use_mid_level_api
int
use_mid_level_api(BIO* bio,
                  QueryResponse* query_result)
{
    /* Set up the KMIP context and send the request message. */
    KMIP kmip_context = {0};

    kmip_init(&kmip_context, NULL, 0, KMIP_1_0);
    
    enum query_function queries[] =
    {
        KMIP_QUERY_OPERATIONS,
        KMIP_QUERY_OBJECTS,
        KMIP_QUERY_SERVER_INFORMATION,
        KMIP_QUERY_APPLICATION_NAMESPACES,
    };

    int result = kmip_bio_query_with_context(&kmip_context, bio, queries, ARRAY_LENGTH(queries), query_result);
    
    /* Handle the response results. */
    printf("\n");
    if(result < 0)
    {
        printf("An error occurred while running the query.");
        printf("Error Code: %d\n", result);
        printf("Error Name: ");
        kmip_print_error_string(stderr, result);
        printf("\n");
        printf("Context Error: %s\n", kmip_context.error_message);
        printf("Stack trace:\n");
        kmip_print_stack_trace(stderr, &kmip_context);
    }
    else if(result >= 0)
    {
        printf("The KMIP operation was executed with no errors.\n");
        printf("Result: ");
        kmip_print_result_status_enum(stdout, result);
        printf(" (%d)\n", result);
        
        if(result == KMIP_STATUS_SUCCESS)
        {
            printf("Query results: ");
            printf("vendor: %s\n", query_result->vendor_identification);
            printf("\n");
        }
    }
    
    printf("\n");
    
    /* Clean up the KMIP context and return the results. */
    kmip_set_buffer(&kmip_context, NULL, 0);
    kmip_destroy(&kmip_context);
    return(result);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x8b0, %rsp            # imm = 0x8B0
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x18(%rsp), %r15
movl $0x898, %edx            # imm = 0x898
movq %r15, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3aef
movaps 0x1d7d6(%rip), %xmm0    # 0x20590
movq %rsp, %rdx
movaps %xmm0, (%rdx)
movl $0x4, %ecx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %r8
callq 0x1f7de
movl %eax, %ebx
movl $0xa, %edi
callq 0x21e0
testl %ebx, %ebx
js 0x2e58
leaq 0x1d768(%rip), %rdi     # 0x20552
callq 0x2210
leaq 0x1d3cf(%rip), %rdi     # 0x201c5
xorl %eax, %eax
callq 0x2040
movq 0x2a1bc(%rip), %rax     # 0x2cfc0
movq (%rax), %rdi
movl %ebx, %esi
callq 0x19bd3
leaq 0x1d3ec(%rip), %rdi     # 0x20201
movl %ebx, %esi
xorl %eax, %eax
callq 0x2040
testl %ebx, %ebx
jne 0x2ecd
leaq 0x1d3db(%rip), %rdi     # 0x20208
xorl %eax, %eax
callq 0x2040
addq $0x190, %r14            # imm = 0x190
leaq 0x1d3d6(%rip), %rdi     # 0x20218
movq %r14, %rsi
xorl %eax, %eax
callq 0x2040
movl $0xa, %edi
callq 0x21e0
jmp 0x2ecd
leaq 0x1d377(%rip), %rdi     # 0x201d6
xorl %eax, %eax
callq 0x2040
leaq 0x1d2c3(%rip), %rdi     # 0x20130
movl %ebx, %esi
xorl %eax, %eax
callq 0x2040
leaq 0x1d2c3(%rip), %rdi     # 0x20140
xorl %eax, %eax
callq 0x2040
movq 0x2a14d(%rip), %r15     # 0x2cfd8
movq (%r15), %rdi
movl %ebx, %esi
callq 0x19708
movl $0xa, %edi
callq 0x21e0
leaq 0x18(%rsp), %r14
movq 0x28(%r14), %rsi
leaq 0x1d29e(%rip), %rdi     # 0x2014d
xorl %eax, %eax
callq 0x2040
leaq 0x1d6c5(%rip), %rdi     # 0x20582
callq 0x2210
movq (%r15), %rdi
movq %r14, %rsi
callq 0x196b6
movl $0xa, %edi
callq 0x21e0
leaq 0x18(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3dbc
movq %r14, %rdi
callq 0x3dcd
movl %ebx, %eax
addq $0x8b0, %rsp            # imm = 0x8B0
popq %rbx
popq %r14
popq %r15
retq