// File: rurban[P]dgnlib/dgnwrite.cpp
// Function: DGNCreateComplexHeaderElem
DGNElemCore *
DGNCreateComplexHeaderElem( DGNHandle hDGN, int nType, 
                            int nTotLength, int nNumElems )
{
    DGNElemComplexHeader *psCH;
    DGNElemCore *psCore;
    unsigned char abyRawZeroLinkage[8] = {0,0,0,0,0,0,0,0};

    CPLAssert( nType == DGNT_COMPLEX_CHAIN_HEADER 
               || nType == DGNT_COMPLEX_SHAPE_HEADER );

    DGNLoadTCB( hDGN );

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

    DGNInitializeElemCore( hDGN, psCore );
    psCore->complex = TRUE;
    psCore->stype = DGNST_COMPLEX_HEADER;
    psCore->type = nType;

/* -------------------------------------------------------------------- */
/*      Set complex header specific information in the structure.       */
/* -------------------------------------------------------------------- */
    psCH->totlength = nTotLength - 4;
    psCH->numelems = nNumElems;
    psCH->surftype = 0;
    psCH->boundelms = 0;

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

    psCore->raw_data[36] = (unsigned char) ((nTotLength-4) % 256);
    psCore->raw_data[37] = (unsigned char) ((nTotLength-4) / 256);
    psCore->raw_data[38] = (unsigned char) (nNumElems % 256);
    psCore->raw_data[39] = (unsigned char) (nNumElems / 256);

/* -------------------------------------------------------------------- */
/*      Set the core raw data.                                          */
/* -------------------------------------------------------------------- */
    DGNUpdateElemCoreExtended( hDGN, psCore );

/* -------------------------------------------------------------------- */
/*      Elements have to be at least 48 bytes long, so we have to       */
/*      add a dummy bit of attribute data to fill out the length.       */
/* -------------------------------------------------------------------- */
    DGNAddRawAttrLink( hDGN, psCore, 8, abyRawZeroLinkage );
    
    return psCore;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x2170
movq -0x8(%rbp), %rdi
callq 0x11190
movl $0x60, %edi
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 $0x1, 0x18(%rax)
movq -0x28(%rbp), %rax
movl $0x7, 0xc(%rax)
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x10(%rbp), %ecx
subl $0x4, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x50(%rax)
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x58(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x5c(%rax)
movq -0x28(%rbp), %rax
movl $0x28, 0x40(%rax)
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 -0x10(%rbp), %eax
subl $0x4, %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 -0x10(%rbp), %eax
subl $0x4, %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movb %al, %cl
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movb %cl, 0x25(%rax)
movl -0x14(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movb %dl, %cl
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movb %cl, 0x26(%rax)
movl -0x14(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movb %al, %cl
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movb %cl, 0x27(%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x12f50
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x30(%rbp), %rcx
movl $0x8, %edx
callq 0x15fb0
movq -0x28(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nop