// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movl $0x6, -0x2c(%rbp)
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2170
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2170
movq -0x10(%rbp), %rdi
callq 0x11190
cmpl $0x1, -0x20(%rbp)
jl 0x166fd
cmpq $0x0, -0x28(%rbp)
jne 0x16722
movl $0x3, %edi
movl $0x1, %esi
leaq 0x4137(%rip), %rdx      # 0x1a845
movb $0x0, %al
callq 0x5740
movq $0x0, -0x8(%rbp)
jmp 0x16a08
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl 0x10(%rax), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x16995
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x40(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x1, 0x18(%rax)
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x48(%rax), %rax
movzbl (%rax), %ecx
orl $0x80, %ecx
movb %cl, (%rax)
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x10(%rax), %eax
cmpl -0x34(%rbp), %eax
je 0x167b9
movl $0x2, %edi
movl $0x1, %esi
leaq 0x405d(%rip), %rdx      # 0x1a80f
movb $0x0, %al
callq 0x5740
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x88(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
callq 0xd100
cmpl $0x0, -0x30(%rbp)
jne 0x16823
movq -0x88(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x16985
movsd -0x58(%rbp), %xmm1
movsd -0x88(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x16845
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
jmp 0x16855
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x50(%rbp), %xmm1
movsd -0x80(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x16881
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
jmp 0x1688e
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x48(%rbp), %xmm1
movsd -0x78(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x168ba
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
jmp 0x168c7
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x70(%rbp), %xmm0
ucomisd -0xa0(%rbp), %xmm0
jbe 0x168f2
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
jmp 0x16902
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x68(%rbp), %xmm0
ucomisd -0x98(%rbp), %xmm0
jbe 0x1692d
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
jmp 0x1693d
movsd -0x98(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0xc8(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x60(%rbp), %xmm0
ucomisd -0x90(%rbp), %xmm0
jbe 0x16968
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
jmp 0x16978
movsd -0x90(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0x16987
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x16736
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl -0x2c(%rbp), %r8d
movl -0x20(%rbp), %r9d
callq 0x16500
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl 0x10(%rax), %edx
movq -0x40(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x40(%rbp), %rax
movl 0x28(%rax), %r8d
movq -0x40(%rbp), %rax
movl 0x2c(%rax), %r9d
movq -0x40(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, (%rsp)
callq 0x12ee0
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
leaq -0x58(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x13630
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)