// File: /workspace/github_cpp_makefile_star2_O1/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 0x2d54
movq %rax, %r14
movl $0x4, 0xc(%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0xafa2
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), %r13
movq 0x4e8(%rbx), %rax
movq %rax, 0x58(%r14)
leaq 0x60(%r14), %r12
movq 0x4f0(%rbx), %rax
movq %rax, 0x60(%r14)
leaq 0x68(%r14), %r15
movq 0x4f8(%rbx), %rax
movq %rax, 0x68(%r14)
movq %r13, %rdi
callq 0x70b4
movq %r12, %rdi
callq 0x70b4
movq %r15, %rdi
callq 0x70b4
movq 0x70(%r14), %rax
testq %rax, %rax
je 0xb71b
movq 0x80(%r14), %rcx
testq %rcx, %rcx
je 0xb71b
movsd (%r13), %xmm0
imulq %rax, %rcx
cvtsi2sd %rcx, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%r13)
movsd (%r12), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%r12)
movsd (%r15), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%r15)
cmpl $0x0, 0x20014(%rbx)
je 0xb93a
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
imulq $0x98, %rbp, %rcx
movzwl 0x3e(%rbx,%rax), %edx
movq 0x8(%rsp), %r9
leaq (%r9,%rcx), %rdi
addq $0x40, %rdi
movl %edx, -0x40(%rdi)
movq 0x40(%rbx,%rax), %rdx
movq %rdx, -0x3c(%rdi)
movzwl 0x4a(%rbx,%rax), %edx
movzbl 0x49(%rbx,%rax), %esi
shll $0x18, %esi
orl %edx, %esi
movzbl 0x48(%rbx,%rax), %edx
shll $0x10, %edx
orl %esi, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
movsd %xmm1, -0x30(%rdi)
movzwl 0x4e(%rbx,%rax), %edx
movzbl 0x4d(%rbx,%rax), %esi
shll $0x18, %esi
orl %edx, %esi
movzbl 0x4c(%rbx,%rax), %edx
shll $0x10, %edx
orl %esi, %edx
xorps %xmm2, %xmm2
cvtsi2sd %edx, %xmm2
movsd %xmm2, -0x28(%rdi)
movzwl 0x52(%rbx,%rax), %edx
movzbl 0x51(%rbx,%rax), %esi
shll $0x18, %esi
orl %edx, %esi
movzbl 0x50(%rbx,%rax), %edx
shll $0x10, %edx
orl %esi, %edx
xorps %xmm3, %xmm3
cvtsi2sd %edx, %xmm3
movq 0x10(%rsp), %r8
leaq (%r8,%rax), %r14
movsd %xmm3, -0x20(%rdi)
movsd 0x20020(%rbx), %xmm0
mulsd %xmm0, %xmm1
subsd 0x20028(%rbx), %xmm1
movsd %xmm1, -0x30(%rdi)
mulsd %xmm0, %xmm2
subsd 0x20030(%rbx), %xmm2
movsd %xmm2, -0x28(%rdi)
mulsd %xmm0, %xmm3
subsd 0x20038(%rbx), %xmm3
movsd %xmm3, -0x20(%rdi)
movzwl 0x56(%rbx,%rax), %edx
movzbl 0x55(%rbx,%rax), %esi
shll $0x18, %esi
orl %edx, %esi
movzbl 0x54(%rbx,%rax), %edx
shll $0x10, %edx
orl %esi, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
movsd %xmm1, -0x18(%rdi)
movzwl 0x5a(%rbx,%rax), %edx
movzbl 0x59(%rbx,%rax), %esi
shll $0x18, %esi
orl %edx, %esi
movzbl 0x58(%rbx,%rax), %edx
shll $0x10, %edx
orl %esi, %edx
xorps %xmm2, %xmm2
cvtsi2sd %edx, %xmm2
movsd %xmm2, -0x10(%rdi)
movzwl 0x5e(%rbx,%rax), %edx
movzbl 0x5d(%rbx,%rax), %esi
shll $0x18, %esi
orl %edx, %esi
movzbl 0x5c(%rbx,%rax), %edx
shll $0x10, %edx
orl %esi, %edx
xorps %xmm3, %xmm3
cvtsi2sd %edx, %xmm3
leaq (%r9,%rcx), %r15
mulsd %xmm0, %xmm1
movsd %xmm1, -0x18(%rdi)
mulsd %xmm0, %xmm2
movsd %xmm2, -0x10(%rdi)
mulsd %xmm0, %xmm3
movsd %xmm3, -0x8(%rdi)
leaq (%r8,%rax), %rsi
addq $0x22, %rsi
movl $0x48, %edx
callq 0x2240
xorl %r12d, %r12d
leaq (%r12,%r13), %rdi
callq 0x70b4
addq $0x8, %r12
cmpq $0x48, %r12
jne 0xb8c7
leaq 0x88(%r15), %rdi
movq 0x6a(%r14), %rax
movq %rax, 0x88(%r15)
callq 0x70b4
movzwl 0x74(%r14), %eax
movzbl 0x73(%r14), %ecx
shll $0x18, %ecx
orq %rax, %rcx
movzbl 0x72(%r14), %eax
shll $0x10, %eax
orq %rcx, %rax
movq %rax, 0x90(%r15)
incq %rbp
addq $0x98, %r13
cmpq $0x8, %rbp
jne 0xb74d
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)
movsd 0x58(%r14), %xmm0
movsd %xmm0, 0x20028(%rbx)
movsd 0x60(%r14), %xmm0
movsd %xmm0, 0x20030(%rbx)
movsd 0x68(%r14), %xmm0
movsd %xmm0, 0x20038(%rbx)
testq %rax, %rax
je 0xb728
movq 0x80(%r14), %rcx
testq %rcx, %rcx
je 0xb728
imulq %rax, %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd 0x5cfb(%rip), %xmm1     # 0x116a0
divsd %xmm0, %xmm1
movsd %xmm1, 0x20020(%rbx)
jmp 0xb728