// File: rurban[P]dgnlib/dgnwrite.cpp
// Function: DGNCreateColorTableElem
DGNElemCore *
DGNCreateColorTableElem( DGNHandle hDGN, int nScreenFlag, 
                         GByte abyColorInfo[256][3] )

{
    DGNElemColorTable *psCT;
    DGNElemCore *psCore;

/* -------------------------------------------------------------------- */
/*      Allocate element.                                               */
/* -------------------------------------------------------------------- */
    psCT = (DGNElemColorTable *) CPLCalloc( sizeof(DGNElemColorTable), 1 );
    psCore = &(psCT->core);

    DGNInitializeElemCore( hDGN, psCore );
    psCore->stype = DGNST_COLORTABLE;
    psCore->type = DGNT_GROUP_DATA;
    psCore->level = DGN_GDL_COLOR_TABLE;

/* -------------------------------------------------------------------- */
/*      Set colortable specific information in the structure.           */
/* -------------------------------------------------------------------- */
    psCT->screen_flag = nScreenFlag;
    memcpy( psCT->color_info, abyColorInfo, 768 );

/* -------------------------------------------------------------------- */
/*      Setup Raw data for the color table specific portion.            */
/* -------------------------------------------------------------------- */
    psCore->raw_bytes = 806;
    psCore->raw_data = (unsigned char*) CPLCalloc(psCore->raw_bytes,1);

    psCore->raw_data[36] = (unsigned char) (nScreenFlag % 256);
    psCore->raw_data[37] = (unsigned char) (nScreenFlag / 256);

    memcpy( psCore->raw_data + 38, abyColorInfo[255], 3 );
    memcpy( psCore->raw_data + 41, abyColorInfo, 783 );
    
/* -------------------------------------------------------------------- */
/*      Set the core raw data.                                          */
/* -------------------------------------------------------------------- */
    DGNUpdateElemCoreExtended( hDGN, psCore );
    
    return psCore;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x358, %edi            # imm = 0x358
movl $0x1, %esi
callq 0x2fc0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x135f0
movq -0x28(%rbp), %rax
movl $0x3, 0xc(%rax)
movq -0x28(%rbp), %rax
movl $0x5, 0x14(%rax)
movq -0x28(%rbp), %rax
movl $0x1, 0x10(%rax)
movl -0xc(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x20(%rbp), %rdi
addq $0x54, %rdi
movq -0x18(%rbp), %rsi
movl $0x300, %edx            # imm = 0x300
callq 0x2240
movq -0x28(%rbp), %rax
movl $0x326, 0x40(%rax)      # imm = 0x326
movq -0x28(%rbp), %rax
movslq 0x40(%rax), %rdi
movl $0x1, %esi
callq 0x2fc0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x48(%rax)
movl -0xc(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movb %dl, %cl
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movb %cl, 0x24(%rax)
movl -0xc(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movb %al, %cl
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movb %cl, 0x25(%rax)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x18(%rbp), %rcx
movw 0x2fd(%rcx), %dx
movw %dx, 0x26(%rax)
movb 0x2ff(%rcx), %cl
movb %cl, 0x28(%rax)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rdi
addq $0x29, %rdi
movq -0x18(%rbp), %rsi
movl $0x30f, %edx            # imm = 0x30F
callq 0x2240
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x12f50
movq -0x28(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)