// File: /workspace/github_c_makefile_star2_O3/OpenKMIP[P]libkmip/demos/demo_query.c
// Function: main
int
main(int argc, char **argv)
{
    char *server_address = NULL;
    char *server_port = NULL;
    char *client_certificate = NULL;
    char *client_key = NULL;
    char *ca_certificate = NULL;
    int help = 0;
    int result = 1;
    
    int error = parse_arguments(argc, argv, &server_address, &server_port,
                                &client_certificate, &client_key,
                                &ca_certificate, &help);
    if(error)
    {
        return(error);
    }
    if(help)
    {
        print_help(argv[0]);
        return(0);
    }

    /* Set up the TLS connection to the KMIP server. */
    SSL_CTX *ctx = NULL;
    SSL *ssl = NULL;
    OPENSSL_init_ssl(0, NULL);
    ctx = SSL_CTX_new(TLS_client_method());

    printf("\n");
    printf("Loading the client certificate: %s\n", client_certificate);
    if(SSL_CTX_use_certificate_file(ctx, client_certificate, SSL_FILETYPE_PEM) != 1)
    {
        fprintf(stderr, "Loading the client certificate failed\n");
        ERR_print_errors_fp(stderr);
        SSL_CTX_free(ctx);
        return(-1);
    }

    printf("Loading the client key: %s\n", client_key);
    if(SSL_CTX_use_PrivateKey_file(ctx, client_key, SSL_FILETYPE_PEM) != 1)
    {
        fprintf(stderr, "Loading the client key failed\n");
        ERR_print_errors_fp(stderr);
        SSL_CTX_free(ctx);
        return(-1);
    }

    printf("Loading the CA certificate: %s\n", ca_certificate);
    if(SSL_CTX_load_verify_locations(ctx, ca_certificate, NULL) != 1)
    {
        fprintf(stderr, "Loading the CA file failed\n");
        ERR_print_errors_fp(stderr);
        SSL_CTX_free(ctx);
        return(-1);
    }

    BIO *bio = NULL;
    bio = BIO_new_ssl_connect(ctx);
    if(bio == NULL)
    {
        fprintf(stderr, "BIO_new_ssl_connect failed\n");
        ERR_print_errors_fp(stderr);
        SSL_CTX_free(ctx);
        return(-1);
    }

    BIO_get_ssl(bio, &ssl);
    SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
    BIO_set_conn_hostname(bio, server_address);
    BIO_set_conn_port(bio, server_port);
    if(BIO_do_connect(bio) != 1)
    {
        fprintf(stderr, "BIO_do_connect failed\n");
        ERR_print_errors_fp(stderr);
        BIO_free_all(bio);
        SSL_CTX_free(ctx);
        return(-1);
    }

    QueryResponse query_result = {0};
    result = use_mid_level_api(bio, &query_result);
    if(result == KMIP_STATUS_SUCCESS)
    {
        printf("Query results: ");
        printf("vendor: %s\n", query_result.vendor_identification);
        printf("num ops: %zu\n", query_result.operations_size);
        printf("num objs: %zu\n", query_result.objects_size);
        printf("server info: %d\n", query_result.server_information_valid );
        printf("\n");
    }

    BIO_free_all(bio);
    SSL_CTX_free(ctx);

    return(result);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x658, %rsp            # imm = 0x658
movq %rsi, %rbx
xorl %eax, %eax
leaq 0x38(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x30(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x28(%rsp), %r8
movq %rax, (%r8)
leaq 0x20(%rsp), %r9
movq %rax, (%r9)
leaq 0x18(%rsp), %r10
movq %rax, (%r10)
leaq 0xc(%rsp), %rax
movl $0x0, (%rax)
pushq %rax
pushq %r10
callq 0x2503
addq $0x10, %rsp
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x318d
cmpl $0x0, 0xc(%rsp)
je 0x2f73
movq (%rbx), %rdi
callq 0x249c
xorl %ebp, %ebp
jmp 0x318d
movq $0x0, 0x10(%rsp)
xorl %edi, %edi
xorl %esi, %esi
callq 0x2120
callq 0x20b0
movq %rax, %rdi
callq 0x21f0
movq %rax, %rbx
movl $0xa, %edi
callq 0x21e0
movq 0x28(%rsp), %r14
leaq 0x1d279(%rip), %rdi     # 0x20224
movq %r14, %rsi
xorl %eax, %eax
callq 0x2040
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x21d0
cmpl $0x1, %eax
jne 0x3155
movq 0x20(%rsp), %r14
leaq 0x1d295(%rip), %rdi     # 0x2026f
movq %r14, %rsi
xorl %eax, %eax
callq 0x2040
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x2030
cmpl $0x1, %eax
jne 0x315f
movq 0x18(%rsp), %r14
leaq 0x1d2a1(%rip), %rdi     # 0x202aa
movq %r14, %rsi
xorl %eax, %eax
callq 0x2040
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x21c0
cmpl $0x1, %eax
jne 0x3169
movq %rbx, %rdi
callq 0x2160
testq %rax, %rax
je 0x3173
movq %rax, %r14
leaq 0x10(%rsp), %r15
movq %rax, %rdi
movl $0x6e, %esi
xorl %edx, %edx
movq %r15, %rcx
callq 0x2060
movq (%r15), %rdi
movl $0x4, %edx
movl $0x21, %esi
xorl %ecx, %ecx
callq 0x2070
movq 0x38(%rsp), %rcx
movq %r14, %rdi
movl $0x64, %esi
xorl %edx, %edx
callq 0x2060
movq 0x30(%rsp), %rcx
movl $0x1, %edx
movq %r14, %rdi
movl $0x64, %esi
callq 0x2060
movq %r14, %rdi
movl $0x65, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2060
cmpq $0x1, %rax
jne 0x317d
leaq 0x40(%rsp), %r15
movl $0x618, %edx            # imm = 0x618
movq %r15, %rdi
xorl %esi, %esi
callq 0x20e0
movq %r14, %rdi
movq %r15, %rsi
callq 0x2d7f
movl %eax, %ebp
testl %eax, %eax
jne 0x3143
leaq 0x1d12e(%rip), %rdi     # 0x20208
xorl %eax, %eax
callq 0x2040
leaq 0x1d0(%rsp), %r15
leaq 0x1d128(%rip), %rdi     # 0x20218
movq %r15, %rsi
xorl %eax, %eax
callq 0x2040
movq -0x190(%r15), %rsi
leaq 0x1d211(%rip), %rdi     # 0x20319
xorl %eax, %eax
callq 0x2040
movq -0x88(%r15), %rsi
leaq 0x1d20a(%rip), %rdi     # 0x20327
xorl %eax, %eax
callq 0x2040
movl 0x80(%r15), %esi
leaq 0x1d204(%rip), %rdi     # 0x20336
xorl %eax, %eax
callq 0x2040
movl $0xa, %edi
callq 0x21e0
movq %r14, %rdi
callq 0x2080
movq %rbx, %rdi
callq 0x2050
jmp 0x318d
movq %rbx, %rdi
callq 0x2282
jmp 0x3188
movq %rbx, %rdi
callq 0x22bc
jmp 0x3188
movq %rbx, %rdi
callq 0x22f6
jmp 0x3188
movq %rbx, %rdi
callq 0x2375
jmp 0x3188
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2330
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x658, %rsp            # imm = 0x658
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)