// File: /workspace/github_c_makefile_star2_O2/OpenKMIP[P]libkmip/src/kmip.c
// Function: kmip_encode_create_request_payload
int
kmip_encode_create_request_payload(KMIP *ctx, const CreateRequestPayload *value)
{
    CHECK_ENCODE_ARGS(ctx, value);

    int result = 0;
    result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_REQUEST_PAYLOAD, KMIP_TYPE_STRUCTURE));
    CHECK_RESULT(ctx, result);
    
    uint8 *length_index = ctx->index;
    uint8 *value_index = ctx->index += 4;
    
    result = kmip_encode_enum(ctx, KMIP_TAG_OBJECT_TYPE, value->object_type);
    CHECK_RESULT(ctx, result);

    if(ctx->version < KMIP_2_0)
    {
        result = kmip_encode_template_attribute(ctx, value->template_attribute);
        CHECK_RESULT(ctx, result);
    }
    else
    {
        if(value->attributes)
        {
            result = kmip_encode_attributes(ctx, value->attributes);
            CHECK_RESULT(ctx, result);
        }
        else if(value->template_attribute)
        {
            Attributes *attributes = ctx->calloc_func(ctx->state, 1, sizeof(Attributes));
            LinkedList *list = ctx->calloc_func(ctx->state, 1, sizeof(LinkedList));
            attributes->attribute_list = list;
            for(size_t i = 0; i < value->template_attribute->attribute_count; i++)
            {
                LinkedListItem *item = ctx->calloc_func(ctx->state, 1, sizeof(LinkedListItem));
                item->data = kmip_deep_copy_attribute(ctx, &value->template_attribute->attributes[i]);
                kmip_linked_list_enqueue(list, item);
            }

            result = kmip_encode_attributes(ctx, attributes);

            kmip_free_attributes(ctx, attributes);
            ctx->free_func(ctx->state, attributes);

            CHECK_RESULT(ctx, result);
        }

        if(value->protection_storage_masks != NULL)
        {
            result = kmip_encode_protection_storage_masks(ctx, value->protection_storage_masks);
            CHECK_RESULT(ctx, result);
        }
    }
    
    uint8 *curr_index = ctx->index;
    ctx->index = length_index;
    
    result = kmip_encode_length(ctx, curr_index - value_index);
    CHECK_RESULT(ctx, result);

    ctx->index = curr_index;
    
    return(KMIP_OK);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
testq %rdi, %rdi
je 0xd3e8
movq %rsi, %r14
xorl %ebp, %ebp
testq %rsi, %rsi
je 0xd427
movq %rdi, %rbx
movl $0x42007901, %esi       # imm = 0x42007901
callq 0x60a0
testl %eax, %eax
je 0xd3ed
movl %eax, %r15d
leaq 0xa6fa(%rip), %rsi      # 0x17ad8
movq %rbx, %rdi
movl $0x1d77, %edx           # imm = 0x1D77
jmp 0xd41f
pushq $-0x11
popq %rbp
jmp 0xd427
movq 0x8(%rbx), %r13
leaq 0x4(%r13), %r12
movq %r12, 0x8(%rbx)
movl (%r14), %edx
movq %rbx, %rdi
movl $0x420057, %esi         # imm = 0x420057
callq 0x6700
testl %eax, %eax
je 0xd438
movl %eax, %r15d
leaq 0xa6c1(%rip), %rsi      # 0x17ad8
movq %rbx, %rdi
movl $0x1d7d, %edx           # imm = 0x1D7D
callq 0x6e80
movl %r15d, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x4, 0x18(%rbx)
ja 0xd469
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x6d30
testl %eax, %eax
je 0xd5b3
movl %eax, %r14d
leaq 0xa67c(%rip), %rsi      # 0x17ad8
movq %rbx, %rdi
movl $0x1d82, %edx           # imm = 0x1D82
jmp 0xd5df
movq 0x10(%r14), %rsi
testq %rsi, %rsi
je 0xd496
movq %rbx, %rdi
callq 0x6360
testl %eax, %eax
je 0xd58a
movl %eax, %r15d
leaq 0xa64c(%rip), %rsi      # 0x17ad8
movq %rbx, %rdi
movl $0x1d89, %edx           # imm = 0x1D89
jmp 0xd41f
cmpq $0x0, 0x8(%r14)
je 0xd58a
movq %r13, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq 0x890(%rbx), %rdi
pushq $0x1
popq %r12
pushq $0x8
popq %rdx
movq %r12, %rsi
callq *0x868(%rbx)
movq %rax, %r15
movq 0x890(%rbx), %rdi
pushq $0x18
popq %rdx
movq %r12, %rsi
callq *0x868(%rbx)
movq %r15, 0x8(%rsp)
movq %rax, 0x20(%rsp)
movq %rax, (%r15)
xorl %r13d, %r13d
xorl %r15d, %r15d
movq 0x8(%r14), %rax
cmpq 0x18(%rax), %r15
jae 0xd539
movq 0x890(%rbx), %rdi
pushq $0x1
popq %rsi
pushq $0x18
popq %rdx
callq *0x868(%rbx)
movq %rax, %r12
movq 0x8(%r14), %rax
movq 0x10(%rax), %rsi
addq %r13, %rsi
movq %rbx, %rdi
callq 0x62c0
movq %rax, 0x10(%r12)
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x6770
incq %r15
addq $0x10, %r13
jmp 0xd4eb
movq %rbx, %rdi
movq 0x8(%rsp), %r12
movq %r12, %rsi
callq 0x6360
movl %eax, %r15d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6e30
movq 0x890(%rbx), %rdi
movq %r12, %rsi
callq *0x878(%rbx)
testl %r15d, %r15d
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %r13
je 0xd58a
leaq 0xa55b(%rip), %rsi      # 0x17ad8
movq %rbx, %rdi
movl $0x1d9c, %edx           # imm = 0x1D9C
jmp 0xd41f
movq 0x18(%r14), %rsi
testq %rsi, %rsi
je 0xd5b3
movq %rbx, %rdi
callq 0x6470
testl %eax, %eax
je 0xd5b3
movl %eax, %r14d
leaq 0xa52f(%rip), %rsi      # 0x17ad8
movq %rbx, %rdi
movl $0x1da2, %edx           # imm = 0x1DA2
jmp 0xd5df
movq 0x8(%rbx), %r15
movq %r13, 0x8(%rbx)
movq %r15, %rsi
subq %r12, %rsi
movq %rbx, %rdi
callq 0x6b10
testl %eax, %eax
je 0xd5ec
movl %eax, %r14d
leaq 0xa501(%rip), %rsi      # 0x17ad8
movq %rbx, %rdi
movl $0x1daa, %edx           # imm = 0x1DAA
callq 0x6e80
movl %r14d, %ebp
jmp 0xd427
movq %r15, 0x8(%rbx)
jmp 0xd427