// File: /workspace/github_cpp_makefile_star2_O3/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 $0x18, %rsp
movq %rdi, %rbx
movl $0x550, %edi            # imm = 0x550
movl $0x1, %esi
callq 0x2d20
movq %rax, %r14
movl $0x4, 0xc(%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0xab08
movb 0x4ce(%rbx), %al
andb $0x40, %al
cmpb $0x1, %al
movl $0x3, %eax
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 0x6f74
movq %r13, %rdi
callq 0x6f74
movq %r12, %rdi
callq 0x6f74
movq 0x70(%r14), %rax
testq %rax, %rax
je 0xb1e4
movq 0x80(%r14), %rcx
testq %rcx, %rcx
je 0xb1e4
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 0xb3f3
leaq 0x3e(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x90(%r14), %rax
movq %rax, 0x8(%rsp)
movq %r14, (%rsp)
movq %r14, %r13
addq $0xd0, %r13
xorl %ebp, %ebp
imulq $0x76, %rbp, %rax
movq 0x10(%rsp), %rsi
leaq (%rsi,%rax), %r15
imulq $0x98, %rbp, %rcx
movq 0x8(%rsp), %rdi
leaq (%rdi,%rcx), %r14
movzwl 0x3e(%rbx,%rax), %edx
addq %rcx, %rdi
addq $0x40, %rdi
movl %edx, -0x40(%rdi)
movq 0x40(%rbx,%rax), %rcx
movq %rcx, -0x3c(%rdi)
movzwl 0x4a(%rbx,%rax), %ecx
movzbl 0x49(%rbx,%rax), %edx
shll $0x18, %edx
orl %ecx, %edx
movzbl 0x48(%rbx,%rax), %ecx
shll $0x10, %ecx
orl %edx, %ecx
movsd 0x20020(%rbx), %xmm0
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
movsd %xmm2, -0x30(%rdi)
movzwl 0x4e(%rbx,%rax), %ecx
movzbl 0x4d(%rbx,%rax), %edx
shll $0x18, %edx
orl %ecx, %edx
movzbl 0x4c(%rbx,%rax), %ecx
shll $0x10, %ecx
orl %edx, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
movsd %xmm1, -0x28(%rdi)
movzwl 0x52(%rbx,%rax), %ecx
movzbl 0x51(%rbx,%rax), %edx
shll $0x18, %edx
orl %ecx, %edx
movzbl 0x50(%rbx,%rax), %ecx
shll $0x10, %ecx
orl %edx, %ecx
cvtsi2sd %ecx, %xmm3
movupd 0x20028(%rbx), %xmm4
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
movapd %xmm0, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
mulpd %xmm1, %xmm2
subpd %xmm4, %xmm2
movupd %xmm2, -0x30(%rdi)
mulsd %xmm0, %xmm3
subsd 0x20038(%rbx), %xmm3
movsd %xmm3, -0x20(%rdi)
movzwl 0x56(%rbx,%rax), %ecx
movzbl 0x55(%rbx,%rax), %edx
shll $0x18, %edx
orl %ecx, %edx
movzbl 0x54(%rbx,%rax), %ecx
shll $0x10, %ecx
orl %edx, %ecx
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
movsd %xmm2, -0x18(%rdi)
movzwl 0x5a(%rbx,%rax), %ecx
movzbl 0x59(%rbx,%rax), %edx
shll $0x18, %edx
orl %ecx, %edx
movzbl 0x58(%rbx,%rax), %ecx
shll $0x10, %ecx
orl %edx, %ecx
xorps %xmm3, %xmm3
cvtsi2sd %ecx, %xmm3
movsd %xmm3, -0x10(%rdi)
movzwl 0x5e(%rbx,%rax), %ecx
movzbl 0x5d(%rbx,%rax), %edx
shll $0x18, %edx
orl %ecx, %edx
movzbl 0x5c(%rbx,%rax), %ecx
shll $0x10, %ecx
orl %edx, %ecx
xorps %xmm4, %xmm4
cvtsi2sd %ecx, %xmm4
unpcklpd %xmm3, %xmm2            # xmm2 = xmm2[0],xmm3[0]
mulpd %xmm1, %xmm2
movupd %xmm2, -0x18(%rdi)
mulsd %xmm0, %xmm4
movsd %xmm4, -0x8(%rdi)
addq %rax, %rsi
addq $0x22, %rsi
movl $0x48, %edx
callq 0x2230
xorl %r12d, %r12d
leaq (%r12,%r13), %rdi
callq 0x6f74
addq $0x8, %r12
cmpq $0x48, %r12
jne 0xb380
leaq 0x88(%r14), %rdi
movq 0x6a(%r15), %rax
movq %rax, 0x88(%r14)
callq 0x6f74
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(%r14)
incq %rbp
addq $0x98, %r13
cmpq $0x8, %rbp
jne 0xb216
movq (%rsp), %rax
addq $0x18, %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 0xb1f1
movq 0x80(%r14), %rcx
testq %rcx, %rcx
je 0xb1f1
imulq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd 0x5282(%rip), %xmm1     # 0x106d0
divsd %xmm0, %xmm1
movsd %xmm1, 0x20020(%rbx)
jmp 0xb1f1