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

    CPLAssert( nType == DGNT_3DSURFACE_HEADER 
               || nType == DGNT_3DSOLID_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 solid header specific information in the structure.         */
/* -------------------------------------------------------------------- */
    psCH->totlength = nTotLength - 4;
    psCH->numelems = nNumElems;
    psCH->surftype = nSurfType;
    psCH->boundelms = nBoundElems;

/* -------------------------------------------------------------------- */
/*      Setup Raw data for the solid specific portion.                  */
/* -------------------------------------------------------------------- */
    psCore->raw_bytes = 42;

    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);
    psCore->raw_data[40] = (unsigned char) psCH->surftype;
    psCore->raw_data[41] = (unsigned char) psCH->boundelms - 1;

/* -------------------------------------------------------------------- */
/*      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 $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
leaq -0x38(%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, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x135f0
movq -0x30(%rbp), %rax
movl $0x1, 0x18(%rax)
movq -0x30(%rbp), %rax
movl $0x7, 0xc(%rax)
movl -0xc(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x18(%rbp), %ecx
subl $0x4, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x50(%rax)
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x54(%rax)
movl -0x10(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x58(%rax)
movl -0x14(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x5c(%rax)
movq -0x30(%rbp), %rax
movl $0x2a, 0x40(%rax)
movq -0x30(%rbp), %rax
movslq 0x40(%rax), %rdi
movl $0x1, %esi
callq 0x2fc0
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
movl -0x18(%rbp), %eax
subl $0x4, %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movb %dl, %cl
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movb %cl, 0x24(%rax)
movl -0x18(%rbp), %eax
subl $0x4, %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movb %al, %cl
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movb %cl, 0x25(%rax)
movl -0x1c(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movb %dl, %cl
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movb %cl, 0x26(%rax)
movl -0x1c(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movb %al, %cl
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movb %cl, 0x27(%rax)
movq -0x28(%rbp), %rax
movl 0x58(%rax), %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movb %cl, 0x28(%rax)
movq -0x28(%rbp), %rax
movl 0x5c(%rax), %eax
movzbl %al, %eax
subl $0x1, %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rax
movb %cl, 0x29(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x12f50
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0x38(%rbp), %rcx
movl $0x8, %edx
callq 0x15fb0
movq -0x30(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)