// File: /workspace/github_c_makefile_star2_O2/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 0x39b5(%rip), %r13      # 0x1310c
testq %rax, %rax
je 0xf77b
testq %rbx, %rbx
leaq 0x39a6(%rip), %rcx      # 0x1310c
leaq 0x3cb4(%rip), %r15      # 0x13421
cmoveq %rcx, %r15
addq %rax, %rbx
movq %rbx, 0x10(%rsp)
jmp 0xf77e
movq %r13, %r15
testl %r8d, %r8d
je 0xf798
movslq 0x18(%r12), %rax
imulq $0x18, %rax, %rax
leaq 0xc5cd(%rip), %rcx      # 0x1bd60
movq 0x10(%rax,%rcx), %r13
movl 0x24(%r12), %eax
cmpq $0x3, %rax
ja 0xf8ed
movl 0x120(%rsp), %r8d
movl 0x28(%r12), %ebp
leaq 0x3bbd(%rip), %rcx      # 0x13378
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, 0x8(%rsp)
movl %edx, 0x4(%rsp)
cmpl $0x2, 0x18(%r12)
je 0xf942
pushq $0x53
popq %rcx
xorl %edi, %edi
movl %ebp, %esi
movq %rbx, %rdx
movl %r9d, %r14d
callq 0xf360
movl 0x110(%rsp), %ecx
movl 0x120(%rsp), %r8d
testq %rax, %rax
je 0xf942
movq %rax, %r9
subq 0x8(%rax), %rbx
movq %rbx, 0x10(%rsp)
movq 0x48(%rax), %rsi
testq %rsi, %rsi
je 0xf9dc
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rdx
movq %r9, %rbp
callq 0xf662
movq %rbp, %r9
movl 0x120(%rsp), %r8d
movl %r14d, %edi
movq (%rbx), %rbx
movl 0x4(%rsp), %edx
movq 0x118(%rsp), %rsi
jmp 0xfa17
movl %r9d, 0x1c(%rsp)
movl %edx, 0x4(%rsp)
movq %r14, 0x8(%rsp)
leaq 0x88(%rsp), %rdi
movl %ebp, (%rdi)
leaq 0xc73e(%rip), %rax      # 0x1bfb0
movq (%rax), %rsi
leaq 0x1060(%rip), %rdx      # 0x108dc
xorl %ecx, %ecx
callq 0x11e3b
movq %rax, %r14
testq %rax, %rax
jne 0xf897
leaq 0x3ba0(%rip), %rdi      # 0x13432
callq 0x11eec
cmpl $0x0, 0x110(%rsp)
je 0xf989
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 0xf999
movl %esi, 0x2c(%r14)
movl %esi, %eax
jmp 0xf999
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0xf241
jmp 0xfa3c
movl %ebp, %edi
movq %r15, 0x8(%rsp)
movq %r13, %r15
movq %r14, %r13
movl %edx, %r14d
callq 0xf089
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 0xf241
jmp 0xfa3c
leaq 0x88(%rsp), %rsi
movl %ebp, %edi
callq 0xeffc
movq %rax, %rbp
cmpl $0x2, 0x18(%r12)
jne 0xf9c2
cmpq $0x0, 0x30(%r12)
movq 0x8(%rsp), %r14
movq 0x118(%rsp), %rcx
je 0xf9cf
movl 0x88(%rsp), %eax
subq %rax, %rbx
movq %rbx, 0x10(%rsp)
leaq 0x3785(%rip), %r13      # 0x1310c
jmp 0xf9cf
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 0xfa32
movq 0x8(%rsp), %r14
movq 0x118(%rsp), %rcx
movb $0x0, 0x20(%rsp)
movl $0x1, (%rcx)
jmp 0xfa3c
movl %r14d, %edi
testl %ecx, %ecx
je 0xfad0
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 0xfa13
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 0xf241
movq 0x8(%rsp), %r14
testq %rbx, %rbx
je 0xfa47
jle 0xfa72
pushq $0x2b
jmp 0xfa7c
subq $0x8, %rsp
leaq 0x39f3(%rip), %rsi      # 0x13445
leaq 0x28(%rsp), %rcx
leaq 0x58(%rsp), %r9
movq %r14, %rdi
movq %r13, %rdx
movq %rbp, %r8
xorl %eax, %eax
pushq %r15
callq 0x91b0
popq %rcx
popq %rdx
jmp 0xfabe
negq %rbx
movq %rbx, 0x10(%rsp)
pushq $0x2d
popq %r10
movswq %bx, %rax
subq $0x8, %rsp
cmpq %rbx, %rax
je 0xfa94
leaq 0x39be(%rip), %rsi      # 0x13450
jmp 0xfa9b
leaq 0x39cb(%rip), %rsi      # 0x13466
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 0xf842