// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl $0x550, %edi            # imm = 0x550
movl $0x1, %esi
callq 0x2fc0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl $0x4, 0xc(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x109e0
movq -0x8(%rbp), %rax
movzbl 0x4ce(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x1151f
movq -0x10(%rbp), %rax
movl $0x3, 0x50(%rax)
jmp 0x1152a
movq -0x10(%rbp), %rax
movl $0x2, 0x50(%rax)
movq -0x8(%rbp), %rax
movzbl 0x46a(%rax), %eax
movq -0x8(%rbp), %rcx
movzbl 0x46b(%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x8(%rbp), %rcx
movzbl 0x469(%rcx), %ecx
shll $0x10, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x8(%rbp), %rcx
movzbl 0x468(%rcx), %ecx
shll $0x10, %ecx
addl %ecx, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x8(%rbp), %rax
movb 0x470(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x88(%rax)
movq -0x8(%rbp), %rax
movb 0x471(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x89(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x8a(%rax)
movq -0x8(%rbp), %rax
movzbl 0x46e(%rax), %eax
movq -0x8(%rbp), %rcx
movzbl 0x46f(%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x8(%rbp), %rcx
movzbl 0x46d(%rcx), %ecx
shll $0x10, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x8(%rbp), %rcx
movzbl 0x46c(%rcx), %ecx
shll $0x10, %ecx
addl %ecx, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x8(%rbp), %rax
movb 0x472(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x78(%rax)
movq -0x8(%rbp), %rax
movb 0x473(%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x79(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x7a(%rax)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x4e8(%rcx), %rcx
movq %rcx, 0x58(%rax)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x4f0(%rcx), %rcx
movq %rcx, 0x60(%rax)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x4f8(%rcx), %rcx
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rdi
addq $0x58, %rdi
callq 0xa190
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
callq 0xa190
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
callq 0xa190
movq -0x10(%rbp), %rax
cmpq $0x0, 0x70(%rax)
je 0x1172a
movq -0x10(%rbp), %rax
cmpq $0x0, 0x80(%rax)
je 0x1172a
movq -0x10(%rbp), %rax
movsd 0x58(%rax), %xmm0
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rcx
imulq 0x80(%rcx), %rax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movsd %xmm0, 0x58(%rax)
movq -0x10(%rbp), %rax
movsd 0x60(%rax), %xmm0
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rcx
imulq 0x80(%rcx), %rax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movsd %xmm0, 0x60(%rax)
movq -0x10(%rbp), %rax
movsd 0x68(%rax), %xmm0
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rcx
imulq 0x80(%rcx), %rax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movsd %xmm0, 0x68(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x20014(%rax)
jne 0x117e5
movq -0x8(%rbp), %rax
movl $0x1, 0x20014(%rax)
movq -0x10(%rbp), %rax
movl 0x50(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x20018(%rax)
movq -0x10(%rbp), %rax
movsd 0x58(%rax), %xmm0
movq -0x8(%rbp), %rax
movsd %xmm0, 0x20028(%rax)
movq -0x10(%rbp), %rax
movsd 0x60(%rax), %xmm0
movq -0x8(%rbp), %rax
movsd %xmm0, 0x20030(%rax)
movq -0x10(%rbp), %rax
movsd 0x68(%rax), %xmm0
movq -0x8(%rbp), %rax
movsd %xmm0, 0x20038(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x70(%rax)
je 0x117e3
movq -0x10(%rbp), %rax
cmpq $0x0, 0x80(%rax)
je 0x117e3
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rcx
imulq 0x80(%rcx), %rax
cvtsi2sd %rax, %xmm1
movsd 0x810d(%rip), %xmm0     # 0x198e0
divsd %xmm1, %xmm0
movq -0x8(%rbp), %rax
movsd %xmm0, 0x20020(%rax)
jmp 0x117e5
movl $0x0, -0x1c(%rbp)
cmpl $0x8, -0x1c(%rbp)
jge 0x11aea
movq -0x8(%rbp), %rax
addq $0x10, %rax
addq $0x2e, %rax
imull $0x76, -0x1c(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
addq $0x90, %rax
movslq -0x1c(%rbp), %rcx
imulq $0x98, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movzbl (%rax), %ecx
movq -0x28(%rbp), %rax
movzbl 0x1(%rax), %eax
shll $0x8, %eax
addl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x2(%rcx), %rcx
movq %rcx, 0x4(%rax)
movq -0x28(%rbp), %rax
movzbl 0xc(%rax), %eax
movq -0x28(%rbp), %rcx
movzbl 0xd(%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzbl 0xb(%rcx), %ecx
shll $0x10, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzbl 0xa(%rcx), %ecx
shll $0x10, %ecx
addl %ecx, %eax
cvtsi2sd %eax, %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, 0x10(%rax)
movq -0x28(%rbp), %rax
movzbl 0x10(%rax), %eax
movq -0x28(%rbp), %rcx
movzbl 0x11(%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzbl 0xf(%rcx), %ecx
shll $0x10, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzbl 0xe(%rcx), %ecx
shll $0x10, %ecx
addl %ecx, %eax
cvtsi2sd %eax, %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, 0x18(%rax)
movq -0x28(%rbp), %rax
movzbl 0x14(%rax), %eax
movq -0x28(%rbp), %rcx
movzbl 0x15(%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzbl 0x13(%rcx), %ecx
shll $0x10, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzbl 0x12(%rcx), %ecx
shll $0x10, %ecx
addl %ecx, %eax
cvtsi2sd %eax, %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x10, %rsi
callq 0xd4f0
movq -0x28(%rbp), %rax
movzbl 0x18(%rax), %eax
movq -0x28(%rbp), %rcx
movzbl 0x19(%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzbl 0x17(%rcx), %ecx
shll $0x10, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzbl 0x16(%rcx), %ecx
shll $0x10, %ecx
addl %ecx, %eax
cvtsi2sd %eax, %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, 0x28(%rax)
movq -0x28(%rbp), %rax
movzbl 0x1c(%rax), %eax
movq -0x28(%rbp), %rcx
movzbl 0x1d(%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzbl 0x1b(%rcx), %ecx
shll $0x10, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzbl 0x1a(%rcx), %ecx
shll $0x10, %ecx
addl %ecx, %eax
cvtsi2sd %eax, %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, 0x30(%rax)
movq -0x28(%rbp), %rax
movzbl 0x20(%rax), %eax
movq -0x28(%rbp), %rcx
movzbl 0x21(%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzbl 0x1f(%rcx), %ecx
shll $0x10, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzbl 0x1e(%rcx), %ecx
shll $0x10, %ecx
addl %ecx, %eax
cvtsi2sd %eax, %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, 0x38(%rax)
movq -0x8(%rbp), %rax
movsd 0x20020(%rax), %xmm0
movq -0x30(%rbp), %rax
mulsd 0x28(%rax), %xmm0
movsd %xmm0, 0x28(%rax)
movq -0x8(%rbp), %rax
movsd 0x20020(%rax), %xmm0
movq -0x30(%rbp), %rax
mulsd 0x30(%rax), %xmm0
movsd %xmm0, 0x30(%rax)
movq -0x8(%rbp), %rax
movsd 0x20020(%rax), %xmm0
movq -0x30(%rbp), %rax
mulsd 0x38(%rax), %xmm0
movsd %xmm0, 0x38(%rax)
movq -0x30(%rbp), %rdi
addq $0x40, %rdi
movq -0x28(%rbp), %rsi
addq $0x22, %rsi
movl $0x48, %edx
callq 0x2240
movl $0x0, -0x34(%rbp)
cmpl $0x9, -0x34(%rbp)
jge 0x11a79
movq -0x30(%rbp), %rdi
addq $0x40, %rdi
movslq -0x34(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0xa190
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x11a50
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x6a(%rcx), %rcx
movq %rcx, 0x88(%rax)
movq -0x30(%rbp), %rdi
addq $0x88, %rdi
callq 0xa190
movq -0x28(%rbp), %rax
movzbl 0x74(%rax), %eax
movq -0x28(%rbp), %rcx
movzbl 0x75(%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzbl 0x73(%rcx), %ecx
shll $0x10, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x28(%rbp), %rcx
movzbl 0x72(%rcx), %ecx
shll $0x10, %ecx
addl %ecx, %eax
movslq %eax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x90(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x117ec
movq -0x18(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)