// File: rurban[P]dgnlib/dgndump.c
// Function: main
int main( int argc, char ** argv )

{
    DGNHandle   hDGN;
    DGNElemCore *psElement;
    const char  *pszFilename = NULL;
    int         bSummary = FALSE, iArg, bRaw = FALSE, bReportExtents = FALSE;
    char        achRaw[128];
    double      dfSFXMin=0.0, dfSFXMax=0.0, dfSFYMin=0.0, dfSFYMax=0.0;

    memset( achRaw, 0, 128 );

    for( iArg = 1; iArg < argc; iArg++ )
    {
        if( strcmp(argv[iArg],"-s") == 0 )
        {
            bSummary = TRUE;
        }
        else if( strcmp(argv[iArg],"-e") == 0 && iArg < argc-4 )
        {
            dfSFXMin = atof(argv[iArg+1]);
            dfSFYMin = atof(argv[iArg+2]);
            dfSFXMax = atof(argv[iArg+3]);
            dfSFYMax = atof(argv[iArg+4]);
            iArg += 4;
        }
        else if( strcmp(argv[iArg],"-r") == 0 && iArg < argc-1 )
        {
            achRaw[MAX(0,MIN(127,atoi(argv[iArg+1])))] = 1;
            bRaw = TRUE;
            iArg++;
        }
        else if( strcmp(argv[iArg],"-extents") == 0 )
        {
            bReportExtents = TRUE;
        }
        else if( argv[iArg][0] == '-' || pszFilename != NULL )
            Usage();
        else 
            pszFilename = argv[iArg];
    }

    if( pszFilename == NULL )
        Usage();

    hDGN = DGNOpen( pszFilename, FALSE );
    if( hDGN == NULL )
        exit( 1 );

    if( bRaw )
        DGNSetOptions( hDGN, DGNO_CAPTURE_RAW_DATA );

    DGNSetSpatialFilter( hDGN, dfSFXMin, dfSFYMin, dfSFXMax, dfSFYMax );

    if( !bSummary )
    {
        while( (psElement=DGNReadElement(hDGN)) != NULL )
        {
            DGNDumpElement( hDGN, psElement, stdout );

            CPLAssert( psElement->type >= 0 && psElement->type < 128 );

            if( achRaw[psElement->type] != 0 )
                DGNDumpRawElement( hDGN, psElement, stdout );

            if( bReportExtents )
            {
                DGNPoint sMin, sMax;
                if( DGNGetElementExtents( hDGN, psElement, &sMin, &sMax ) )
                    printf( "  Extents: (%.6f,%.6f,%.6f)\n"
                            "        to (%.6f,%.6f,%.6f)\n",
                            sMin.x, sMin.y, sMin.z, 
                            sMax.x, sMax.y, sMax.z );
            }

            DGNFreeElement( hDGN, psElement );
        }
    }
    else
    {
        const DGNElementInfo    *pasEI;
        int                     nCount, i, nLevel, nType;
        int                     anLevelTypeCount[128*64];
        int                     anLevelCount[64];
        int                     anTypeCount[128];
        double                  adfExtents[6];

        DGNGetExtents( hDGN, adfExtents );
        printf( "X Range: %.2f to %.2f\n", 
                adfExtents[0], adfExtents[3] );
        printf( "Y Range: %.2f to %.2f\n", 
                adfExtents[1], adfExtents[4] );
        printf( "Z Range: %.2f to %.2f\n", 
                adfExtents[2], adfExtents[5] );

        pasEI = DGNGetElementIndex( hDGN, &nCount );

        printf( "Total Elements: %d\n", nCount );
        
        memset( anLevelTypeCount, 0, 128*64*sizeof(int) );
        memset( anLevelCount, 0, 64*sizeof(int) );
        memset( anTypeCount, 0, 128*sizeof(int) );

        for( i = 0; i < nCount; i++ )
        {
            anLevelTypeCount[pasEI[i].level * 128 + pasEI[i].type]++;
            anLevelCount[pasEI[i].level]++;
            anTypeCount[pasEI[i].type]++;
        }

        printf( "\n" );
        printf( "Per Type Report\n" );
        printf( "===============\n" );

        for( nType = 0; nType < 128; nType++ )
        {
            if( anTypeCount[nType] != 0 )
            {
                printf( "Type %s: %d\n", 
                        DGNTypeToName( nType ), 
                        anTypeCount[nType] );
            }
        }

        printf( "\n" );
        printf( "Per Level Report\n" );
        printf( "================\n" );

        for( nLevel = 0; nLevel < 64; nLevel++ )
        {
            if( anLevelCount[nLevel] == 0 )
                continue;

            printf( "Level %d, %d elements:\n", 
                    nLevel, 
                    anLevelCount[nLevel] );

            for( nType = 0; nType < 128; nType++ )
            {
                if( anLevelTypeCount[nLevel * 128 + nType] != 0 )
                {
                    printf( "  Type %s: %d\n", 
                            DGNTypeToName( nType ), 
                            anLevelTypeCount[nLevel*128 + nType] );
                }
            }

            printf( "\n" );
        }
    }

    DGNClose( hDGN );

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8470, %rsp           # imm = 0x8470
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xc8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xd0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xd8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xe0(%rbp)
leaq -0xc0(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x2170
movl $0x1, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x2943
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x16909(%rip), %rsi     # 0x19004
callq 0x2400
cmpl $0x0, %eax
jne 0x2711
movl $0x1, -0x2c(%rbp)
jmp 0x2933
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x168e3(%rip), %rsi     # 0x19007
callq 0x2400
cmpl $0x0, %eax
jne 0x27c9
movl -0x30(%rbp), %eax
movl -0x8(%rbp), %ecx
subl $0x4, %ecx
cmpl %ecx, %eax
jge 0x27c9
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x23a0
movsd %xmm0, -0xc8(%rbp)
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x23a0
movsd %xmm0, -0xd8(%rbp)
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x23a0
movsd %xmm0, -0xd0(%rbp)
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x4, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x23a0
movsd %xmm0, -0xe0(%rbp)
movl -0x30(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x30(%rbp)
jmp 0x2931
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x1682e(%rip), %rsi     # 0x1900a
callq 0x2400
cmpl $0x0, %eax
jne 0x28d3
movl -0x30(%rbp), %eax
movl -0x8(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x28d3
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2470
movl %eax, %ecx
movl $0x7f, %eax
cmpl %ecx, %eax
jge 0x2829
movl $0x7f, %eax
movl %eax, -0x8464(%rbp)
jmp 0x2845
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2470
movl %eax, -0x8464(%rbp)
movl -0x8464(%rbp), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jle 0x285b
xorl %eax, %eax
movl %eax, -0x8468(%rbp)
jmp 0x28b1
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2470
movl %eax, %ecx
movl $0x7f, %eax
cmpl %ecx, %eax
jge 0x2889
movl $0x7f, %eax
movl %eax, -0x846c(%rbp)
jmp 0x28a5
movq -0x10(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2470
movl %eax, -0x846c(%rbp)
movl -0x846c(%rbp), %eax
movl %eax, -0x8468(%rbp)
movl -0x8468(%rbp), %eax
cltq
movb $0x1, -0xc0(%rbp,%rax)
movl $0x1, -0x34(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x292f
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x16727(%rip), %rsi     # 0x1900d
callq 0x2400
cmpl $0x0, %eax
jne 0x28f9
movl $0x1, -0x38(%rbp)
jmp 0x292d
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x2914
cmpq $0x0, -0x28(%rbp)
je 0x291b
callq 0x2de0
jmp 0x292b
movq -0x10(%rbp), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
jmp 0x292d
jmp 0x292f
jmp 0x2931
jmp 0x2933
jmp 0x2935
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x26dc
cmpq $0x0, -0x28(%rbp)
jne 0x294f
callq 0x2de0
movq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x177c0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x296f
movl $0x1, %edi
callq 0x2380
cmpl $0x0, -0x34(%rbp)
je 0x2983
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x179d0
movq -0x18(%rbp), %rdi
movsd -0xc8(%rbp), %xmm0
movsd -0xd8(%rbp), %xmm1
movsd -0xd0(%rbp), %xmm2
movsd -0xe0(%rbp), %xmm3
callq 0x17a00
cmpl $0x0, -0x2c(%rbp)
jne 0x2a8f
jmp 0x29b8
movq -0x18(%rbp), %rdi
callq 0xd5e0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x2a8a
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq 0x1c5ea(%rip), %rax     # 0x1efc8
movq (%rax), %rdx
callq 0xadc0
movq -0x20(%rbp), %rax
movslq 0x14(%rax), %rax
movsbl -0xc0(%rbp,%rax), %eax
cmpl $0x0, %eax
je 0x2a12
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq 0x1c5be(%rip), %rax     # 0x1efc8
movq (%rax), %rdx
callq 0x2e40
cmpl $0x0, -0x38(%rbp)
je 0x2a78
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
leaq -0x110(%rbp), %rcx
callq 0xd100
cmpl $0x0, %eax
je 0x2a76
movsd -0xf8(%rbp), %xmm0
movsd -0xf0(%rbp), %xmm1
movsd -0xe8(%rbp), %xmm2
movsd -0x110(%rbp), %xmm3
movsd -0x108(%rbp), %xmm4
movsd -0x100(%rbp), %xmm5
leaq 0x165a7(%rip), %rdi     # 0x19016
movb $0x6, %al
callq 0x2050
jmp 0x2a78
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x10be0
jmp 0x29b8
jmp 0x2dcc
movq -0x18(%rbp), %rdi
leaq -0x8460(%rbp), %rsi
callq 0x11280
movsd -0x8460(%rbp), %xmm0
movsd -0x8448(%rbp), %xmm1
leaq 0x16599(%rip), %rdi     # 0x1904f
movb $0x2, %al
callq 0x2050
movsd -0x8458(%rbp), %xmm0
movsd -0x8440(%rbp), %xmm1
leaq 0x16592(%rip), %rdi     # 0x19066
movb $0x2, %al
callq 0x2050
movsd -0x8450(%rbp), %xmm0
movsd -0x8438(%rbp), %xmm1
leaq 0x1658b(%rip), %rdi     # 0x1907d
movb $0x2, %al
callq 0x2050
movq -0x18(%rbp), %rdi
leaq -0x11c(%rbp), %rsi
callq 0x11230
movq %rax, -0x118(%rbp)
movl -0x11c(%rbp), %esi
leaq 0x16577(%rip), %rdi     # 0x19094
movb $0x0, %al
callq 0x2050
leaq -0x8130(%rbp), %rdi
xorl %esi, %esi
movl $0x8000, %edx           # imm = 0x8000
callq 0x2170
leaq -0x8230(%rbp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x2170
leaq -0x8430(%rbp), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x2170
movl $0x0, -0x120(%rbp)
movl -0x120(%rbp), %eax
cmpl -0x11c(%rbp), %eax
jge 0x2c29
movq -0x118(%rbp), %rax
movslq -0x120(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzbl (%rax), %eax
shll $0x7, %eax
movq -0x118(%rbp), %rcx
movslq -0x120(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movzbl 0x1(%rcx), %ecx
addl %ecx, %eax
cltq
movl -0x8130(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x8130(%rbp,%rax,4)
movq -0x118(%rbp), %rax
movslq -0x120(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzbl (%rax), %eax
movl -0x8230(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x8230(%rbp,%rax,4)
movq -0x118(%rbp), %rax
movslq -0x120(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzbl 0x1(%rax), %eax
movl -0x8430(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x8430(%rbp,%rax,4)
movl -0x120(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x120(%rbp)
jmp 0x2b67
leaq 0x17053(%rip), %rdi     # 0x19c83
movb $0x0, %al
callq 0x2050
leaq 0x1646a(%rip), %rdi     # 0x190a8
movb $0x0, %al
callq 0x2050
leaq 0x16480(%rip), %rdi     # 0x190cc
movb $0x0, %al
callq 0x2050
movl $0x0, -0x128(%rbp)
cmpl $0x80, -0x128(%rbp)
jge 0x2cb7
movslq -0x128(%rbp), %rax
cmpl $0x0, -0x8430(%rbp,%rax,4)
je 0x2ca4
movl -0x128(%rbp), %edi
callq 0xc2d0
movq %rax, %rsi
movslq -0x128(%rbp), %rax
movl -0x8430(%rbp,%rax,4), %edx
leaq 0x1645a(%rip), %rdi     # 0x190f7
movb $0x0, %al
callq 0x2050
jmp 0x2ca6
movl -0x128(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x128(%rbp)
jmp 0x2c5d
leaq 0x16fc5(%rip), %rdi     # 0x19c83
movb $0x0, %al
callq 0x2050
leaq 0x163ed(%rip), %rdi     # 0x190b9
movb $0x0, %al
callq 0x2050
leaq 0x163f1(%rip), %rdi     # 0x190cb
movb $0x0, %al
callq 0x2050
movl $0x0, -0x124(%rbp)
cmpl $0x40, -0x124(%rbp)
jge 0x2dca
movslq -0x124(%rbp), %rax
cmpl $0x0, -0x8230(%rbp,%rax,4)
jne 0x2d0e
jmp 0x2db6
movl -0x124(%rbp), %esi
movslq -0x124(%rbp), %rax
movl -0x8230(%rbp,%rax,4), %edx
leaq 0x163b4(%rip), %rdi     # 0x190dd
movb $0x0, %al
callq 0x2050
movl $0x0, -0x128(%rbp)
cmpl $0x80, -0x128(%rbp)
jge 0x2da8
movl -0x124(%rbp), %eax
shll $0x7, %eax
addl -0x128(%rbp), %eax
cltq
cmpl $0x0, -0x8130(%rbp,%rax,4)
je 0x2d95
movl -0x128(%rbp), %edi
callq 0xc2d0
movq %rax, %rsi
movl -0x124(%rbp), %eax
shll $0x7, %eax
addl -0x128(%rbp), %eax
cltq
movl -0x8130(%rbp,%rax,4), %edx
leaq 0x16367(%rip), %rdi     # 0x190f5
movb $0x0, %al
callq 0x2050
jmp 0x2d97
movl -0x128(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x128(%rbp)
jmp 0x2d3a
leaq 0x16ed4(%rip), %rdi     # 0x19c83
movb $0x0, %al
callq 0x2050
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x2ceb
jmp 0x2dcc
movq -0x18(%rbp), %rdi
callq 0x17c20
xorl %eax, %eax
addq $0x8470, %rsp           # imm = 0x8470
popq %rbp
retq