// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x128(%rbp)
movb $0x0, -0xd0(%rbp)
movb $0x0, -0x100(%rbp)
leaq 0x5444(%rip), %rax      # 0x181c0
movq %rax, -0x118(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x12dbc
cmpq $0x0, -0x128(%rbp)
je 0x12da6
leaq 0x5752(%rip), %rax      # 0x184f1
movq %rax, -0x118(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
addq -0x128(%rbp), %rax
movq %rax, -0x128(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x12de5
movq -0x10(%rbp), %rax
movslq 0x18(%rax), %rcx
leaq 0xd0bf(%rip), %rax      # 0x1fe90
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0xa0(%rbp)
jmp 0x12df3
leaq 0x53d4(%rip), %rax      # 0x181c0
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl 0x24(%rax), %eax
movq %rax, -0x130(%rbp)
subq $0x3, %rax
ja 0x130c9
movq -0x130(%rbp), %rax
leaq 0x5625(%rip), %rcx      # 0x18448
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
cmpl $0x2, 0x18(%rax)
je 0x12f3c
movl -0x2c(%rbp), %esi
movq -0x128(%rbp), %rdx
xorl %edi, %edi
movl $0x53, %ecx
callq 0x12720
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x12f3a
movq -0x38(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x110(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x128(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x128(%rbp)
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x98(%rbp)
je 0x12ec2
leaq -0x100(%rbp), %rdi
movq -0x98(%rbp), %rsi
leaq -0x128(%rbp), %rdx
callq 0x12c10
movl %eax, -0x11c(%rbp)
jmp 0x12ef9
cmpl $0x0, 0x10(%rbp)
je 0x12eec
cmpl $0x2, -0x28(%rbp)
jg 0x12ed8
movq -0x38(%rbp), %rax
cmpl $0x2, 0x38(%rax)
jg 0x12ee2
movq -0x38(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x12eec
movl -0x28(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x38(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x11c(%rbp)
movl -0x11c(%rbp), %eax
cmpl -0x28(%rbp), %eax
je 0x12f10
movq 0x18(%rbp), %rax
movl $0x0, (%rax)
jmp 0x12f1a
movq 0x18(%rbp), %rax
movl $0x1, (%rax)
leaq -0xd0(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movq -0x38(%rbp), %rcx
movl 0x20(%rbp), %r8d
callq 0x12520
jmp 0x130c9
jmp 0x12f3c
movl -0x2c(%rbp), %edi
leaq -0x104(%rbp), %rsi
callq 0x12160
movq %rax, -0x110(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, 0x18(%rax)
jne 0x12f8e
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x12f8e
leaq 0x5252(%rip), %rax      # 0x181c0
movq %rax, -0xa0(%rbp)
movl -0x104(%rbp), %eax
movl %eax, %ecx
movq -0x128(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x128(%rbp)
movb $0x0, -0xd0(%rbp)
movq 0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0x130c9
movl -0x2c(%rbp), %edi
callq 0x12220
movq %rax, -0x110(%rbp)
movq 0x18(%rbp), %rax
movl $0x1, (%rax)
leaq -0xd0(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movl 0x20(%rbp), %r8d
xorl %eax, %eax
movl %eax, %ecx
callq 0x12520
jmp 0x130c9
movl -0x2c(%rbp), %eax
movl %eax, -0x88(%rbp)
leaq 0xd193(%rip), %rax      # 0x20180
movq (%rax), %rsi
leaq -0x88(%rbp), %rdi
leaq 0x18d2(%rip), %rdx      # 0x148d0
xorl %eax, %eax
movl %eax, %ecx
callq 0x16c50
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
jne 0x13024
leaq 0x54e3(%rip), %rdi      # 0x18502
callq 0x16e00
movq -0x90(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x110(%rbp)
cmpl $0x0, 0x10(%rbp)
je 0x13069
cmpl $0x2, -0x28(%rbp)
jg 0x1304f
movq -0x90(%rbp), %rax
cmpl $0x2, 0x2c(%rax)
jg 0x1305c
movq -0x90(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jne 0x13069
movl -0x28(%rbp), %ecx
movq -0x90(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x90(%rbp), %rax
movl 0x2c(%rax), %eax
cmpl -0x28(%rbp), %eax
je 0x13084
movq 0x18(%rbp), %rax
movl $0x0, (%rax)
jmp 0x1308e
movq 0x18(%rbp), %rax
movl $0x1, (%rax)
leaq -0xd0(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movq -0x90(%rbp), %rcx
movl 0x20(%rbp), %r8d
callq 0x12520
jmp 0x130c9
leaq -0xd0(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movl 0x20(%rbp), %r8d
xorl %eax, %eax
movl %eax, %ecx
callq 0x12520
cmpq $0x0, -0x128(%rbp)
jne 0x13111
movq -0x8(%rbp), %rdi
movq -0xa0(%rbp), %rdx
leaq -0xd0(%rbp), %rcx
movq -0x110(%rbp), %r8
leaq -0x100(%rbp), %r9
movq -0x118(%rbp), %rax
leaq 0x5414(%rip), %rsi      # 0x18515
movq %rax, (%rsp)
movb $0x0, %al
callq 0x9190
jmp 0x131fd
cmpq $0x0, -0x128(%rbp)
jle 0x13124
movb $0x2b, -0x11d(%rbp)
jmp 0x1313b
movb $0x2d, -0x11d(%rbp)
xorl %eax, %eax
subq -0x128(%rbp), %rax
movq %rax, -0x128(%rbp)
cmpq $0x7fff, -0x128(%rbp) # imm = 0x7FFF
jg 0x13155
cmpq $-0x8000, -0x128(%rbp) # imm = 0x8000
jge 0x131a9
movq -0x8(%rbp), %rdi
movq -0xa0(%rbp), %rdx
leaq -0xd0(%rbp), %rcx
movq -0x110(%rbp), %r8
leaq -0x100(%rbp), %r9
movsbl -0x11d(%rbp), %r11d
movq -0x128(%rbp), %r10
movq -0x118(%rbp), %rax
leaq 0x538e(%rip), %rsi      # 0x18520
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x9190
jmp 0x131fb
movq -0x8(%rbp), %rdi
movq -0xa0(%rbp), %rdx
leaq -0xd0(%rbp), %rcx
movq -0x110(%rbp), %r8
leaq -0x100(%rbp), %r9
movsbl -0x11d(%rbp), %r11d
movq -0x128(%rbp), %r10
movq -0x118(%rbp), %rax
leaq 0x5350(%rip), %rsi      # 0x18536
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x9190
jmp 0x131fd
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopw %cs:(%rax,%rax)