// File: /workspace/github_cpp_makefile_star2_O2/rurban[P]dgnlib/dgnhelp.cpp
// Function: DGNGetLinkage
unsigned char *DGNGetLinkage( DGNHandle hDGN, DGNElemCore *psElement, 
                              int iIndex, int *pnLinkageType,
                              int *pnEntityNum, int *pnMSLink, int *pnLength )
    
{
    int nAttrOffset;
    int iLinkage, nLinkSize;

    for( iLinkage=0, nAttrOffset=0;
         (nLinkSize = DGNGetAttrLinkSize( hDGN, psElement, nAttrOffset)) != 0;
         iLinkage++, nAttrOffset += nLinkSize )
    {
        if( iLinkage == iIndex )
        {
            int  nLinkageType=0, nEntityNum=0, nMSLink = 0;
            CPLAssert( nLinkSize > 4 );

            if( psElement->attr_data[nAttrOffset+0] == 0x00
                && (psElement->attr_data[nAttrOffset+1] == 0x00
                    || psElement->attr_data[nAttrOffset+1] == 0x80) )
            {
                nLinkageType = DGNLT_DMRS;
                nEntityNum = psElement->attr_data[nAttrOffset+2] 
                    + psElement->attr_data[nAttrOffset+3] * 256;
                nMSLink = psElement->attr_data[nAttrOffset+4] 
                    + psElement->attr_data[nAttrOffset+5] * 256
                    + psElement->attr_data[nAttrOffset+6] * 65536;
            }
            else
                nLinkageType = psElement->attr_data[nAttrOffset+2] 
                    + psElement->attr_data[nAttrOffset+3] * 256;

            // Possibly an external database linkage?
            if( nLinkSize == 16 && nLinkageType != DGNLT_SHAPE_FILL )
            {
                nEntityNum = psElement->attr_data[nAttrOffset+6] 
                    + psElement->attr_data[nAttrOffset+7] * 256;
                nMSLink = psElement->attr_data[nAttrOffset+8] 
                    + psElement->attr_data[nAttrOffset+9] * 256
                    + psElement->attr_data[nAttrOffset+10] * 65536
                    + psElement->attr_data[nAttrOffset+11] * 65536 * 256;
                
            }

            if( pnLinkageType != NULL )
                *pnLinkageType = nLinkageType;
            if( pnEntityNum != NULL )
                *pnEntityNum = nEntityNum;
            if( pnMSLink != NULL )
                *pnMSLink = nMSLink;
            if( pnLength != NULL )
                *pnLength = nLinkSize;

            return psElement->attr_data + nAttrOffset;
        }
    }
             
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %r15
movq %r8, %r12
movq %rcx, (%rsp)
movl %edx, %ebp
movq %rsi, %r13
xorl %ebx, %ebx
xorl %r14d, %r14d
movq %r13, %rsi
movl %r14d, %edx
callq 0x7efc
testl %eax, %eax
je 0x6ddd
subl $0x1, %ebp
jb 0x6d6d
addl %eax, %r14d
jmp 0x6d54
movq 0x38(%r13), %rcx
movl %r14d, %edx
leaq (%rcx,%rdx), %rbx
cmpb $0x0, (%rcx,%rdx)
je 0x6d88
movzwl 0x2(%rbx), %esi
xorl %ecx, %ecx
xorl %edx, %edx
jmp 0x6da4
movzbl 0x1(%rbx), %ecx
testb $0x7f, %cl
jne 0x6d7e
movzwl 0x2(%rbx), %ecx
movzwl 0x4(%rbx), %esi
movzbl 0x6(%rbx), %edx
shll $0x10, %edx
orl %esi, %edx
xorl %esi, %esi
movq (%rsp), %rdi
cmpl $0x10, %eax
jne 0x6db9
cmpl $0x41, %esi
je 0x6db9
movzwl 0x6(%rbx), %ecx
movl 0x8(%rbx), %edx
testq %rdi, %rdi
je 0x6dc0
movl %esi, (%rdi)
testq %r12, %r12
je 0x6dc9
movl %ecx, (%r12)
testq %r15, %r15
je 0x6dd1
movl %edx, (%r15)
movq 0x40(%rsp), %rcx
testq %rcx, %rcx
je 0x6ddd
movl %eax, (%rcx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq