// File: /workspace/github_cpp_makefile_star2_O1/rurban[P]dgnlib/dgnwrite.cpp
// Function: DGNCreateSolidHeaderFromGroup
DGNElemCore *
DGNCreateSolidHeaderFromGroup( DGNHandle hDGN, int nType, int nSurfType,
                               int nBoundElems, int nNumElems, 
                               DGNElemCore **papsElems )

{
    int         nTotalLength = 6;
    int         i, nLevel;
    DGNElemCore *psCH;
    DGNPoint    sMin = {0.0,0.0,0.0}, sMax = {0.0,0.0,0.0};

    DGNLoadTCB( hDGN );

    if( nNumElems < 1 || papsElems == NULL )
    {
        CPLError( CE_Failure, CPLE_AppDefined, 
                  "Need at least one element to form a solid." );
        return NULL;
    }

/* -------------------------------------------------------------------- */
/*      Collect the total size, and bounds.                             */
/* -------------------------------------------------------------------- */
    nLevel = papsElems[0]->level;

    for( i = 0; i < nNumElems; i++ )
    {
        DGNPoint sThisMin, sThisMax;

        nTotalLength += papsElems[i]->raw_bytes / 2;

        papsElems[i]->complex = TRUE;
        papsElems[i]->raw_data[0] |= 0x80;

        if( papsElems[i]->level != nLevel )
        {
            CPLError( CE_Warning, CPLE_AppDefined, 
                      "Not all level values matching in a complex set group!");
        }

        DGNGetElementExtents( hDGN, papsElems[i], &sThisMin, &sThisMax );
        if( i == 0 )
        {
            sMin = sThisMin;
            sMax = sThisMax;
        }
        else
        {
            sMin.x = MIN(sMin.x,sThisMin.x);
            sMin.y = MIN(sMin.y,sThisMin.y);
            sMin.z = MIN(sMin.z,sThisMin.z);
            sMax.x = MAX(sMax.x,sThisMax.x);
            sMax.y = MAX(sMax.y,sThisMax.y);
            sMax.z = MAX(sMax.z,sThisMax.z);
        }
    }

/* -------------------------------------------------------------------- */
/*      Create the corresponding solid header.                          */
/* -------------------------------------------------------------------- */
    psCH = DGNCreateSolidHeaderElem( hDGN, nType, nSurfType, nBoundElems, 
                                     nTotalLength, nNumElems );
    DGNUpdateElemCore( hDGN, psCH, papsElems[0]->level, psCH->graphic_group,
                       psCH->color, psCH->weight, psCH->style );

    DGNWriteBounds( (DGNInfo *) hDGN, psCH, &sMin, &sMax );
    
    return psCH;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, %r14
movl %r8d, %ebx
movl %ecx, %ebp
movl %edx, %r15d
movl %esi, %r12d
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movq %rax, 0x20(%rsp)
movapd %xmm0, 0x10(%rsp)
movq %rdi, 0x50(%rsp)
callq 0xb37c
testl %ebx, %ebx
setg %al
testq %r14, %r14
setne %cl
testb %cl, %al
jne 0xe04e
leaq 0x3b84(%rip), %rdx      # 0x11bb9
xorl %r15d, %r15d
movl $0x3, %edi
movl $0x1, %esi
xorl %eax, %eax
callq 0x46dc
jmp 0xe1c4
movl %r12d, (%rsp)
movl %r15d, 0x4(%rsp)
movl %ebp, 0x8(%rsp)
movq (%r14), %rax
movl 0x10(%rax), %ebp
movl %ebx, 0xc(%rsp)
movl %ebx, %r12d
movl $0x6, %r15d
xorl %r13d, %r13d
movq (%r14,%r13,8), %rax
movl 0x40(%rax), %ebx
movl $0x1, 0x18(%rax)
movq 0x48(%rax), %rax
orb $-0x80, (%rax)
movq (%r14,%r13,8), %rax
cmpl %ebp, 0x10(%rax)
je 0xe0a7
movl $0x2, %edi
movl $0x1, %esi
leaq 0x3ae3(%rip), %rdx      # 0x11b83
xorl %eax, %eax
callq 0x46dc
movq (%r14,%r13,8), %rsi
movq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rdx
leaq 0x58(%rsp), %rcx
callq 0x8c32
testq %r13, %r13
je 0xe135
movsd 0x30(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
minsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
minsd 0x78(%rsp), %xmm1
movsd %xmm1, 0x38(%rsp)
movsd 0x40(%rsp), %xmm0
minsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
maxsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
maxsd 0x60(%rsp), %xmm1
movsd %xmm1, 0x18(%rsp)
movsd 0x20(%rsp), %xmm0
maxsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
jmp 0xe162
movq 0x80(%rsp), %rax
movq %rax, 0x40(%rsp)
movups 0x70(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
movupd 0x58(%rsp), %xmm0
movapd %xmm0, 0x10(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x20(%rsp)
movl %ebx, %eax
shrl $0x1f, %eax
addl %ebx, %eax
sarl %eax
addl %eax, %r15d
incq %r13
cmpq %r13, %r12
jne 0xe071
movq 0x50(%rsp), %rbx
movq %rbx, %rdi
movl (%rsp), %esi
movl 0x4(%rsp), %edx
movl 0x8(%rsp), %ecx
movl %r15d, %r8d
movl 0xc(%rsp), %r9d
callq 0xdeb2
movq %rax, %r15
movq (%r14), %rax
movl 0x10(%rax), %eax
movl %eax, 0x10(%r15)
movq %r15, %rsi
callq 0xc46f
leaq 0x30(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc80f
movq %r15, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq