// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
testl %esi, %esi
leaq 0xfa4(%rip), %rax       # 0xe420
leaq 0xfa0(%rip), %rsi       # 0xe423
cmoveq %rax, %rsi
callq 0x6970
testq %rax, %rax
je 0xd535
movq %rax, %r15
movq %rsp, %rbx
pushq $0x1
popq %rsi
movl $0x200, %edx            # imm = 0x200
movq %rbx, %rdi
movq %rax, %rcx
callq 0x6989
movq %rbx, %rdi
movl $0x200, %esi            # imm = 0x200
callq 0xd414
testl %eax, %eax
je 0xd550
movq %r15, %rdi
callq 0x6984
pushq $0x1
popq %rsi
movl $0x203b8, %edi          # imm = 0x203B8
callq 0x2c6c
movq %rax, %rbx
movq %r15, (%rax)
andl $0x0, 0x8(%rax)
andl $0x0, 0x20014(%rax)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x20020(%rbx)
andq $0x0, 0x20050(%rbx)
andl $0x0, 0x2035c(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x20028(%rbx)
movups %xmm0, 0x20038(%rbx)
xorl %eax, %eax
cmpb $-0x38, (%rsp)
sete %al
orl $0x2, %eax
movl %eax, 0x20018(%rbx)
movups %xmm0, 0x20378(%rbx)
jmp 0xd571
leaq 0x2854(%rip), %rdx      # 0xfd90
xorl %ebx, %ebx
pushq $0x3
popq %rdi
pushq $0x4
popq %rsi
movq %r14, %rcx
xorl %eax, %eax
callq 0x439c
jmp 0xd571
leaq 0x285f(%rip), %rdx      # 0xfdb6
xorl %ebx, %ebx
pushq $0x3
popq %rdi
pushq $0x1
popq %rsi
movq %r14, %rcx
xorl %eax, %eax
callq 0x439c
movq %r15, %rdi
callq 0x6975
movq %rbx, %rax
addq $0x200, %rsp            # imm = 0x200
popq %rbx
popq %r14
popq %r15
retq