// File: rurban[P]dgnlib/dgnread.cpp
// Function: DGNReadElement
DGNElemCore *DGNReadElement( DGNHandle hDGN )

{
    DGNInfo     *psDGN = (DGNInfo *) hDGN;
    DGNElemCore *psElement = NULL;
    int         nType, nLevel;
    int         bInsideFilter;

/* -------------------------------------------------------------------- */
/*      Load the element data into the current buffer.  If a spatial    */
/*      filter is in effect, loop until we get something within our     */
/*      spatial constraints.                                            */
/* -------------------------------------------------------------------- */
    do { 
        bInsideFilter = TRUE;

        if( !DGNLoadRawElement( psDGN, &nType, &nLevel ) )
            return NULL;
        
        if( psDGN->has_spatial_filter )
        {
            GUInt32     nXMin, nXMax, nYMin, nYMax;
            
            if( !psDGN->sf_converted_to_uor )
                DGNSpatialFilterToUOR( psDGN );

            if( !DGNGetRawExtents( psDGN, nType, NULL,
                                   &nXMin, &nYMin, NULL,
                                   &nXMax, &nYMax, NULL ) )
            {
                /* If we don't have spatial characterists for the element
                   we will pass it through. */
                bInsideFilter = TRUE;
            }
            else if( nXMin > psDGN->sf_max_x
                     || nYMin > psDGN->sf_max_y
                     || nXMax < psDGN->sf_min_x
                     || nYMax < psDGN->sf_min_y )
                bInsideFilter = FALSE;

            /*
            ** We want to select complex elements based on the extents of
            ** the header, not the individual elements.
            */
            if( nType == DGNT_COMPLEX_CHAIN_HEADER
                || nType == DGNT_COMPLEX_SHAPE_HEADER )
            {
                psDGN->in_complex_group = TRUE;
                psDGN->select_complex_group = bInsideFilter;
            }
            else if( psDGN->abyElem[0] & 0x80 /* complex flag set */ )
            {
                if( psDGN->in_complex_group )
                    bInsideFilter = psDGN->select_complex_group;
            }
            else
                psDGN->in_complex_group = FALSE;
        }
    } while( !bInsideFilter );

/* -------------------------------------------------------------------- */
/*      Convert into an element structure.                              */
/* -------------------------------------------------------------------- */
    psElement = DGNProcessElement( psDGN, nType, nLevel );

    return psElement;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x1, -0x2c(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x24(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0xcfe0
cmpl $0x0, %eax
jne 0xd626
movq $0x0, -0x8(%rbp)
jmp 0xd76d
movq -0x18(%rbp), %rax
cmpl $0x0, 0x20378(%rax)
je 0xd73f
movq -0x18(%rbp), %rax
cmpl $0x0, 0x2037c(%rax)
jne 0xd64d
movq -0x18(%rbp), %rdi
callq 0x17af0
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
xorl %eax, %eax
movl %eax, %r9d
leaq -0x30(%rbp), %rcx
leaq -0x38(%rbp), %r8
leaq -0x34(%rbp), %r10
leaq -0x3c(%rbp), %rax
movq %r9, %rdx
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
callq 0xd2e0
cmpl $0x0, %eax
jne 0xd691
movl $0x1, -0x2c(%rbp)
jmp 0xd6d6
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x20390(%rcx), %eax
ja 0xd6cd
movl -0x38(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x20394(%rcx), %eax
ja 0xd6cd
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x20388(%rcx), %eax
jb 0xd6cd
movl -0x3c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x2038c(%rcx), %eax
jae 0xd6d4
movl $0x0, -0x2c(%rbp)
jmp 0xd6d6
cmpl $0xc, -0x24(%rbp)
je 0xd6e2
cmpl $0xe, -0x24(%rbp)
jne 0xd6ff
movq -0x18(%rbp), %rax
movl $0x1, 0x20384(%rax)
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x20380(%rax)
jmp 0xd73d
movq -0x18(%rbp), %rax
movzbl 0x10(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0xd72d
movq -0x18(%rbp), %rax
cmpl $0x0, 0x20384(%rax)
je 0xd72b
movq -0x18(%rbp), %rax
movl 0x20380(%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0xd73b
movq -0x18(%rbp), %rax
movl $0x0, 0x20384(%rax)
jmp 0xd73d
jmp 0xd73f
jmp 0xd741
cmpl $0x0, -0x2c(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xd5fc
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
callq 0xd780
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)