// File: /workspace/github_c_makefile_star2_O3/OpenKMIP[P]libkmip/tests/tests.c
// Function: test_encode_create_request_payload_kmip_2_0
int
test_encode_create_request_payload_kmip_2_0(TestTracker *tracker)
{
    TRACK_TEST(tracker);

    /* This encoding matches the following set of values:
    *  Request Payload
    *      Object Type - Symmetric Key
    *      Attributes
    *          Cryptographic Algorithm - AES
    *          Cryptographic Length - 128
    *          Cryptographic Usage Mask - Encrypt | Decrypt
    *      Protection Storage Masks
    *          Protection Storage Mask - Software | On System
    *          Protection Storage Mask - Off System | Off Premises
    */
    uint8 expected[120] = {
        0x42, 0x00, 0x79, 0x01, 0x00, 0x00, 0x00, 0x70, 
        0x42, 0x00, 0x57, 0x05, 0x00, 0x00, 0x00, 0x04, 
        0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
        0x42, 0x01, 0x25, 0x01, 0x00, 0x00, 0x00, 0x30,
        0x42, 0x00, 0x28, 0x05, 0x00, 0x00, 0x00, 0x04,
        0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
        0x42, 0x00, 0x2A, 0x02, 0x00, 0x00, 0x00, 0x04,
        0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00,
        0x42, 0x00, 0x2C, 0x02, 0x00, 0x00, 0x00, 0x04,
        0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00,
        0x42, 0x01, 0x5F, 0x01, 0x00, 0x00, 0x00, 0x20,
        0x42, 0x01, 0x5E, 0x02, 0x00, 0x00, 0x00, 0x04,
        0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00,
        0x42, 0x01, 0x5E, 0x02, 0x00, 0x00, 0x00, 0x04,
        0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00
    };
    
    uint8 observed[120] = {0};
    struct kmip ctx = {0};
    kmip_init(&ctx, observed, ARRAY_LENGTH(observed), KMIP_2_0);
    
    Attribute a[3] = {0};
    for(int i = 0; i < 3; i++)
    {
        kmip_init_attribute(&a[i]);
    }
    
    enum cryptographic_algorithm algorithm = KMIP_CRYPTOALG_AES;
    a[0].type = KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM;
    a[0].value = &algorithm;
    
    int32 length = 128;
    a[1].type = KMIP_ATTR_CRYPTOGRAPHIC_LENGTH;
    a[1].value = &length;
    
    int32 mask = KMIP_CRYPTOMASK_ENCRYPT | KMIP_CRYPTOMASK_DECRYPT;
    a[2].type = KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK;
    a[2].value = &mask;
    
    Attributes attributes = {0};
    LinkedList list = {0};
    LinkedListItem item_1, item_2, item_3 = {0};
    item_1.data = &a[0];
    item_2.data = &a[1];
    item_3.data = &a[2];
    kmip_linked_list_enqueue(&list, &item_1);
    kmip_linked_list_enqueue(&list, &item_2);
    kmip_linked_list_enqueue(&list, &item_3);
    attributes.attribute_list = &list;

    ProtectionStorageMasks psm = {0};
    LinkedList masks = {0};
    LinkedListItem mask_1, mask_2 = {0};
    int32 m1 = KMIP_PROTECT_SOFTWARE | KMIP_PROTECT_ON_SYSTEM;
    int32 m2 = KMIP_PROTECT_OFF_SYSTEM | KMIP_PROTECT_OFF_PREMISES;
    mask_1.data = &m1;
    mask_2.data = &m2;
    kmip_linked_list_enqueue(&masks, &mask_1);
    kmip_linked_list_enqueue(&masks, &mask_2);
    psm.masks = &masks;

    CreateRequestPayload payload = {0};
    payload.object_type = KMIP_OBJTYPE_SYMMETRIC_KEY;
    payload.attributes = &attributes;
    payload.protection_storage_masks = &psm;
    
    int result = kmip_encode_create_request_payload(&ctx, &payload);
    result = report_encoding_test_result(
        tracker,
        &ctx,
        expected,
        observed,
        result,
        __func__);
    kmip_destroy(&ctx);
    return(result);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa50, %rsp            # imm = 0xA50
movq %rdi, %rbx
incw (%rdi)
xorps %xmm0, %xmm0
leaq 0x140(%rsp), %r14
movaps %xmm0, 0x60(%r14)
movaps %xmm0, 0x50(%r14)
movaps %xmm0, 0x40(%r14)
movaps %xmm0, 0x30(%r14)
movaps %xmm0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
movq $0x0, 0x70(%r14)
leaq 0x1b8(%rsp), %r15
xorl %r12d, %r12d
movl $0x898, %edx            # imm = 0x898
movq %r15, %rdi
xorl %esi, %esi
callq 0x10c0
movl $0x78, %edx
movq %r15, %rdi
movq %r14, %rsi
movl $0x5, %ecx
callq 0x13177
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
leaq (%rsp,%r12), %rdi
addq $0x20, %rdi
callq 0x1388b
addq $0x10, %r12
cmpq $0x30, %r12
jne 0x9953
movl $0x3, %eax
leaq 0x1c(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x30(%rsp), %rdx
movl %eax, -0x10(%rdx)
movq %rcx, -0x8(%rdx)
leaq 0x18(%rsp), %rax
movl $0x80, (%rax)
movl $0x4, (%rdx)
movq %rax, 0x8(%rdx)
leaq 0x14(%rsp), %rax
movl $0xc, (%rax)
leaq 0x40(%rsp), %rcx
movl $0x6, (%rcx)
movq %rax, 0x8(%rcx)
xorl %r13d, %r13d
leaq 0xc0(%rsp), %r14
movq %r13, 0x10(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
leaq 0xa0(%rsp), %r15
movaps %xmm0, (%r15)
leaq 0x20(%rsp), %rax
leaq 0x108(%rsp), %rsi
movq %rax, 0x10(%rsi)
leaq 0xf0(%rsp), %r12
movq %rdx, 0x10(%r12)
movq %rcx, 0x10(%r15)
movq %r14, %rdi
callq 0x128ec
movq %r14, %rdi
movq %r12, %rsi
callq 0x128ec
movq %r14, %rdi
movq %r15, %rsi
callq 0x128ec
leaq 0x58(%rsp), %r12
movq %r14, (%r12)
leaq 0x80(%rsp), %r14
movq %r13, 0x10(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
leaq 0x60(%rsp), %r15
movaps %xmm0, (%r15)
leaq 0x10(%rsp), %rax
movl $0x9, (%rax)
leaq 0xc(%rsp), %rcx
movl $0x210, (%rcx)          # imm = 0x210
leaq 0xd8(%rsp), %rsi
movq %rax, 0x10(%rsi)
movq %rcx, 0x10(%r15)
movq %r14, %rdi
callq 0x128ec
movq %r14, %rdi
movq %r15, %rsi
callq 0x128ec
leaq 0x50(%rsp), %rax
movq %r14, (%rax)
leaq 0x120(%rsp), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, (%rsi)
movl $0x2, (%rsi)
movq %r12, 0x10(%rsi)
movq %rax, 0x18(%rsi)
leaq 0x1b8(%rsp), %r14
movq %r14, %rdi
callq 0x19bcf
leaq 0x27584(%rip), %rdx     # 0x31030
leaq 0x24795(%rip), %r9      # 0x2e248
leaq 0x140(%rsp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movl %eax, %r8d
callq 0x123c
movl %eax, %ebx
movq %r14, %rdi
callq 0x13455
movl %ebx, %eax
addq $0xa50, %rsp            # imm = 0xA50
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq