// File: /workspace/github_c_makefile_star2_O0/OpenKMIP[P]libkmip/demos/demo_get.c
// Function: use_mid_level_api
int
use_mid_level_api(char *server_address,
                  char *server_port,
                  char *client_certificate,
                  char *client_key,
                  char *ca_certificate,
                  char *username,
                  char *password,
                  char *id)
{
    /* 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)
    {
        printf("BIO_new_ssl_connect failed\n");
        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);
    }
    
    printf("\n");
    
    char *key = NULL;
    int key_size = 0;
    size_t id_size = kmip_strnlen_s(id, 50);
    
    /* Set up the KMIP context and send the request message. */
    KMIP kmip_context = {0};
    
    kmip_context.calloc_func = &demo_calloc;
    kmip_context.realloc_func = &demo_realloc;
    kmip_context.free_func = &demo_free;
    
    kmip_init(&kmip_context, NULL, 0, KMIP_1_0);
    
    TextString u = {0};
    u.value = username;
    u.size = kmip_strnlen_s(username, 50);
    
    TextString p = {0};
    p.value = password;
    p.size = kmip_strnlen_s(password, 50);
    
    UsernamePasswordCredential upc = {0};
    upc.username = &u;
    upc.password = &p;
    
    Credential credential = {0};
    credential.credential_type = KMIP_CRED_USERNAME_AND_PASSWORD;
    credential.credential_value = &upc;
    
    int result = kmip_add_credential(&kmip_context, &credential);
    
    if(result != KMIP_OK)
    {
        printf("Failed to add credential to the KMIP context.\n");
        BIO_free_all(bio);
        SSL_CTX_free(ctx);
        kmip_destroy(&kmip_context);
        return(result);
    }
    
    result = kmip_bio_get_symmetric_key_with_context(&kmip_context, bio, id, id_size, &key, &key_size);
    
    BIO_free_all(bio);
    SSL_CTX_free(ctx);
    
    /* Handle the response results. */
    printf("\n");
    if(result < 0)
    {
        printf("An error occurred while creating the symmetric key.");
        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("Symmetric Key ID: %s\n", id);
            printf("Symmetric Key Size: %d bits\n", key_size * 8);
            printf("Symmetric Key:");
            kmip_print_buffer(stdout, key, key_size);
            printf("\n");
        }
    }
    
    printf("\n");
    
    if(key != NULL)
    {
        kmip_memset(key, 0, key_size);
        kmip_free(NULL, key);
    }
    
    /* Clean up the KMIP context and return the results. */
    kmip_destroy(&kmip_context);
    return(result);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x950, %rsp            # imm = 0x950
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
xorl %eax, %eax
movl %eax, %esi
movq %rsi, %rdi
callq 0x2120
callq 0x20b0
movq %rax, %rdi
callq 0x21c0
movq %rax, -0x40(%rbp)
leaq 0x27827(%rip), %rdi     # 0x2a026
movb $0x0, %al
callq 0x2040
movq -0x20(%rbp), %rsi
leaq 0x27a77(%rip), %rdi     # 0x2a288
movb $0x0, %al
callq 0x2040
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x1, %edx
callq 0x21b0
cmpl $0x1, %eax
je 0x286b
movq 0x327aa(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
leaq 0x27a6c(%rip), %rsi     # 0x2a2ac
movb $0x0, %al
callq 0x21d0
movq 0x32792(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
callq 0x20d0
movq -0x40(%rbp), %rdi
callq 0x2050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2dad
movq -0x28(%rbp), %rsi
leaq 0x27a5d(%rip), %rdi     # 0x2a2d3
movb $0x0, %al
callq 0x2040
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl $0x1, %edx
callq 0x2030
cmpl $0x1, %eax
je 0x28d0
movq 0x32745(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
leaq 0x27a4a(%rip), %rsi     # 0x2a2ef
movb $0x0, %al
callq 0x21d0
movq 0x3272d(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
callq 0x20d0
movq -0x40(%rbp), %rdi
callq 0x2050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2dad
movq -0x30(%rbp), %rsi
leaq 0x27a33(%rip), %rdi     # 0x2a30e
movb $0x0, %al
callq 0x2040
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x21a0
cmpl $0x1, %eax
je 0x2934
movq 0x326e1(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
leaq 0x27a25(%rip), %rsi     # 0x2a32e
movb $0x0, %al
callq 0x21d0
movq 0x326c9(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
callq 0x20d0
movq -0x40(%rbp), %rdi
callq 0x2050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2dad
movq $0x0, -0x50(%rbp)
movq -0x40(%rbp), %rdi
callq 0x2160
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x2973
leaq 0x279f3(%rip), %rdi     # 0x2a34a
movb $0x0, %al
callq 0x2040
movq -0x40(%rbp), %rdi
callq 0x2050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2dad
movq -0x50(%rbp), %rdi
movl $0x6e, %esi
xorl %eax, %eax
movl %eax, %edx
leaq -0x48(%rbp), %rcx
callq 0x2060
movq -0x48(%rbp), %rdi
movl $0x21, %esi
movl $0x4, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x2070
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x64, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x2060
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x64, %esi
movl $0x1, %edx
callq 0x2060
movq -0x50(%rbp), %rdi
movl $0x65, %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x2060
cmpq $0x1, %rax
je 0x2a2d
movq 0x325f1(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
leaq 0x2796d(%rip), %rsi     # 0x2a366
movb $0x0, %al
callq 0x21d0
movq 0x325d9(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
callq 0x20d0
movq -0x50(%rbp), %rdi
callq 0x2080
movq -0x40(%rbp), %rdi
callq 0x2050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2dad
leaq 0x275f2(%rip), %rdi     # 0x2a026
movb $0x0, %al
callq 0x2040
movq $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movq 0x18(%rbp), %rdi
movl $0x32, %esi
callq 0x2ee0
movq %rax, -0x68(%rbp)
leaq -0x900(%rbp), %rdi
xorl %esi, %esi
movl $0x898, %edx            # imm = 0x898
callq 0x20e0
leaq -0x3b6(%rip), %rax      # 0x26c0
movq %rax, -0x98(%rbp)
leaq -0x374(%rip), %rax      # 0x2710
movq %rax, -0x90(%rbp)
leaq -0x332(%rip), %rax      # 0x2760
movq %rax, -0x88(%rbp)
leaq -0x900(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
movq %rdx, %rsi
callq 0x4140
leaq -0x910(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x20e0
movq -0x38(%rbp), %rax
movq %rax, -0x910(%rbp)
movq -0x38(%rbp), %rdi
movl $0x32, %esi
callq 0x2ee0
movq %rax, -0x908(%rbp)
leaq -0x920(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x20e0
movq 0x10(%rbp), %rax
movq %rax, -0x920(%rbp)
movq 0x10(%rbp), %rdi
movl $0x32, %esi
callq 0x2ee0
movq %rax, -0x918(%rbp)
leaq -0x930(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x20e0
leaq -0x910(%rbp), %rax
movq %rax, -0x930(%rbp)
leaq -0x920(%rbp), %rax
movq %rax, -0x928(%rbp)
leaq -0x940(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x20e0
movl $0x1, -0x940(%rbp)
leaq -0x930(%rbp), %rax
movq %rax, -0x938(%rbp)
leaq -0x900(%rbp), %rdi
leaq -0x940(%rbp), %rsi
callq 0x4310
movl %eax, -0x944(%rbp)
cmpl $0x0, -0x944(%rbp)
je 0x2bca
leaq 0x277e6(%rip), %rdi     # 0x2a37d
movb $0x0, %al
callq 0x2040
movq -0x50(%rbp), %rdi
callq 0x2080
movq -0x40(%rbp), %rdi
callq 0x2050
leaq -0x900(%rbp), %rdi
callq 0x4510
movl -0x944(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2dad
movq -0x50(%rbp), %rsi
movq 0x18(%rbp), %rdx
movq -0x68(%rbp), %rax
movl %eax, %ecx
leaq -0x900(%rbp), %rdi
leaq -0x58(%rbp), %r8
leaq -0x5c(%rbp), %r9
callq 0x28410
movl %eax, -0x944(%rbp)
movq -0x50(%rbp), %rdi
callq 0x2080
movq -0x40(%rbp), %rdi
callq 0x2050
leaq 0x2741b(%rip), %rdi     # 0x2a026
movb $0x0, %al
callq 0x2040
cmpl $0x0, -0x944(%rbp)
jge 0x2cb0
leaq 0x27786(%rip), %rdi     # 0x2a3ac
movb $0x0, %al
callq 0x2040
movl -0x944(%rbp), %esi
leaq 0x277a6(%rip), %rdi     # 0x2a3e0
movb $0x0, %al
callq 0x2040
leaq 0x277a8(%rip), %rdi     # 0x2a3f0
movb $0x0, %al
callq 0x2040
movq 0x3238a(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
movl -0x944(%rbp), %esi
callq 0x1fdd0
leaq 0x273bb(%rip), %rdi     # 0x2a026
movb $0x0, %al
callq 0x2040
movq -0x8d8(%rbp), %rsi
leaq 0x2777d(%rip), %rdi     # 0x2a3fd
movb $0x0, %al
callq 0x2040
leaq 0x27782(%rip), %rdi     # 0x2a410
movb $0x0, %al
callq 0x2040
movq 0x32344(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
leaq -0x900(%rbp), %rsi
callq 0x1fd60
jmp 0x2d67
cmpl $0x0, -0x944(%rbp)
jl 0x2d65
leaq 0x2775a(%rip), %rdi     # 0x2a41e
movb $0x0, %al
callq 0x2040
leaq 0x2777d(%rip), %rdi     # 0x2a44f
movb $0x0, %al
callq 0x2040
movq 0x322e8(%rip), %rax     # 0x34fc8
movq (%rax), %rdi
movl -0x944(%rbp), %esi
callq 0x20630
movl -0x944(%rbp), %esi
leaq 0x2775d(%rip), %rdi     # 0x2a458
movb $0x0, %al
callq 0x2040
cmpl $0x0, -0x944(%rbp)
jne 0x2d63
movq 0x18(%rbp), %rsi
leaq 0x27749(%rip), %rdi     # 0x2a45f
movb $0x0, %al
callq 0x2040
movl -0x5c(%rbp), %esi
shll $0x3, %esi
leaq 0x2774b(%rip), %rdi     # 0x2a475
movb $0x0, %al
callq 0x2040
leaq 0x2775a(%rip), %rdi     # 0x2a492
movb $0x0, %al
callq 0x2040
movq 0x32282(%rip), %rax     # 0x34fc8
movq (%rax), %rdi
movq -0x58(%rbp), %rsi
movl -0x5c(%rbp), %edx
callq 0x1fcd0
leaq 0x272ca(%rip), %rdi     # 0x2a026
movb $0x0, %al
callq 0x2040
jmp 0x2d65
jmp 0x2d67
leaq 0x272b8(%rip), %rdi     # 0x2a026
movb $0x0, %al
callq 0x2040
cmpq $0x0, -0x58(%rbp)
je 0x2d98
movq -0x58(%rbp), %rdi
movslq -0x5c(%rbp), %rdx
xorl %esi, %esi
callq 0x1fc90
movq -0x58(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x31b0
leaq -0x900(%rbp), %rdi
callq 0x4510
movl -0x944(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x950, %rsp            # imm = 0x950
popq %rbp
retq
nopl (%rax)