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

{
    int         nTotalLength = 5;
    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 complex group." );
        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 complex header.                        */
/* -------------------------------------------------------------------- */
    psCH = DGNCreateComplexHeaderElem( hDGN, nType, 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 %rcx, %r14
movl %edx, %ebx
movl %esi, %ebp
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
movapd %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movq %rdi, 0x48(%rsp)
callq 0xa500
testl %ebx, %ebx
setg %al
testq %r14, %r14
setne %cl
testb %cl, %al
jne 0xc941
leaq 0x32e4(%rip), %rdx      # 0xfc10
xorl %r15d, %r15d
pushq $0x3
popq %rdi
pushq $0x1
popq %rsi
xorl %eax, %eax
callq 0x439c
jmp 0xca80
movl %ebp, 0x8(%rsp)
movq (%r14), %rax
movl 0x10(%rax), %ebp
movl %ebx, 0xc(%rsp)
movl %ebx, %r13d
pushq $0x5
popq %r12
xorl %ebx, %ebx
cmpq %rbx, %r13
je 0xca3e
movq (%r14,%rbx,8), %rcx
movl 0x40(%rcx), %eax
cltd
pushq $0x2
popq %rsi
idivl %esi
movl %eax, %r15d
movl $0x1, 0x18(%rcx)
movq 0x48(%rcx), %rax
orb $-0x80, (%rax)
movq (%r14,%rbx,8), %rsi
cmpl %ebp, 0x10(%rsi)
je 0xc9a0
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
leaq 0x32ae(%rip), %rdx      # 0xfc43
xorl %eax, %eax
callq 0x439c
movq (%r14,%rbx,8), %rsi
movq 0x48(%rsp), %rdi
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rcx
callq 0x84ea
testq %rbx, %rbx
je 0xca06
movapd 0x30(%rsp), %xmm0
minpd 0x70(%rsp), %xmm0
movapd %xmm0, 0x30(%rsp)
movsd 0x40(%rsp), %xmm0
minsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movapd 0x10(%rsp), %xmm0
maxpd 0x50(%rsp), %xmm0
movapd %xmm0, 0x10(%rsp)
movsd 0x20(%rsp), %xmm0
maxsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
jmp 0xca33
movq 0x80(%rsp), %rax
movq %rax, 0x40(%rsp)
movaps 0x70(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
movapd 0x50(%rsp), %xmm0
movapd %xmm0, 0x10(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x20(%rsp)
addl %r15d, %r12d
incq %rbx
jmp 0xc958
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
movl 0x8(%rsp), %esi
movl %r12d, %edx
movl 0xc(%rsp), %ecx
callq 0xc6d0
movq %rax, %r15
movq (%r14), %rax
movl 0x10(%rax), %eax
movl %eax, 0x10(%r15)
movq %r15, %rsi
callq 0xb380
leaq 0x30(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xb6bf
movq %r15, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq