// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %r8, %r15
movq %rcx, %r12
movl %edx, %ebp
movq %rsi, %r13
xorl %ebx, %ebx
xorl %edx, %edx
callq 0x85e5
testl %eax, %eax
je 0x73e7
movq %r14, (%rsp)
incl %ebp
xorl %r14d, %r14d
decl %ebp
je 0x7377
addl %eax, %r14d
movq %r13, %rsi
movl %r14d, %edx
callq 0x85e5
testl %eax, %eax
jne 0x735f
jmp 0x73e7
movq 0x38(%r13), %rcx
movl %r14d, %edx
leaq (%rcx,%rdx), %rbx
cmpb $0x0, (%rcx,%rdx)
je 0x7392
movzwl 0x2(%rbx), %esi
xorl %ecx, %ecx
xorl %edx, %edx
jmp 0x73ae
movzbl 0x1(%rbx), %ecx
testb $0x7f, %cl
jne 0x7388
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 0x73c3
cmpl $0x41, %esi
je 0x73c3
movzwl 0x6(%rbx), %ecx
movl 0x8(%rbx), %edx
testq %r12, %r12
je 0x73cc
movl %esi, (%r12)
testq %r15, %r15
je 0x73d4
movl %ecx, (%r15)
testq %rdi, %rdi
je 0x73db
movl %edx, (%rdi)
movq 0x40(%rsp), %rcx
testq %rcx, %rcx
je 0x73e7
movl %eax, (%rcx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq