// File: /workspace/github_c_makefile_star2_O0/OpenKMIP[P]libkmip/src/kmip.c
// Function: kmip_encode_attribute_v1
int
kmip_encode_attribute_v1(KMIP *ctx, const Attribute *value)
{
    /* TODO (ph) Add CryptographicParameters support? */
    CHECK_ENCODE_ARGS(ctx, value);

    int result = 0;
    
    result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_ATTRIBUTE, KMIP_TYPE_STRUCTURE));
    CHECK_RESULT(ctx, result);
    
    uint8 *length_index = ctx->index;
    uint8 *value_index = ctx->index += 4;
    
    result = kmip_encode_attribute_name(ctx, value->type);
    CHECK_RESULT(ctx, result);
    
    if(value->index != KMIP_UNSET)
    {
        result = kmip_encode_integer(ctx, KMIP_TAG_ATTRIBUTE_INDEX, value->index);
        CHECK_RESULT(ctx, result);
    }
    
    uint8 *curr_index = 0;
    uint8 *tag_index = ctx->index;
    enum tag t = KMIP_TAG_ATTRIBUTE_VALUE;
    
    switch(value->type)
    {
        case KMIP_ATTR_APPLICATION_SPECIFIC_INFORMATION:
        {
            result = kmip_encode_application_specific_information(ctx, (ApplicationSpecificInformation*)value->value);
            CHECK_RESULT(ctx, result);

            curr_index = ctx->index;
            ctx->index = tag_index;

            result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_ATTRIBUTE_VALUE, KMIP_TYPE_STRUCTURE));

            ctx->index = curr_index;
        }
        break;

        case KMIP_ATTR_UNIQUE_IDENTIFIER:
        result = kmip_encode_text_string(ctx, t, (TextString*)value->value);
        break;
        
        case KMIP_ATTR_NAME:
        /* TODO (ph) This is messy. Clean it up? */
        result = kmip_encode_name(ctx, (Name*)value->value);
        CHECK_RESULT(ctx, result);
        
        curr_index = ctx->index;
        ctx->index = tag_index;
        
        result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_ATTRIBUTE_VALUE, KMIP_TYPE_STRUCTURE));
        
        ctx->index = curr_index;
        break;
        
        case KMIP_ATTR_OBJECT_TYPE:
        result = kmip_encode_enum(ctx, t, *(int32 *)value->value);
        break;
        
        case KMIP_ATTR_CRYPTOGRAPHIC_ALGORITHM:
        result = kmip_encode_enum(ctx, t, *(int32 *)value->value);
        break;
        
        case KMIP_ATTR_CRYPTOGRAPHIC_LENGTH:
        result = kmip_encode_integer(ctx, t, *(int32 *)value->value);
        break;
        
        case KMIP_ATTR_OPERATION_POLICY_NAME:
        result = kmip_encode_text_string(ctx, t, (TextString*)value->value);
        break;
        
        case KMIP_ATTR_CRYPTOGRAPHIC_USAGE_MASK:
        result = kmip_encode_integer(ctx, t, *(int32 *)value->value);
        break;
        
        case KMIP_ATTR_STATE:
        result = kmip_encode_enum(ctx, t, *(int32 *)value->value);
        break;
        
        case KMIP_ATTR_OBJECT_GROUP:
        {
            result = kmip_encode_text_string(ctx, t, (TextString*)value->value);
        }
        break;

        case KMIP_ATTR_ACTIVATION_DATE:
        case KMIP_ATTR_DEACTIVATION_DATE:
        case KMIP_ATTR_PROCESS_START_DATE:
        case KMIP_ATTR_PROTECT_STOP_DATE:
        {
            result = kmip_encode_date_time(ctx, t, *(int64 *)value->value);
        } break;

        case KMIP_ATTR_CRYPTOGRAPHIC_PARAMETERS:
        {
            result = kmip_encode_cryptographic_parameters(ctx, (CryptographicParameters*)value->value);
            CHECK_RESULT(ctx, result);

            curr_index = ctx->index;
            ctx->index = tag_index;

            result = kmip_encode_int32_be(ctx, TAG_TYPE(KMIP_TAG_ATTRIBUTE_VALUE, KMIP_TYPE_STRUCTURE));

            ctx->index = curr_index;
        } break;

        default:
        kmip_push_error_frame(ctx, __func__, __LINE__);
        return(KMIP_ERROR_ATTR_UNSUPPORTED);
        break;
    };
    CHECK_RESULT(ctx, result);
    
    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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x11573
movl $0xffffffef, -0x4(%rbp) # imm = 0xFFFFFFEF
jmp 0x119c8
cmpq $0x0, -0x18(%rbp)
jne 0x11586
movl $0x0, -0x4(%rbp)
jmp 0x119c8
jmp 0x11588
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movl $0x42000801, %esi       # imm = 0x42000801
callq 0x60b0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x115c6
movq -0x10(%rbp), %rdi
leaq 0x137c2(%rip), %rsi     # 0x24d73
movl $0x1971, %edx           # imm = 0x1971
callq 0x6f20
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x119c8
jmp 0x115c8
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rax
addq $0x4, %rax
movq %rax, 0x8(%rcx)
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %esi
callq 0x6940
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x11620
movq -0x10(%rbp), %rdi
leaq 0x13768(%rip), %rsi     # 0x24d73
movl $0x1977, %edx           # imm = 0x1977
callq 0x6f20
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x119c8
jmp 0x11622
movq -0x18(%rbp), %rax
cmpl $-0x1, 0x4(%rax)
je 0x1166e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edx
movl $0x420009, %esi         # imm = 0x420009
callq 0x6420
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x1166a
movq -0x10(%rbp), %rdi
leaq 0x1371e(%rip), %rsi     # 0x24d73
movl $0x197c, %edx           # imm = 0x197C
callq 0x6f20
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x119c8
jmp 0x1166c
jmp 0x1166e
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movl $0x42000b, -0x44(%rbp)  # imm = 0x42000B
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x50(%rbp)
subq $0xe, %rax
ja 0x11919
movq -0x50(%rbp), %rax
leaq 0x13194(%rip), %rcx     # 0x2483c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x6310
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x116eb
movq -0x10(%rbp), %rdi
leaq 0x1369d(%rip), %rsi     # 0x24d73
movl $0x1988, %edx           # imm = 0x1988
callq 0x6f20
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x119c8
jmp 0x116ed
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movl $0x42000b01, %esi       # imm = 0x42000B01
callq 0x60b0
movl %eax, -0x1c(%rbp)
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x1193a
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x66f0
movl %eax, -0x1c(%rbp)
jmp 0x1193a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x61a0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x1177d
movq -0x10(%rbp), %rdi
leaq 0x1360b(%rip), %rsi     # 0x24d73
movl $0x199a, %edx           # imm = 0x199A
callq 0x6f20
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x119c8
jmp 0x1177f
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movl $0x42000b01, %esi       # imm = 0x42000B01
callq 0x60b0
movl %eax, -0x1c(%rbp)
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x1193a
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %edx
callq 0x6770
movl %eax, -0x1c(%rbp)
jmp 0x1193a
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %edx
callq 0x6770
movl %eax, -0x1c(%rbp)
jmp 0x1193a
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %edx
callq 0x6420
movl %eax, -0x1c(%rbp)
jmp 0x1193a
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x66f0
movl %eax, -0x1c(%rbp)
jmp 0x1193a
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %edx
callq 0x6420
movl %eax, -0x1c(%rbp)
jmp 0x1193a
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %edx
callq 0x6770
movl %eax, -0x1c(%rbp)
jmp 0x1193a
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x66f0
movl %eax, -0x1c(%rbp)
jmp 0x1193a
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdx
callq 0x6250
movl %eax, -0x1c(%rbp)
jmp 0x1193a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x6d50
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x118e0
movq -0x10(%rbp), %rdi
leaq 0x134a8(%rip), %rsi     # 0x24d73
movl $0x19cd, %edx           # imm = 0x19CD
callq 0x6f20
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x119c8
jmp 0x118e2
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movl $0x42000b01, %esi       # imm = 0x42000B01
callq 0x60b0
movl %eax, -0x1c(%rbp)
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x1193a
movq -0x10(%rbp), %rdi
leaq 0x1344f(%rip), %rsi     # 0x24d73
movl $0x19d8, %edx           # imm = 0x19D8
callq 0x6f20
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x119c8
jmp 0x1193c
cmpl $0x0, -0x1c(%rbp)
je 0x1195f
movq -0x10(%rbp), %rdi
leaq 0x13426(%rip), %rsi     # 0x24d73
movl $0x19dc, %edx           # imm = 0x19DC
callq 0x6f20
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x119c8
jmp 0x11961
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rax
subq %rax, %rsi
callq 0x6ba0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x119b3
movq -0x10(%rbp), %rdi
leaq 0x133d2(%rip), %rsi     # 0x24d73
movl $0x19e2, %edx           # imm = 0x19E2
callq 0x6f20
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x119c8
jmp 0x119b5
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)