// File: /workspace/github_c_makefile_star2_O2/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 0x37e9
movaps 0x16923(%rip), %xmm0    # 0x19590
movq %rsp, %rdx
movaps %xmm0, (%rdx)
pushq $0x4
popq %rcx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %r8
callq 0x184d9
movl %eax, %ebx
pushq $0xa
popq %rdi
callq 0x21e0
testl %ebx, %ebx
js 0x2d05
leaq 0x168b9(%rip), %rdi     # 0x19552
callq 0x2210
leaq 0x16520(%rip), %rdi     # 0x191c5
xorl %eax, %eax
callq 0x2040
movq 0x2430d(%rip), %rax     # 0x26fc0
movq (%rax), %rdi
movl %ebx, %esi
callq 0x12d6c
leaq 0x1653d(%rip), %rdi     # 0x19201
movl %ebx, %esi
xorl %eax, %eax
callq 0x2040
testl %ebx, %ebx
jne 0x2d78
leaq 0x1652c(%rip), %rdi     # 0x19208
xorl %eax, %eax
callq 0x2040
addq $0x190, %r14            # imm = 0x190
leaq 0x16527(%rip), %rdi     # 0x19218
movq %r14, %rsi
xorl %eax, %eax
callq 0x2040
pushq $0xa
popq %rdi
callq 0x21e0
jmp 0x2d78
leaq 0x164ca(%rip), %rdi     # 0x191d6
xorl %eax, %eax
callq 0x2040
leaq 0x16416(%rip), %rdi     # 0x19130
movl %ebx, %esi
xorl %eax, %eax
callq 0x2040
leaq 0x16416(%rip), %rdi     # 0x19140
xorl %eax, %eax
callq 0x2040
movq 0x242a0(%rip), %r15     # 0x26fd8
movq (%r15), %rdi
movl %ebx, %esi
callq 0x12920
pushq $0xa
popq %rdi
callq 0x21e0
leaq 0x18(%rsp), %r14
movq 0x28(%r14), %rsi
leaq 0x163f3(%rip), %rdi     # 0x1914d
xorl %eax, %eax
callq 0x2040
leaq 0x1681a(%rip), %rdi     # 0x19582
callq 0x2210
movq (%r15), %rdi
movq %r14, %rsi
callq 0x128ce
pushq $0xa
popq %rdi
callq 0x21e0
leaq 0x18(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x39c9
movq %r14, %rdi
callq 0x39da
movl %ebx, %eax
addq $0x8b0, %rsp            # imm = 0x8B0
popq %rbx
popq %r14
popq %r15
retq