// File: /workspace/github_cpp_makefile_star2_O2/rurban[P]dgnlib/dgnread.cpp
// Function: DGNParseTCB(DGNInfo*)
static DGNElemCore *DGNParseTCB( DGNInfo * psDGN )

{
    DGNElemTCB *psTCB;
    DGNElemCore *psElement;
    int iView;

    psTCB = (DGNElemTCB *) CPLCalloc(sizeof(DGNElemTCB),1);
    psElement = (DGNElemCore *) psTCB;
    psElement->stype = DGNST_TCB;
    DGNParseCore( psDGN, psElement );

    if( psDGN->abyElem[1214] & 0x40 )
        psTCB->dimension = 3;
    else
        psTCB->dimension = 2;
          
    psTCB->subunits_per_master = DGN_INT32( psDGN->abyElem + 1112 );

    psTCB->master_units[0] = (char) psDGN->abyElem[1120];
    psTCB->master_units[1] = (char) psDGN->abyElem[1121];
    psTCB->master_units[2] = '\0';

    psTCB->uor_per_subunit = DGN_INT32( psDGN->abyElem + 1116 );

    psTCB->sub_units[0] = (char) psDGN->abyElem[1122];
    psTCB->sub_units[1] = (char) psDGN->abyElem[1123];
    psTCB->sub_units[2] = '\0';

    /* Get global origin */
    memcpy( &(psTCB->origin_x), psDGN->abyElem+1240, 8 );
    memcpy( &(psTCB->origin_y), psDGN->abyElem+1248, 8 );
    memcpy( &(psTCB->origin_z), psDGN->abyElem+1256, 8 );

    /* Transform to IEEE */
    DGN2IEEEDouble( &(psTCB->origin_x) );
    DGN2IEEEDouble( &(psTCB->origin_y) );
    DGN2IEEEDouble( &(psTCB->origin_z) );

    /* Convert from UORs to master units. */
    if( psTCB->uor_per_subunit != 0
        && psTCB->subunits_per_master != 0 )
    {
        psTCB->origin_x = psTCB->origin_x / 
            (psTCB->uor_per_subunit * psTCB->subunits_per_master);
        psTCB->origin_y = psTCB->origin_y / 
            (psTCB->uor_per_subunit * psTCB->subunits_per_master);
        psTCB->origin_z = psTCB->origin_z / 
            (psTCB->uor_per_subunit * psTCB->subunits_per_master);
    }

    if( !psDGN->got_tcb )
    {
        psDGN->got_tcb = TRUE;
        psDGN->dimension = psTCB->dimension;
        psDGN->origin_x = psTCB->origin_x;
        psDGN->origin_y = psTCB->origin_y;
        psDGN->origin_z = psTCB->origin_z;

        if( psTCB->uor_per_subunit != 0
            && psTCB->subunits_per_master != 0 )
            psDGN->scale = 1.0 
                / (psTCB->uor_per_subunit * psTCB->subunits_per_master);
    }

    /* Collect views */
    for( iView = 0; iView < 8; iView++ )
    {
        unsigned char *pabyRawView = psDGN->abyElem + 46 + iView*118;
        DGNViewInfo *psView = psTCB->views + iView;
        int i;

        psView->flags = pabyRawView[0] + pabyRawView[1] * 256;
        memcpy( psView->levels, pabyRawView + 2, 8 );
        
        psView->origin.x = DGN_INT32( pabyRawView + 10 );
        psView->origin.y = DGN_INT32( pabyRawView + 14 );
        psView->origin.z = DGN_INT32( pabyRawView + 18 );

        DGNTransformPoint( psDGN, &(psView->origin) );

        psView->delta.x = DGN_INT32( pabyRawView + 22 );
        psView->delta.y = DGN_INT32( pabyRawView + 26 );
        psView->delta.z = DGN_INT32( pabyRawView + 30 );

        psView->delta.x *= psDGN->scale;
        psView->delta.y *= psDGN->scale;
        psView->delta.z *= psDGN->scale;

        memcpy( psView->transmatrx, pabyRawView + 34, sizeof(double) * 9 );
        for( i = 0; i < 9; i++ )
            DGN2IEEEDouble( psView->transmatrx + i );

        memcpy( &(psView->conversion), pabyRawView + 106, sizeof(double) );
        DGN2IEEEDouble( &(psView->conversion) );

        psView->activez = DGN_INT32( pabyRawView + 114 );
    }

    return psElement;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
pushq $0x1
popq %rsi
movl $0x550, %edi            # imm = 0x550
callq 0x2c6c
movq %rax, %r14
movl $0x4, 0xc(%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0xa1c3
movb 0x4ce(%rbx), %al
andb $0x40, %al
cmpb $0x1, %al
pushq $0x3
popq %rax
sbbl $0x0, %eax
movl %eax, 0x50(%r14)
movzwl 0x46a(%rbx), %eax
movzbl 0x469(%rbx), %ecx
shll $0x18, %ecx
orq %rax, %rcx
movzbl 0x468(%rbx), %eax
shll $0x10, %eax
orq %rcx, %rax
movq %rax, 0x80(%r14)
movb 0x470(%rbx), %al
movb %al, 0x88(%r14)
movb 0x471(%rbx), %al
movb %al, 0x89(%r14)
xorl %eax, %eax
movb %al, 0x8a(%r14)
movzwl 0x46e(%rbx), %ecx
movzbl 0x46d(%rbx), %edx
shll $0x18, %edx
orq %rcx, %rdx
movzbl 0x46c(%rbx), %ecx
shll $0x10, %ecx
orq %rdx, %rcx
movq %rcx, 0x70(%r14)
movb 0x472(%rbx), %cl
movb %cl, 0x78(%r14)
movb 0x473(%rbx), %cl
movb %cl, 0x79(%r14)
movb %al, 0x7a(%r14)
leaq 0x58(%r14), %r15
movq 0x4e8(%rbx), %rax
movq %rax, 0x58(%r14)
leaq 0x60(%r14), %r13
movq 0x4f0(%rbx), %rax
movq %rax, 0x60(%r14)
leaq 0x68(%r14), %r12
movq 0x4f8(%rbx), %rax
movq %rax, 0x68(%r14)
movq %r15, %rdi
callq 0x6adc
movq %r13, %rdi
callq 0x6adc
movq %r12, %rdi
callq 0x6adc
movq 0x70(%r14), %rax
testq %rax, %rax
je 0xa863
movq 0x80(%r14), %rcx
testq %rcx, %rcx
je 0xa863
imulq %rax, %rcx
cvtsi2sd %rcx, %xmm0
movupd (%r15), %xmm1
movapd %xmm0, %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
divpd %xmm2, %xmm1
movupd %xmm1, (%r15)
movsd (%r12), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%r12)
cmpl $0x0, 0x20014(%rbx)
je 0xaa9a
leaq 0x3e(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0x90(%r14), %rax
movq %rax, 0x18(%rsp)
movq %r14, 0x10(%rsp)
addq $0xd0, %r14
xorl %eax, %eax
movq 0x18(%rsp), %r13
cmpq $0x8, %rax
je 0xaa86
imulq $0x76, %rax, %r15
movq 0x8(%rsp), %rcx
addq %r15, %rcx
movq %rcx, 0x28(%rsp)
movq %rax, 0x30(%rsp)
imulq $0x98, %rax, %rbp
movzwl 0x3e(%rbx,%r15), %eax
leaq 0x10(,%rbp), %r12
addq %r13, %r12
movl %eax, -0x10(%r12)
movq 0x40(%rbx,%r15), %rax
movq %rax, -0xc(%r12)
movzwl 0x4a(%rbx,%r15), %eax
movzbl 0x49(%rbx,%r15), %ecx
shll $0x18, %ecx
orl %eax, %ecx
movzbl 0x48(%rbx,%r15), %eax
shll $0x10, %eax
orl %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, (%r12)
movzwl 0x4e(%rbx,%r15), %eax
movzbl 0x4d(%rbx,%r15), %ecx
shll $0x18, %ecx
orl %eax, %ecx
movzbl 0x4c(%rbx,%r15), %eax
shll $0x10, %eax
orl %ecx, %eax
cvtsi2sd %eax, %xmm0
movq %r13, %rax
addq %rbp, %rax
movq %rax, 0x20(%rsp)
movsd %xmm0, 0x8(%r12)
movzwl 0x52(%rbx,%r15), %eax
movzbl 0x51(%rbx,%r15), %ecx
shll $0x18, %ecx
orl %eax, %ecx
movzbl 0x50(%rbx,%r15), %eax
shll $0x10, %eax
orl %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%r12)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x86f6
movzwl 0x56(%rbx,%r15), %eax
movzbl 0x55(%rbx,%r15), %ecx
shll $0x18, %ecx
orl %eax, %ecx
movzbl 0x54(%rbx,%r15), %eax
shll $0x10, %eax
orl %ecx, %eax
movsd 0x20020(%rbx), %xmm1
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x18(%r12)
movzwl 0x5a(%rbx,%r15), %eax
movzbl 0x59(%rbx,%r15), %ecx
shll $0x18, %ecx
orl %eax, %ecx
movzbl 0x58(%rbx,%r15), %eax
shll $0x10, %eax
orl %ecx, %eax
cvtsi2sd %eax, %xmm2
movsd %xmm2, 0x20(%r12)
movzwl 0x5e(%rbx,%r15), %eax
movzbl 0x5d(%rbx,%r15), %ecx
shll $0x18, %ecx
orl %eax, %ecx
movzbl 0x5c(%rbx,%r15), %eax
shll $0x10, %eax
orl %ecx, %eax
cvtsi2sd %eax, %xmm3
mulsd %xmm1, %xmm3
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
unpcklpd %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0]
mulpd %xmm1, %xmm0
movupd %xmm0, 0x18(%r12)
movsd %xmm3, 0x28(%r12)
leaq 0x40(%r13,%rbp), %rdi
movq 0x8(%rsp), %rax
leaq 0x22(%rax,%r15), %rsi
pushq $0x48
popq %rdx
callq 0x2230
xorl %r15d, %r15d
cmpq $0x48, %r15
je 0xaa2c
leaq (%r14,%r15), %rdi
callq 0x6adc
addq $0x8, %r15
jmp 0xaa17
movq 0x20(%rsp), %r12
leaq 0x88(%r12), %rdi
movq 0x28(%rsp), %r15
movq 0x6a(%r15), %rax
movq %rax, 0x88(%r12)
callq 0x6adc
movzwl 0x74(%r15), %eax
movzbl 0x73(%r15), %ecx
shll $0x18, %ecx
orq %rax, %rcx
movzbl 0x72(%r15), %eax
shll $0x10, %eax
orq %rcx, %rax
movq %rax, 0x90(%r12)
movq 0x30(%rsp), %rax
incq %rax
addq $0x98, %r14
jmp 0xa898
movq 0x10(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, 0x20014(%rbx)
movl 0x50(%r14), %ecx
movl %ecx, 0x20018(%rbx)
movups 0x58(%r14), %xmm0
movups %xmm0, 0x20028(%rbx)
movsd 0x68(%r14), %xmm0
movsd %xmm0, 0x20038(%rbx)
testq %rax, %rax
je 0xa870
movq 0x80(%r14), %rcx
testq %rcx, %rcx
je 0xa870
imulq %rax, %rcx
cvtsi2sd %rcx, %xmm0
movsd 0x4bde(%rip), %xmm1     # 0xf6d0
divsd %xmm0, %xmm1
movsd %xmm1, 0x20020(%rbx)
jmp 0xa870
nop