// File: /workspace/github_c_makefile_star2_O3/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 0xe2c5
movq %rsi, %r14
xorl %ebp, %ebp
testq %rsi, %rsi
je 0xe307
movq %rdi, %rbx
movl $0x42007901, %esi       # imm = 0x42007901
callq 0x60a0
testl %eax, %eax
je 0xe2cc
movl %eax, %r15d
leaq 0x120bb(%rip), %rsi     # 0x20376
movq %rbx, %rdi
movl $0x1d77, %edx           # imm = 0x1D77
jmp 0xe2ff
movl $0xffffffef, %ebp       # imm = 0xFFFFFFEF
jmp 0xe307
movq 0x8(%rbx), %r12
leaq 0x4(%r12), %r13
movq %r13, 0x8(%rbx)
movl (%r14), %edx
movq %rbx, %rdi
movl $0x420057, %esi         # imm = 0x420057
callq 0x66d0
testl %eax, %eax
je 0xe318
movl %eax, %r15d
leaq 0x1207f(%rip), %rsi     # 0x20376
movq %rbx, %rdi
movl $0x1d7d, %edx           # imm = 0x1D7D
callq 0x6de0
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 0xe349
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x6c90
testl %eax, %eax
je 0xe4ab
movl %eax, %r14d
leaq 0x1203a(%rip), %rsi     # 0x20376
movq %rbx, %rdi
movl $0x1d82, %edx           # imm = 0x1D82
jmp 0xe4d7
movq %r12, 0x18(%rsp)
movq 0x10(%r14), %rsi
testq %rsi, %rsi
je 0xe37b
movq %rbx, %rdi
callq 0x6340
testl %eax, %eax
je 0xe47d
movl %eax, %r15d
leaq 0x12005(%rip), %rsi     # 0x20376
movq %rbx, %rdi
movl $0x1d89, %edx           # imm = 0x1D89
jmp 0xe2ff
cmpq $0x0, 0x8(%r14)
je 0xe47d
movq %r13, 0x10(%rsp)
movq 0x890(%rbx), %rdi
movl $0x1, %esi
movl $0x8, %edx
callq *0x868(%rbx)
movq %rax, %r15
movq 0x890(%rbx), %rdi
movl $0x1, %esi
movl $0x18, %edx
callq *0x868(%rbx)
movq %r15, 0x8(%rsp)
movq %rax, 0x20(%rsp)
movq %rax, (%r15)
movq 0x8(%r14), %rax
cmpq $0x0, 0x18(%rax)
je 0xe429
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x890(%rbx), %rdi
movl $0x1, %esi
movl $0x18, %edx
callq *0x868(%rbx)
movq %rax, %r13
movq 0x8(%r14), %rax
movq 0x10(%rax), %rsi
addq %r15, %rsi
movq %rbx, %rdi
callq 0x62b0
movq %rax, 0x10(%r13)
movq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x6740
incq %r12
movq 0x8(%r14), %rax
addq $0x10, %r15
cmpq 0x18(%rax), %r12
jb 0xe3da
movq %rbx, %rdi
movq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0x6340
movl %eax, %r12d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6d90
movq 0x890(%rbx), %rdi
movq %r15, %rsi
callq *0x878(%rbx)
testl %r12d, %r12d
movq 0x10(%rsp), %r13
je 0xe47d
leaq 0x11f0e(%rip), %rsi     # 0x20376
movq %rbx, %rdi
movl $0x1d9c, %edx           # imm = 0x1D9C
callq 0x6de0
movl %r12d, %ebp
jmp 0xe307
movq 0x18(%r14), %rsi
testq %rsi, %rsi
movq 0x18(%rsp), %r12
je 0xe4ab
movq %rbx, %rdi
callq 0x6450
testl %eax, %eax
je 0xe4ab
movl %eax, %r14d
leaq 0x11ed5(%rip), %rsi     # 0x20376
movq %rbx, %rdi
movl $0x1da2, %edx           # imm = 0x1DA2
jmp 0xe4d7
movq 0x8(%rbx), %r15
movq %r12, 0x8(%rbx)
movq %r15, %rsi
subq %r13, %rsi
movq %rbx, %rdi
callq 0x6a80
testl %eax, %eax
je 0xe4e4
movl %eax, %r14d
leaq 0x11ea7(%rip), %rsi     # 0x20376
movq %rbx, %rdi
movl $0x1daa, %edx           # imm = 0x1DAA
callq 0x6de0
movl %r14d, %ebp
jmp 0xe307
movq %r15, 0x8(%rbx)
jmp 0xe307