// File: /workspace/github_cpp_makefile_star2_O2/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 %rsi, %rbx
movq 0x48(%rsi), %r14
movl 0x40(%rsi), %ecx
pushq $0x2
popq %rsi
movl %ecx, %eax
cltd
idivl %esi
testq %r14, %r14
sete %dl
cmpl $0x24, %ecx
setl %cl
xorl %ebp, %ebp
orb %dl, %cl
jne 0xb464
movb 0x10(%rbx), %cl
movb %cl, (%r14)
cmpl $0x0, 0x18(%rbx)
je 0xb3be
orb $-0x80, %cl
movb %cl, (%r14)
addl $-0x2, %eax
movb 0x14(%rbx), %cl
movb %cl, 0x1(%r14)
cmpl $0x0, 0x1c(%rbx)
je 0xb3d5
orb $-0x80, %cl
movb %cl, 0x1(%r14)
movb %al, 0x2(%r14)
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movb %al, 0x3(%r14)
movq 0x48(%rbx), %rdi
cmpb $0x0, 0x1e(%rdi)
jne 0xb414
cmpb $0x0, 0x1f(%rdi)
jne 0xb414
movl 0x40(%rbx), %ecx
addl $-0x20, %ecx
movl %ecx, %eax
cltd
idivl %esi
movb %al, 0x1e(%rdi)
movl $0x200, %esi            # imm = 0x200
movl %ecx, %eax
cltd
idivl %esi
movq 0x48(%rbx), %rcx
movb %al, 0x1f(%rcx)
pushq $0x1
popq %rbp
cmpl $0x25, 0x40(%rbx)
jl 0xb464
movl 0x14(%rbx), %edi
callq 0xa1a5
testl %eax, %eax
je 0xb464
movb 0x20(%rbx), %al
movb %al, 0x1c(%r14)
movl 0x20(%rbx), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movb %al, 0x1d(%r14)
movb 0x24(%rbx), %al
movb %al, 0x20(%r14)
movl 0x24(%rbx), %eax
cltd
idivl %ecx
movb %al, 0x21(%r14)
movl 0x2c(%rbx), %eax
shll $0x3, %eax
orl 0x30(%rbx), %eax
movb %al, 0x22(%r14)
movb 0x28(%rbx), %al
movb %al, 0x23(%r14)
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq