// File: /workspace/github_cpp_makefile_star2_O1/rurban[P]dgnlib/dgnwrite.cpp
// Function: DGNUpdateElemCoreExtended
int DGNUpdateElemCoreExtended( DGNHandle hDGN, DGNElemCore *psElement )

{
    GByte *rd = psElement->raw_data;
    int   nWords = (psElement->raw_bytes / 2) - 2;

    if( psElement->raw_data == NULL 
        || psElement->raw_bytes < 36 )
    {
        CPLAssert( FALSE );
        return FALSE;
    }

/* -------------------------------------------------------------------- */
/*      Setup first four bytes.                                         */
/* -------------------------------------------------------------------- */
    rd[0] = (GByte) psElement->level;
    if( psElement->complex )
        rd[0] |= 0x80;

    rd[1] = (GByte) psElement->type;
    if( psElement->deleted )
        rd[1] |= 0x80;

    rd[2] = (GByte) (nWords % 256);
    rd[3] = (GByte) (nWords / 256);

/* -------------------------------------------------------------------- */
/*      If the attribute offset hasn't been set, set it now under       */
/*      the assumption it should point to the end of the element.       */
/* -------------------------------------------------------------------- */
    if( psElement->raw_data[30] == 0 && psElement->raw_data[31] == 0 )
    {
        int     nAttIndex = (psElement->raw_bytes - 32) / 2;
        
        psElement->raw_data[30] = (GByte) (nAttIndex % 256);
        psElement->raw_data[31] = (GByte) (nAttIndex / 256);
    }
/* -------------------------------------------------------------------- */
/*      Handle the graphic properties.                                  */
/* -------------------------------------------------------------------- */
    if( psElement->raw_bytes > 36 && DGNElemTypeHasDispHdr( psElement->type ) )
    {
        rd[28] = (GByte) (psElement->graphic_group % 256);
        rd[29] = (GByte) (psElement->graphic_group / 256);
        rd[32] = (GByte) (psElement->properties % 256);
        rd[33] = (GByte) (psElement->properties / 256);
        rd[34] = (GByte) (psElement->style | (psElement->weight << 3));
        rd[35] = (GByte) psElement->color;
    }
    
    return TRUE;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq 0x48(%rsi), %rbp
movl 0x40(%rsi), %ecx
testq %rbp, %rbp
sete %al
cmpl $0x24, %ecx
setl %dl
xorl %r14d, %r14d
orb %al, %dl
jne 0xc566
movq %rsi, %rbx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
movb 0x10(%rsi), %cl
movb %cl, (%rbp)
cmpl $0x0, 0x18(%rsi)
je 0xc4af
orb $-0x80, %cl
movb %cl, (%rbp)
addl $-0x2, %eax
movb 0x14(%rbx), %cl
movb %cl, 0x1(%rbp)
cmpl $0x0, 0x1c(%rbx)
je 0xc4c4
orb $-0x80, %cl
movb %cl, 0x1(%rbp)
movb %al, 0x2(%rbp)
leal 0xff(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
movb %ch, 0x3(%rbp)
movq 0x48(%rbx), %rax
cmpb $0x0, 0x1e(%rax)
jne 0xc510
cmpb $0x0, 0x1f(%rax)
jne 0xc510
movl 0x40(%rbx), %ecx
leal -0x20(%rcx), %edx
movl %edx, %esi
shrl $0x1f, %esi
addl %ecx, %esi
addl $-0x20, %esi
shrl %esi
addl $0x1df, %ecx            # imm = 0x1DF
testl %edx, %edx
cmovnsl %edx, %ecx
movb %sil, 0x1e(%rax)
shrl $0x9, %ecx
movq 0x48(%rbx), %rax
movb %cl, 0x1f(%rax)
movl $0x1, %r14d
cmpl $0x25, 0x40(%rbx)
jl 0xc566
movl 0x14(%rbx), %edi
callq 0xaf82
testl %eax, %eax
je 0xc566
movb 0x20(%rbx), %al
movb %al, 0x1c(%rbp)
movl 0x20(%rbx), %ecx
movl $0xff, %eax
leal (%rcx,%rax), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
movb %dh, 0x1d(%rbp)
movb 0x24(%rbx), %cl
movb %cl, 0x20(%rbp)
movl 0x24(%rbx), %ecx
addl %ecx, %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
movb %ah, 0x21(%rbp)
movl 0x2c(%rbx), %eax
shll $0x3, %eax
orl 0x30(%rbx), %eax
movb %al, 0x22(%rbp)
movb 0x28(%rbx), %al
movb %al, 0x23(%rbp)
movl %r14d, %eax
popq %rbx
popq %r14
popq %rbp
retq