// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/crossassemblers/macro11/assemble_aux.c
// Function: mode_extension
void mode_extension(
    TEXT_RLD *tr,
    ADDR_MODE *mode,
    STREAM *str)
{
    EX_TREE        *value = mode->offset;
    SYMBOL         *sym;
    unsigned        offset;

    /* Also frees the mode. */

    if (value == NULL) {
        free_addr_mode(mode);
        return;
    }

    if (value->type == EX_LIT) {
        if (mode->rel)                 /* PC-relative? */
            store_displaced_word(str, tr, 2, value->data.lit);
        else
            store_word(str, tr, 2, value->data.lit);    /* Just a
                                                           known
                                                           value. */
    } else if (express_sym_offset(value, &sym, &offset)) {
        if ((sym->flags & (SYMBOLFLAG_GLOBAL | SYMBOLFLAG_DEFINITION)) == SYMBOLFLAG_GLOBAL) {
            /* Reference to a global symbol. */
            /* Global symbol plus offset */
            if (mode->rel)
                store_global_displaced_offset_word(str, tr, 2, offset, sym->label);
            else
                store_global_offset_word(str, tr, 2, offset, sym->label);
        } else {
            /* Relative to non-external symbol. */
            if (current_pc->section == sym->section) {
                /* In the same section */
                if (mode->rel) {
                    /* I can compute this myself. */
                    store_word(str, tr, 2, sym->value + offset - DOT - 2);
                } else
                    store_internal_word(str, tr, 2, sym->value + offset);
            } else {
                /* In a different section */
                if (mode->rel)
                    store_psect_displaced_offset_word(str, tr, 2, sym->value + offset, sym->section->label);
                else
                    store_psect_offset_word(str, tr, 2, sym->value + offset, sym->section->label);
            }
        }
    } else {
        /* Complex relocation */

        if (mode->rel)
            store_complex_displaced(str, tr, 2, mode->offset);
        else
            store_complex(str, tr, 2, mode->offset);
    }

    free_addr_mode(mode);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x8(%rsi), %rdi
testq %rdi, %rdi
je 0x646d
movq %rdx, %r15
cmpl $0x1, (%rdi)
jne 0x6221
cmpl $0x0, 0x4(%rbx)
movl 0x10(%rdi), %ebp
je 0x62ad
movq %r14, %rdi
movl $0x2, %esi
callq 0x5c47
leaq 0x11460(%rip), %r12     # 0x17648
movq (%r12), %rax
movl 0x8(%rax), %esi
leaq 0xa0be(%rip), %r8       # 0x102b4
movq %r15, %rdi
movl %ebp, %edx
movl $0x2, %ecx
callq 0x79dd
movq (%r12), %rsi
addq $0x8, %rsi
movq %r14, %rdi
movl $0x2, %edx
movl %ebp, %ecx
callq 0xcb1a
jmp 0x645f
leaq 0x8(%rsp), %rsi
leaq 0x4(%rsp), %rdx
callq 0x5f2d
testl %eax, %eax
je 0x62c4
movq 0x8(%rsp), %rcx
movl 0x10(%rcx), %eax
andl $0xa, %eax
cmpl $0x2, %eax
jne 0x634d
cmpl $0x0, 0x4(%rbx)
movl 0x4(%rsp), %ebp
movq (%rcx), %r12
je 0x63de
movq %r14, %rdi
movl $0x2, %esi
callq 0x5c47
leaq 0x113d7(%rip), %r13     # 0x17648
movq (%r13), %rax
movl 0x8(%rax), %esi
leaq 0xa6cd(%rip), %r8       # 0x1094c
movq %r15, %rdi
movl %ebp, %edx
movl $0x2, %ecx
callq 0x79dd
movq (%r13), %rsi
addq $0x8, %rsi
movq %r14, %rdi
movl $0x2, %edx
movl %ebp, %ecx
movq %r12, %r8
callq 0xceb8
jmp 0x645f
movq %r15, %rdi
movq %r14, %rsi
movl $0x2, %edx
movl %ebp, %ecx
callq 0x5ceb
jmp 0x645f
cmpl $0x0, 0x4(%rbx)
movq 0x8(%rbx), %r12
je 0x63c6
movq %r14, %rdi
movl $0x2, %esi
callq 0x5c47
movq %r12, %rdi
callq 0x5e0f
leaq 0x14(%rsp), %r13
movq %r13, %rdi
callq 0xd855
movq %r13, %rdi
movq %r12, %rsi
callq 0x5fbb
testl %eax, %eax
je 0x6411
leaq 0x1133a(%rip), %r12     # 0x17648
movq (%r12), %rax
movl 0x8(%rax), %esi
leaq 0xa605(%rip), %r8       # 0x10921
movq %r15, %rdi
xorl %edx, %edx
movl $0x2, %ecx
callq 0x79dd
movq (%r12), %rsi
addq $0x8, %rsi
leaq 0x14(%rsp), %rcx
movq %r14, %rdi
movl $0x2, %edx
xorl %r8d, %r8d
callq 0xdbd8
jmp 0x645f
leaq 0x112f4(%rip), %r13     # 0x17648
movq (%r13), %rax
movq 0x18(%rcx), %rsi
movl 0x4(%rbx), %edx
movl 0x8(%rcx), %ecx
movl 0x4(%rsp), %ebp
cmpq %rsi, 0x18(%rax)
je 0x63f5
addl %ecx, %ebp
movq (%rsi), %r12
testl %edx, %edx
je 0x6434
movq %r14, %rdi
movl $0x2, %esi
callq 0x5c47
movq (%r13), %rax
movl 0x8(%rax), %esi
leaq 0x9f1c(%rip), %r8       # 0x102b4
movq %r15, %rdi
movl %ebp, %edx
movl $0x2, %ecx
callq 0x79dd
movq (%r13), %rsi
addq $0x8, %rsi
movq %r14, %rdi
movl $0x2, %edx
movl %ebp, %ecx
movq %r12, %r8
callq 0xd6f1
jmp 0x645f
movq %r15, %rdi
movq %r14, %rsi
movl $0x2, %edx
movq %r12, %rcx
callq 0x65b6
jmp 0x645f
movq %r15, %rdi
movq %r14, %rsi
movl $0x2, %edx
movl %ebp, %ecx
movq %r12, %r8
callq 0x6487
jmp 0x645f
testl %edx, %edx
je 0x644b
addl %ebp, %ecx
subl 0x8(%rax), %ecx
addl $-0x2, %ecx
movq %r15, %rdi
movq %r14, %rsi
movl $0x2, %edx
jmp 0x62ba
leaq 0x9e9e(%rip), %rsi      # 0x102b6
movq %r15, %rdi
xorl %eax, %eax
callq 0x7b5a
movq %r15, %rdi
movq %r14, %rsi
movl $0x2, %edx
xorl %ecx, %ecx
jmp 0x62ba
movq %r15, %rdi
movq %r14, %rsi
movl $0x2, %edx
movl %ebp, %ecx
movq %r12, %r8
callq 0x654b
jmp 0x645f
addl %ecx, %ebp
movq %r15, %rdi
movq %r14, %rsi
movl $0x2, %edx
movl %ebp, %ecx
callq 0x64f2
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x646d
callq 0x6e73
movq $0x0, 0x8(%rbx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq