// File: /workspace/github_cpp_makefile_star2_O3/rurban[P]dgnlib/dgnopen.cpp
// Function: DGNOpen
DGNHandle DGNOpen( const char * pszFilename, int bUpdate )

{
    DGNInfo     *psDGN;
    FILE        *fp;

/* -------------------------------------------------------------------- */
/*      Open the file.                                                  */
/* -------------------------------------------------------------------- */
    if( bUpdate )
        fp = VSIFOpen( pszFilename, "rb+" );
    else
        fp = VSIFOpen( pszFilename, "rb" );
    if( fp == NULL )
    {
        CPLError( CE_Failure, CPLE_OpenFailed, 
                  "Unable to open `%s' for read access.\n", 
                  pszFilename );
        return NULL;
    }

/* -------------------------------------------------------------------- */
/*      Verify the format ... add later.                                */
/* -------------------------------------------------------------------- */
    GByte       abyHeader[512];

    VSIFRead( abyHeader, 1, sizeof(abyHeader), fp );
    if( !DGNTestOpen( abyHeader, sizeof(abyHeader) ) )
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "File `%s' does not have expected DGN header.\n", 
                  pszFilename );
        VSIFClose( fp );
        return NULL;
    }

    VSIRewind( fp );

/* -------------------------------------------------------------------- */
/*      Create the info structure.                                      */
/* -------------------------------------------------------------------- */
    psDGN = (DGNInfo *) CPLCalloc(sizeof(DGNInfo),1);
    psDGN->fp = fp;
    psDGN->next_element_id = 0;

    psDGN->got_tcb = FALSE;
    psDGN->scale = 1.0;
    psDGN->origin_x = 0.0;
    psDGN->origin_y = 0.0;
    psDGN->origin_z = 0.0;                                             

    psDGN->index_built = FALSE;
    psDGN->element_count = 0;
    psDGN->element_index = NULL;

    psDGN->got_bounds = FALSE;

    if( abyHeader[0] == 0xC8 )
        psDGN->dimension = 3;
    else
        psDGN->dimension = 2;

    psDGN->has_spatial_filter = FALSE;
    psDGN->sf_converted_to_uor = FALSE;
    psDGN->select_complex_group = FALSE;
    psDGN->in_complex_group = FALSE;

    return (DGNHandle) psDGN;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x200, %rsp            # imm = 0x200
movq %rdi, %rbx
testl %esi, %esi
leaq 0x1332(%rip), %rax      # 0xf420
leaq 0x132e(%rip), %rsi      # 0xf423
cmoveq %rax, %rsi
callq 0x6e04
testq %rax, %rax
je 0xe138
movq %rax, %r14
movq %rsp, %r15
movl $0x1, %esi
movl $0x200, %edx            # imm = 0x200
movq %r15, %rdi
movq %rax, %rcx
callq 0x6e1d
movzbl (%r15), %eax
cmpl $0x8, %eax
je 0xe15b
cmpl $0xc8, %eax
jne 0xe211
movb 0x1(%rsp), %al
jmp 0xe17a
leaq 0x2c41(%rip), %rdx      # 0x10d80
xorl %r15d, %r15d
movl $0x3, %edi
movl $0x4, %esi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x460c
jmp 0xe237
movb 0x1(%rsp), %al
cmpb $0x5, %al
jne 0xe17a
cmpb $0x17, 0x2(%rsp)
jne 0xe211
cmpb $0x0, 0x3(%rsp)
je 0xe194
jmp 0xe211
cmpb $0x9, %al
jne 0xe211
cmpb $-0x2, 0x2(%rsp)
jne 0xe211
cmpb $0x2, 0x3(%rsp)
jne 0xe211
movq %r14, %rdi
callq 0x6e18
movl $0x203b8, %edi          # imm = 0x203B8
movl $0x1, %esi
callq 0x2d20
movq %rax, %r15
movq %r14, (%rax)
xorl %eax, %eax
movl %eax, 0x8(%r15)
movl %eax, 0x20014(%r15)
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, 0x20020(%r15)
movq $0x0, 0x20050(%r15)
movl %eax, 0x2035c(%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x20028(%r15)
movups %xmm0, 0x20038(%r15)
xorl %eax, %eax
cmpb $-0x38, (%rsp)
sete %al
orl $0x2, %eax
movl %eax, 0x20018(%r15)
movups %xmm0, 0x20378(%r15)
jmp 0xe237
leaq 0x2b8e(%rip), %rdx      # 0x10da6
xorl %r15d, %r15d
movl $0x3, %edi
movl $0x1, %esi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x460c
movq %r14, %rdi
callq 0x6e09
movq %r15, %rax
addq $0x200, %rsp            # imm = 0x200
popq %rbx
popq %r14
popq %r15
retq