// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r9d, %ebp
movl %r8d, %r12d
movl %ecx, %r13d
movl %edx, %ebx
movl %esi, %r14d
movq %rdi, 0x8(%rsp)
leaq 0x10(%rsp), %rax
andq $0x0, (%rax)
callq 0xa500
pushq $0x60
popq %rdi
pushq $0x1
popq %rsi
callq 0x2c6c
movq %rax, %r15
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x40(%rax)
orl $-0x1, (%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movabsq $0x7ffffffff, %rax      # imm = 0x7FFFFFFFF
movq %rax, 0x8(%r15)
movl $0x1, 0x18(%r15)
movl %r14d, 0x14(%r15)
addl $-0x4, %r12d
movl %r12d, 0x50(%r15)
movl %ebp, 0x54(%r15)
movl %ebx, 0x58(%r15)
movl %r13d, 0x5c(%r15)
movl $0x2a, 0x40(%r15)
pushq $0x2a
popq %rdi
pushq $0x1
popq %rsi
callq 0x2c6c
movq %rax, 0x48(%r15)
movb %r12b, 0x24(%rax)
movl $0x100, %ecx            # imm = 0x100
movl %r12d, %eax
cltd
idivl %ecx
movq 0x48(%r15), %rdx
movb %al, 0x25(%rdx)
movq 0x48(%r15), %rax
movb %bpl, 0x26(%rax)
movl %ebp, %eax
cltd
idivl %ecx
movq 0x48(%r15), %rcx
movb %al, 0x27(%rcx)
movb 0x58(%r15), %al
movq 0x48(%r15), %rcx
movb %al, 0x28(%rcx)
movb 0x5c(%r15), %al
decb %al
movq 0x48(%r15), %rcx
movb %al, 0x29(%rcx)
movq %r15, %rsi
callq 0xb380
pushq $0x8
popq %rdx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
leaq 0x10(%rsp), %rcx
callq 0xc7b3
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq