// File: /workspace/github_cpp_makefile_star2_O1/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 0x1ad0(%rip), %rax      # 0x10400
leaq 0x1acc(%rip), %rsi      # 0x10403
cmoveq %rax, %rsi
callq 0x6f44
testq %rax, %rax
je 0xe9ef
movq %rax, %r15
movq %rsp, %rbx
movl $0x1, %esi
movl $0x200, %edx            # imm = 0x200
movq %rbx, %rdi
movq %rax, %rcx
callq 0x6f5d
movq %rbx, %rdi
movl $0x200, %esi            # imm = 0x200
callq 0xe8c0
testl %eax, %eax
je 0xea0e
movq %r15, %rdi
callq 0x6f58
movl $0x203b8, %edi          # imm = 0x203B8
movl $0x1, %esi
callq 0x2d54
movq %rax, %rbx
movq %r15, (%rax)
xorl %eax, %eax
movl %eax, 0x8(%rbx)
movl %eax, 0x20014(%rbx)
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, 0x20020(%rbx)
movq $0x0, 0x20050(%rbx)
movl %eax, 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 0xea33
leaq 0x32ca(%rip), %rdx      # 0x11cc0
xorl %ebx, %ebx
movl $0x3, %edi
movl $0x4, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x46dc
jmp 0xea33
leaq 0x32d1(%rip), %rdx      # 0x11ce6
xorl %ebx, %ebx
movl $0x3, %edi
movl $0x1, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x46dc
movq %r15, %rdi
callq 0x6f49
movq %rbx, %rax
addq $0x200, %rsp            # imm = 0x200
popq %rbx
popq %r14
popq %r15
retq