// File: /workspace/github_c_makefile_star2_O3/Nico01[P]obj2asm/outarget.c
// Function: get_target
void get_target( result, fixup, mode, data, pre_name, type, assign,
                                                        type_known, seg_reg )
    char        *result;        /* Output string                            */
    FIX_T       *fixup;         /* Fixup to figure out                      */
    int         mode;           /* 0 = Data Deref, 1 = Code, 2 = Data Ref   */
    long        data;           /* Value added (fixups get added onto this) */
    int         pre_name;       /* Are the fixup type words needed?         */
    int         type;           /* type of value pointed to (word ptr, etc) */
    int         assign;         /* Assign type if needed?                   */
    int         *type_known;    /* Is the "word ptr" text needed? (result)  */
    int         seg_reg;        /* Segment register used                    */
{
    int         index;
    PUB_T       *pub_rec;
    EXT_T       ext_search;
    EXT_T       *ext_rec;
    STRUC_T     *pub_struct;
    char        *prefix;
    char        this_seg[NAMESIZE+1+1];     /* 1 for ':', 1 for \0 */
    char        this_member[NAMESIZE+1+1];  /* 1 for ., 1 for \0 */
    word    seg_size;
    char        *this_name;
    char        *this_comment;
    int         this_type;
    char        sign;
    long        disp;

#ifdef DEBUG
printf("-> get_target for [%04X:%04X]\n", fix_rec->seg_idx, fix_rec->dat_offset );
#endif

    disp = data;

    this_seg[0] = '\0';
    this_member[0] = '\0';
    this_comment = "";

    /*
    ** Fixups cannot have a displacement value (stored with the fixup)
    ** AND a value added (stored in the image to which the fixup is added)
    */
    if ( fixup->displacement != 0L ) {
        if ( disp != 0L ) {
            this_comment = "[MULTIPLE FIXUP]";
        }
        disp += fixup->displacement;
    }

    if ( pre_name ) {
        prefix = fix_type[fixup->form].prefix;
    } else {
        prefix = "";
    }

    index = fixup->b_index;

    switch( fixup->b_mode ) {
        case SEGMENT:           /* Segment Index and Displacement */
            if ( fixup->form != BASE ) {
                /* PUBLIC names will be stored as segment + offset */
                pub_rec = check_public( 0, index, disp, 'S' );
                if ( pub_rec ) {
                    this_name = pub_rec->name;
                    disp -= (long)pub_rec->offset;
                    pub_struct = pub_rec->structure;
                    if ( pub_struct ) {
                        this_type = find_member( this_member, pub_struct,
                                                                      &disp );
                    } else {
                        if ( assign && ((type <= FAR && pub_rec->type > FAR)
                                || pub_rec->type == UNKNOWN) ) {
                            pub_rec->type = type;
                        }
                        this_type = pub_rec->type;
                    }
                    if ( this_type != type ) {
                        *type_known = FALSE;
                    } else {
                        *type_known = TRUE;
                    }
                    get_seg( this_seg, fixup, mode, pub_rec, seg_reg );
                    break;
                }
            }

            this_name = seg_name(index,&seg_size);
            if ( fixup->form == BASE && fixup->displacement != 0 ) {
                prefix = "";        /* MASM generates seg length, if */
                disp -= seg_size;   /* "SEG" is missing, do the same */
            }
            this_seg[0] = '\0';
            *type_known = TRUE;
            break;
        case GROUP:                     /* Group Index and Displacement */
            this_name = grp_name(index);
            *type_known = TRUE;
            get_seg( this_seg, fixup, mode, NULL, seg_reg );
            break;
        case EXTERNAL:                  /* External Index and Displacement */
            ext_search.index = index;
            ext_rec = (EXT_T *)find( (char *)&ext_search,
                                        extern_tree, TC ext_compare, NULL );
            if ( ext_rec == NULL ) fmt_error( "Undefined external" );

            this_name = ext_rec->name;

            if ( assign && ((type <= FAR && ext_rec->type > FAR)
                            || ext_rec->type == UNKNOWN) ) {
                ext_rec->type = type;
            }
            if ( ext_rec->type != type ) {
                *type_known = FALSE;
            } else {
                *type_known = TRUE;
            }
            get_seg( this_seg, fixup, mode, ext_rec, seg_reg );
            break;
        case FRAME:                     /* Frame Number and Displacement */
            get_seg( this_seg, fixup, mode, NULL, seg_reg );
            break;
    }

    if ( disp == 0 ) {
/* ;* */ sprintf( result, "%s%s%s%s%s", prefix, this_seg,
                     this_name, this_member, this_comment );
    } else {
        if ( disp > 0L ) {
            sign = '+';
        } else {
            sign = '-';
            disp = -disp;
        }
        if ( disp > 32767L || disp < -32768L ) {
            sprintf( result, "%s%s%s%s %c 0%08lXh%s",
                                prefix, this_seg,
                                this_name, this_member,
                                sign, disp,
                                this_comment );
        } else {
            sprintf( result, "%s%s%s%s %c 0%04lXh%s",
                                prefix, this_seg,
                                this_name, this_member,
                                sign, disp,
                                this_comment );
        }
    }
#ifdef DEBUG
printf("<- get_target [%04X:%04X]\n", fix_rec->seg_idx, fix_rec->dat_offset );
#endif

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rcx, %rbx
movq %rsi, %r12
movq %rdi, %r14
movq %rcx, 0x10(%rsp)
xorl %eax, %eax
movb %al, 0x20(%rsp)
movb %al, 0x50(%rsp)
movq 0x30(%rsi), %rax
leaq 0x4217(%rip), %r13      # 0x1410c
testq %rax, %rax
je 0xff19
testq %rbx, %rbx
leaq 0x4208(%rip), %rcx      # 0x1410c
leaq 0x4516(%rip), %r15      # 0x14421
cmoveq %rcx, %r15
addq %rax, %rbx
movq %rbx, 0x10(%rsp)
jmp 0xff1c
movq %r13, %r15
testl %r8d, %r8d
je 0xff36
movslq 0x18(%r12), %rax
leaq (%rax,%rax,2), %rax
leaq 0xce2f(%rip), %rcx      # 0x1cd60
movq 0x10(%rcx,%rax,8), %r13
movl 0x24(%r12), %eax
cmpq $0x3, %rax
ja 0x1008d
movl 0x120(%rsp), %r8d
movl 0x28(%r12), %ebp
leaq 0x441f(%rip), %rcx      # 0x14378
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, 0x8(%rsp)
movl %edx, 0x4(%rsp)
cmpl $0x2, 0x18(%r12)
je 0x100e2
xorl %edi, %edi
movl %ebp, %esi
movq %rbx, %rdx
movl $0x53, %ecx
movl %r9d, %r14d
callq 0xfafa
movl 0x110(%rsp), %ecx
movl 0x120(%rsp), %r8d
testq %rax, %rax
je 0x100e2
movq %rax, %r9
subq 0x8(%rax), %rbx
movq %rbx, 0x10(%rsp)
movq 0x48(%rax), %rsi
testq %rsi, %rsi
je 0x1017c
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rdx
movq %r9, %rbp
callq 0xfdfe
movq %rbp, %r9
movl 0x120(%rsp), %r8d
movl %r14d, %edi
movq (%rbx), %rbx
movl 0x4(%rsp), %edx
movq 0x118(%rsp), %rsi
jmp 0x101b7
movl %r9d, 0x1c(%rsp)
movl %edx, 0x4(%rsp)
movq %r14, 0x8(%rsp)
leaq 0x88(%rsp), %rdi
movl %ebp, (%rdi)
leaq 0xcf9e(%rip), %rax      # 0x1cfb0
movq (%rax), %rsi
leaq 0x10d0(%rip), %rdx      # 0x110ec
xorl %ecx, %ecx
callq 0x1280f
movq %rax, %r14
testq %rax, %rax
jne 0x10037
leaq 0x4400(%rip), %rdi      # 0x14432
callq 0x128bc
cmpl $0x0, 0x110(%rsp)
je 0x10129
movl 0x1c(%rsp), %esi
cmpl $0x3, %esi
setl %cl
movl 0x2c(%r14), %eax
cmpl $0x3, %eax
setge %dl
andb %cl, %dl
testl %eax, %eax
sete %cl
orb %dl, %cl
cmpb $0x1, %cl
movl 0x120(%rsp), %r8d
jne 0x10139
movl %esi, 0x2c(%r14)
movl %esi, %eax
jmp 0x10139
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0xf9d1
jmp 0x101dc
movl %ebp, %edi
movq %r15, 0x8(%rsp)
movq %r13, %r15
movq %r14, %r13
movl %edx, %r14d
callq 0xf81d
movq %rax, %rbp
movq 0x118(%rsp), %rax
movl $0x1, (%rax)
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
movl %r14d, %edx
movq %r13, %r14
movq %r15, %r13
movq 0x8(%rsp), %r15
xorl %ecx, %ecx
movl 0x120(%rsp), %r8d
callq 0xf9d1
jmp 0x101dc
leaq 0x88(%rsp), %rsi
movl %ebp, %edi
callq 0xf790
movq %rax, %rbp
cmpl $0x2, 0x18(%r12)
jne 0x10162
cmpq $0x0, 0x30(%r12)
movq 0x8(%rsp), %r14
movq 0x118(%rsp), %rcx
je 0x1016f
movl 0x88(%rsp), %eax
subq %rax, %rbx
movq %rbx, 0x10(%rsp)
leaq 0x3fe5(%rip), %r13      # 0x1410c
jmp 0x1016f
movl 0x2c(%r14), %eax
movl 0x1c(%rsp), %esi
movl 0x120(%rsp), %r8d
movq %r14, %rbp
addq $0x4, %rbp
xorl %ecx, %ecx
cmpl %esi, %eax
sete %cl
movq 0x118(%rsp), %rax
movl %ecx, (%rax)
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
movl 0x4(%rsp), %edx
movq %r14, %rcx
jmp 0x101d2
movq 0x8(%rsp), %r14
movq 0x118(%rsp), %rcx
movb $0x0, 0x20(%rsp)
movl $0x1, (%rcx)
jmp 0x101dc
movl %r14d, %edi
testl %ecx, %ecx
je 0x10276
cmpl $0x3, %edi
setl %cl
movl 0x38(%r9), %eax
cmpl $0x3, %eax
setge %dl
andb %cl, %dl
testl %eax, %eax
sete %cl
orb %dl, %cl
cmpb $0x1, %cl
movq 0x118(%rsp), %rsi
jne 0x101b3
movl %edi, 0x38(%r9)
movl %edi, %eax
movl 0x4(%rsp), %edx
movq %r9, %rbp
addq $0x10, %rbp
xorl %ecx, %ecx
cmpl %edi, %eax
sete %cl
movl %ecx, (%rsi)
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
movq %r9, %rcx
callq 0xf9d1
movq 0x8(%rsp), %r14
testq %rbx, %rbx
je 0x1020d
movl $0x2b, %r10d
jg 0x101f7
negq %rbx
movq %rbx, 0x10(%rsp)
movl $0x2d, %r10d
movswq %bx, %rax
subq $0x8, %rsp
cmpq %rbx, %rax
je 0x1023a
leaq 0x4245(%rip), %rsi      # 0x14450
jmp 0x10241
subq $0x8, %rsp
leaq 0x422d(%rip), %rsi      # 0x14445
leaq 0x28(%rsp), %rcx
leaq 0x58(%rsp), %r9
movq %r14, %rdi
movq %r13, %rdx
movq %rbp, %r8
xorl %eax, %eax
pushq %r15
callq 0x91b0
addq $0x10, %rsp
jmp 0x10264
leaq 0x4225(%rip), %rsi      # 0x14466
leaq 0x28(%rsp), %rcx
leaq 0x58(%rsp), %r9
movq %r14, %rdi
movq %r13, %rdx
movq %rbp, %r8
xorl %eax, %eax
pushq %r15
pushq %rbx
pushq %r10
callq 0x91b0
addq $0x20, %rsp
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x38(%r9), %eax
jmp 0xffe2