// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x690, %rsp            # imm = 0x690
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x1, -0x40(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq -0x18(%rbp), %rdx
leaq -0x20(%rbp), %rcx
leaq -0x28(%rbp), %r8
leaq -0x30(%rbp), %r9
leaq -0x38(%rbp), %r10
leaq -0x3c(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x23a0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x3300
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3653
cmpl $0x0, -0x3c(%rbp)
je 0x331e
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2310
movl $0x0, -0x4(%rbp)
jmp 0x3653
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
xorl %eax, %eax
movl %eax, %esi
movq %rsi, %rdi
callq 0x2120
callq 0x20b0
movq %rax, %rdi
callq 0x21c0
movq %rax, -0x50(%rbp)
leaq 0x280dc(%rip), %rdi     # 0x2b42e
movb $0x0, %al
callq 0x2040
movq -0x28(%rbp), %rsi
leaq 0x2812b(%rip), %rdi     # 0x2b48f
movb $0x0, %al
callq 0x2040
movq -0x50(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x21b0
cmpl $0x1, %eax
je 0x33be
movq 0x32c57(%rip), %rax     # 0x35fe0
movq (%rax), %rdi
leaq 0x28120(%rip), %rsi     # 0x2b4b3
movb $0x0, %al
callq 0x21d0
movq 0x32c3f(%rip), %rax     # 0x35fe0
movq (%rax), %rdi
callq 0x20d0
movq -0x50(%rbp), %rdi
callq 0x2050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3653
movq -0x30(%rbp), %rsi
leaq 0x28111(%rip), %rdi     # 0x2b4da
movb $0x0, %al
callq 0x2040
movq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl $0x1, %edx
callq 0x2030
cmpl $0x1, %eax
je 0x3423
movq 0x32bf2(%rip), %rax     # 0x35fe0
movq (%rax), %rdi
leaq 0x280fe(%rip), %rsi     # 0x2b4f6
movb $0x0, %al
callq 0x21d0
movq 0x32bda(%rip), %rax     # 0x35fe0
movq (%rax), %rdi
callq 0x20d0
movq -0x50(%rbp), %rdi
callq 0x2050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3653
movq -0x38(%rbp), %rsi
leaq 0x280e7(%rip), %rdi     # 0x2b515
movb $0x0, %al
callq 0x2040
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x21a0
cmpl $0x1, %eax
je 0x3487
movq 0x32b8e(%rip), %rax     # 0x35fe0
movq (%rax), %rdi
leaq 0x280d9(%rip), %rsi     # 0x2b535
movb $0x0, %al
callq 0x21d0
movq 0x32b76(%rip), %rax     # 0x35fe0
movq (%rax), %rdi
callq 0x20d0
movq -0x50(%rbp), %rdi
callq 0x2050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3653
movq $0x0, -0x60(%rbp)
movq -0x50(%rbp), %rdi
callq 0x2160
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x34df
movq 0x32b36(%rip), %rax     # 0x35fe0
movq (%rax), %rdi
leaq 0x2809d(%rip), %rsi     # 0x2b551
movb $0x0, %al
callq 0x21d0
movq 0x32b1e(%rip), %rax     # 0x35fe0
movq (%rax), %rdi
callq 0x20d0
movq -0x50(%rbp), %rdi
callq 0x2050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3653
movq -0x60(%rbp), %rdi
movl $0x6e, %esi
xorl %eax, %eax
movl %eax, %edx
leaq -0x58(%rbp), %rcx
callq 0x2060
movq -0x58(%rbp), %rdi
movl $0x21, %esi
movl $0x4, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x2070
movq -0x60(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x64, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x2060
movq -0x60(%rbp), %rdi
movq -0x20(%rbp), %rcx
movl $0x64, %esi
movl $0x1, %edx
callq 0x2060
movq -0x60(%rbp), %rdi
movl $0x65, %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x2060
cmpq $0x1, %rax
je 0x3599
movq 0x32a85(%rip), %rax     # 0x35fe0
movq (%rax), %rdi
leaq 0x28008(%rip), %rsi     # 0x2b56d
movb $0x0, %al
callq 0x21d0
movq 0x32a6d(%rip), %rax     # 0x35fe0
movq (%rax), %rdi
callq 0x20d0
movq -0x60(%rbp), %rdi
callq 0x2080
movq -0x50(%rbp), %rdi
callq 0x2050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3653
leaq -0x678(%rbp), %rdi
xorl %esi, %esi
movl $0x618, %edx            # imm = 0x618
callq 0x20e0
movq -0x60(%rbp), %rdi
leaq -0x678(%rbp), %rsi
callq 0x3070
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x363b
leaq 0x27ea7(%rip), %rdi     # 0x2b473
movb $0x0, %al
callq 0x2040
leaq -0x678(%rbp), %rsi
addq $0x190, %rsi            # imm = 0x190
leaq 0x27e9b(%rip), %rdi     # 0x2b483
movb $0x0, %al
callq 0x2040
movq -0x678(%rbp), %rsi
leaq 0x27f87(%rip), %rdi     # 0x2b584
movb $0x0, %al
callq 0x2040
movq -0x570(%rbp), %rsi
leaq 0x27f80(%rip), %rdi     # 0x2b592
movb $0x0, %al
callq 0x2040
movl -0x468(%rbp), %esi
leaq 0x27f7b(%rip), %rdi     # 0x2b5a1
movb $0x0, %al
callq 0x2040
leaq 0x27dfa(%rip), %rdi     # 0x2b42e
movb $0x0, %al
callq 0x2040
movq -0x60(%rbp), %rdi
callq 0x2080
movq -0x50(%rbp), %rdi
callq 0x2050
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x690, %rsp            # imm = 0x690
popq %rbp
retq
nop