// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8408, %rsp           # imm = 0x8408
movq %rsi, -0x30(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
movaps %xmm0, -0xb0(%rbp)
movaps %xmm0, -0xc0(%rbp)
movaps %xmm0, -0xd0(%rbp)
movaps %xmm0, -0xe0(%rbp)
movaps %xmm0, -0xf0(%rbp)
movaps %xmm0, -0x100(%rbp)
leal -0x4(%rdi), %eax
movl %eax, -0x50(%rbp)
movq %rdi, -0x48(%rbp)
leal -0x1(%rdi), %eax
movl %eax, -0x4c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
pushq $0x1
popq %r15
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x3c(%rbp)
movsd %xmm0, -0x60(%rbp)
movsd %xmm0, -0x68(%rbp)
movsd %xmm0, -0x58(%rbp)
xorl %r12d, %r12d
cmpl -0x48(%rbp), %r15d
jge 0x282f
movslq %r15d, %r14
movq -0x30(%rbp), %rax
movq (%rax,%r14,8), %r13
movb (%r13), %bl
cmpb $0x2d, %bl
jne 0x27ed
cmpb $0x73, 0x1(%r13)
jne 0x2736
cmpb $0x0, 0x2(%r13)
je 0x281b
cmpb $0x65, 0x1(%r13)
jne 0x279c
cmpb $0x0, 0x2(%r13)
sete %al
cmpl -0x50(%rbp), %r15d
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x279c
movq -0x30(%rbp), %rbx
movq 0x8(%rbx,%r14,8), %rdi
callq 0x2390
movsd %xmm0, -0x70(%rbp)
movq 0x10(%rbx,%r14,8), %rdi
callq 0x2390
movsd %xmm0, -0x68(%rbp)
movq 0x18(%rbx,%r14,8), %rdi
callq 0x2390
movsd %xmm0, -0x60(%rbp)
addl $0x4, %r15d
movq 0x20(%rbx,%r14,8), %rdi
callq 0x2390
movsd %xmm0, -0x58(%rbp)
jmp 0x2821
cmpb $0x72, 0x1(%r13)
jne 0x27ed
cmpb $0x0, 0x2(%r13)
sete %al
cmpl -0x4c(%rbp), %r15d
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x27ed
incl %r15d
movq -0x30(%rbp), %rax
movq 0x8(%rax,%r14,8), %rdi
callq 0x2480
cmpl $0x7f, %eax
pushq $0x7f
popq %rcx
cmovgel %ecx, %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
movb $0x1, -0x100(%rbp,%rax)
pushq $0x1
popq %rax
movl %eax, -0x34(%rbp)
jmp 0x2821
movq %r13, %rdi
leaq 0xb80d(%rip), %rsi      # 0xe004
callq 0x2400
testl %eax, %eax
je 0x2813
cmpb $0x2d, %bl
je 0x2c18
testq %r12, %r12
je 0x2824
jmp 0x2c18
pushq $0x1
popq %rax
movl %eax, -0x3c(%rbp)
jmp 0x2821
pushq $0x1
popq %rax
movl %eax, -0x38(%rbp)
movq %r12, %r13
incl %r15d
movq %r13, %r12
jmp 0x2702
testq %r12, %r12
je 0x2c18
movq %r12, %rdi
xorl %esi, %esi
callq 0xd464
testq %rax, %rax
je 0x2c1d
movq %rax, %r12
cmpl $0x0, -0x34(%rbp)
je 0x285f
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0xd581
movq %r12, %rdi
movsd -0x70(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
movsd -0x60(%rbp), %xmm2
movsd -0x58(%rbp), %xmm3
callq 0xd588
cmpl $0x0, -0x38(%rbp)
movq %r12, -0x48(%rbp)
je 0x2a8f
leaq -0x130(%rbp), %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0xa583
movsd (%rbx), %xmm0
movsd 0x18(%rbx), %xmm1
leaq 0xb79b(%rip), %rdi      # 0xe046
movb $0x2, %al
callq 0x2050
movsd 0x8(%rbx), %xmm0
movsd 0x20(%rbx), %xmm1
leaq 0xb79a(%rip), %rdi      # 0xe05d
movb $0x2, %al
callq 0x2050
movsd 0x10(%rbx), %xmm0
movsd 0x28(%rbx), %xmm1
leaq 0xb799(%rip), %rdi      # 0xe074
movb $0x2, %al
callq 0x2050
leaq -0x74(%rbp), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0xa557
movq %rax, %rbx
movl (%r15), %esi
leaq 0xb78d(%rip), %rdi      # 0xe08b
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x2050
leaq -0x8430(%rbp), %r14
movl $0x8000, %edx           # imm = 0x8000
movq %r14, %rdi
xorl %esi, %esi
callq 0x2160
leaq -0x430(%rbp), %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x2160
leaq -0x330(%rbp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x2160
movl (%r15), %eax
testl %eax, %eax
cmovlel %r12d, %eax
shlq $0x4, %rax
cmpq %r12, %rax
je 0x2981
movzbl (%rbx,%r12), %ecx
movzbl 0x1(%rbx,%r12), %edx
incl -0x430(%rbp,%rcx,4)
shll $0x7, %ecx
addl %edx, %ecx
incl -0x8430(%rbp,%rcx,4)
incl -0x330(%rbp,%rdx,4)
addq $0x10, %r12
jmp 0x2951
pushq $0xa
popq %rdi
callq 0x23f0
leaq 0xb758(%rip), %rdi      # 0xe0e8
callq 0x2460
leaq 0xb76e(%rip), %rdi      # 0xe10a
callq 0x2460
leaq 0xb711(%rip), %rbx      # 0xe0b9
xorl %r15d, %r15d
cmpq $0x80, %r15
je 0x29de
movl -0x330(%rbp,%r15,4), %r12d
testl %r12d, %r12d
je 0x29d9
movl %r15d, %edi
callq 0x7d82
movq %rbx, %rdi
movq %rax, %rsi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2050
incq %r15
jmp 0x29ab
pushq $0xa
popq %rdi
callq 0x23f0
leaq 0xb70b(%rip), %rdi      # 0xe0f8
callq 0x2460
leaq 0xb710(%rip), %rdi      # 0xe109
callq 0x2460
leaq 0xb6b2(%rip), %r12      # 0xe0b7
xorl %r13d, %r13d
cmpq $0x40, %r13
je 0x2a6f
movl -0x430(%rbp,%r13,4), %edx
testl %edx, %edx
je 0x2a63
leaq 0xb67e(%rip), %rdi      # 0xe09f
movl %r13d, %esi
xorl %eax, %eax
callq 0x2050
xorl %ebx, %ebx
cmpq $0x80, %rbx
je 0x2a5b
movl (%r14,%rbx,4), %r15d
testl %r15d, %r15d
je 0x2a56
movl %ebx, %edi
callq 0x7d82
movq %r12, %rdi
movq %rax, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x2050
incq %rbx
jmp 0x2a2d
pushq $0xa
popq %rdi
callq 0x23f0
incq %r13
addq $0x200, %r14            # imm = 0x200
jmp 0x2a08
movq -0x48(%rbp), %r12
movq %r12, %rdi
callq 0xd6c6
xorl %eax, %eax
addq $0x8408, %rsp           # imm = 0x8408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x12532(%rip), %rbx     # 0x14fc8
leaq -0x8430(%rbp), %r14
leaq -0x330(%rbp), %r15
movq %r12, %rdi
callq 0x8731
testq %rax, %rax
je 0x2a73
movq %rax, %r13
movq (%rbx), %rdx
movq %r12, %rdi
movq %rax, %rsi
callq 0x6f89
movslq 0x14(%r13), %rax
cmpb $0x0, -0x100(%rbp,%rax)
je 0x2baf
movq (%rbx), %rdi
movl 0x40(%r13), %edx
xorl %r12d, %r12d
movq %rdi, -0x30(%rbp)
leaq 0xb5dd(%rip), %rsi      # 0xe0c6
xorl %eax, %eax
callq 0x2410
xorl %ebx, %ebx
movslq 0x40(%r13), %rax
cmpq %rax, %r12
jge 0x2ba4
testb $0xf, %r12b
jne 0x2b22
xorl %ebx, %ebx
movq %r14, %rdi
leaq 0xb5cd(%rip), %rsi      # 0xe0de
movl %r12d, %edx
leaq 0xc16a(%rip), %rcx      # 0xec85
xorl %eax, %eax
callq 0x20a0
movq 0x48(%r13), %rax
movzbl (%rax,%r12), %edx
movq %r15, %rdi
leaq 0xc918(%rip), %rsi      # 0xf44d
xorl %eax, %eax
callq 0x20a0
leal (%rbx,%rbx), %eax
movslq %eax, %rdi
leaq -0x8428(%rbp), %rax
addq %rax, %rdi
movq %r15, %rsi
pushq $0x2
popq %rdx
callq 0x2150
movq 0x48(%r13), %rax
movzbl (%rax,%r12), %eax
cmpb $0x20, %al
movslq %ebx, %rcx
pushq $0x2e
popq %rdx
cmovll %edx, %eax
movb %al, 0x2a(%rcx,%r14)
movl 0x40(%r13), %eax
decl %eax
cmpq %rax, %r12
je 0x2b85
leal 0x1(%r12), %eax
andl $0xf, %eax
jne 0x2b9a
movq -0x30(%rbp), %rdi
leaq 0xb9fe(%rip), %rsi      # 0xe58e
movq %r14, %rdx
xorl %eax, %eax
callq 0x2410
incl %ebx
incq %r12
jmp 0x2af2
movq -0x48(%rbp), %r12
movq 0x12419(%rip), %rbx     # 0x14fc8
cmpl $0x0, -0x3c(%rbp)
je 0x2c08
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x84ea
testl %eax, %eax
je 0x2c08
movsd -0x8430(%rbp), %xmm0
movsd -0x8428(%rbp), %xmm1
movsd -0x8420(%rbp), %xmm2
movsd -0x330(%rbp), %xmm3
movsd -0x328(%rbp), %xmm4
movsd -0x320(%rbp), %xmm5
leaq 0xb40c(%rip), %rdi      # 0xe00d
movb $0x6, %al
callq 0x2050
movq %r12, %rdi
movq %r13, %rsi
callq 0xa2bd
jmp 0x2aa4
callq 0x2c25
pushq $0x1
popq %rdi
callq 0x2370