// File: /workspace/github_c_makefile_star2_O1/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
movl %r9d, %r13d
movl %edx, %r9d
movq %rsi, %r15
movq %rdi, %r12
movq %rcx, 0x10(%rsp)
xorl %eax, %eax
movb %al, 0x20(%rsp)
movb %al, 0x50(%rsp)
movq 0x30(%rsi), %rax
leaq 0x4239(%rip), %rbp      # 0x1410c
movq %rbp, %r14
testq %rax, %rax
je 0xfef8
testq %rcx, %rcx
leaq 0x4227(%rip), %rdx      # 0x1410c
leaq 0x4535(%rip), %r14      # 0x14421
cmoveq %rdx, %r14
addq %rcx, %rax
movq %rax, 0x10(%rsp)
testl %r8d, %r8d
je 0xff11
movslq 0x18(%r15), %rax
leaq (%rax,%rax,2), %rax
leaq 0xce54(%rip), %rcx      # 0x1cd60
movq 0x10(%rcx,%rax,8), %rbp
movl 0x24(%r15), %eax
cmpq $0x3, %rax
ja 0x1007e
movl 0x120(%rsp), %r8d
movl 0x28(%r15), %ebx
leaq 0x4446(%rip), %rcx      # 0x14378
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r12, 0x18(%rsp)
cmpl $0x2, 0x18(%r15)
je 0x100b8
movq 0x10(%rsp), %r12
xorl %edi, %edi
movl %ebx, %esi
movq %r12, %rdx
movl $0x53, %ecx
movl %r9d, 0xc(%rsp)
callq 0xfad5
movl 0x110(%rsp), %ecx
movl 0x120(%rsp), %r8d
movl 0xc(%rsp), %edx
testq %rax, %rax
je 0x100b8
movq %rax, %r9
subq 0x8(%rax), %r12
movq %r12, 0x10(%rsp)
movq 0x48(%rax), %rsi
testq %rsi, %rsi
je 0x10114
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rdx
movq %r9, %rbx
callq 0xfdd9
movq %rbx, %r9
movl 0x120(%rsp), %r8d
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %r12
jmp 0x10139
movl %r9d, 0xc(%rsp)
movq %r12, 0x18(%rsp)
leaq 0x88(%rsp), %rdi
movl %ebx, (%rdi)
leaq 0xcfcf(%rip), %rax      # 0x1cfb0
movq (%rax), %rsi
leaq 0x1075(%rip), %rdx      # 0x11060
xorl %ecx, %ecx
callq 0x1275f
movq %rax, %r12
testq %rax, %rax
jne 0x10006
leaq 0x4431(%rip), %rdi      # 0x14432
callq 0x12808
cmpl $0x0, 0x110(%rsp)
movl 0x120(%rsp), %r8d
movq 0x118(%rsp), %rcx
je 0x1003b
cmpl $0x2, %r13d
jg 0x1002e
cmpl $0x2, 0x2c(%r12)
jg 0x10036
cmpl $0x0, 0x2c(%r12)
jne 0x1003b
movl %r13d, 0x2c(%r12)
movq %r12, %rbx
addq $0x4, %rbx
xorl %eax, %eax
cmpl %r13d, 0x2c(%r12)
sete %al
movl %eax, (%rcx)
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
movl 0xc(%rsp), %edx
movq %r12, %rcx
callq 0xf995
movq 0x18(%rsp), %r12
jmp 0x10162
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
movl %r9d, %edx
xorl %ecx, %ecx
callq 0xf995
jmp 0x10162
movl %ebx, %edi
movl %r9d, %r13d
callq 0xf7e1
movq %rax, %rbx
movq 0x118(%rsp), %rax
movl $0x1, (%rax)
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
movl %r13d, %edx
xorl %ecx, %ecx
movl 0x120(%rsp), %r8d
jmp 0x1015d
leaq 0x88(%rsp), %rsi
movl %ebx, %edi
callq 0xf754
movq %rax, %rbx
cmpl $0x2, 0x18(%r15)
jne 0x100fa
cmpq $0x0, 0x30(%r15)
movq 0x18(%rsp), %r12
movq 0x118(%rsp), %rcx
je 0x10107
movl 0x88(%rsp), %eax
subq %rax, 0x10(%rsp)
leaq 0x4014(%rip), %rbp      # 0x1410c
jmp 0x10107
movq 0x18(%rsp), %r12
movq 0x118(%rsp), %rcx
movb $0x0, 0x20(%rsp)
movl $0x1, (%rcx)
jmp 0x10162
testl %ecx, %ecx
movq 0x18(%rsp), %r12
je 0x10135
cmpl $0x2, %r13d
jg 0x1012a
cmpl $0x2, 0x38(%r9)
jg 0x10131
cmpl $0x0, 0x38(%r9)
jne 0x10135
movl %r13d, 0x38(%r9)
movl 0x38(%r9), %eax
movq %r9, %rbx
addq $0x10, %rbx
xorl %ecx, %ecx
cmpl %r13d, %eax
sete %cl
movq 0x118(%rsp), %rax
movl %ecx, (%rax)
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %r9, %rcx
callq 0xf995
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x1019d
movl $0x2b, %r10d
jg 0x10182
negq %rax
movq %rax, 0x10(%rsp)
movl $0x2d, %r10d
movq 0x10(%rsp), %r11
movswq %r11w, %rax
subq $0x8, %rsp
cmpq %r11, %rax
je 0x101ca
leaq 0x42b5(%rip), %rsi      # 0x14450
jmp 0x101d1
subq $0x8, %rsp
leaq 0x429d(%rip), %rsi      # 0x14445
leaq 0x28(%rsp), %rcx
leaq 0x58(%rsp), %r9
movq %r12, %rdi
movq %rbp, %rdx
movq %rbx, %r8
xorl %eax, %eax
pushq %r14
callq 0x91b0
addq $0x10, %rsp
jmp 0x101f5
leaq 0x4295(%rip), %rsi      # 0x14466
leaq 0x28(%rsp), %rcx
leaq 0x58(%rsp), %r9
movq %r12, %rdi
movq %rbp, %rdx
movq %rbx, %r8
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r10
callq 0x91b0
addq $0x20, %rsp
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq