// File: /workspace/github_c_makefile_star2_O2/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 0x5ef1
movq %rdx, %r15
cmpl $0x1, (%rdi)
jne 0x5f0a
cmpl $0x0, 0x4(%rbx)
movl 0x10(%rdi), %ebp
je 0x5f99
pushq $0x2
popq %r12
movq %r14, %rdi
movl %r12d, %esi
callq 0x594d
leaq 0x1178c(%rip), %r13     # 0x17648
movq (%r13), %rax
movl 0x8(%rax), %esi
leaq 0x942e(%rip), %r8       # 0xf2f8
movq %r15, %rdi
movl %ebp, %edx
movl %r12d, %ecx
callq 0x7517
movq (%r13), %rsi
addq $0x8, %rsi
movq %r14, %rdi
movl %r12d, %edx
movl %ebp, %ecx
callq 0xbe21
jmp 0x612f
movq %rbx, %rdi
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5a8f
leaq 0x8(%rsp), %rsi
leaq 0x4(%rsp), %rdx
callq 0x5c07
testl %eax, %eax
je 0x5fae
movq 0x8(%rsp), %rcx
movl 0x10(%rcx), %eax
andl $0xa, %eax
cmpl $0x2, %eax
jne 0x6032
cmpl $0x0, 0x4(%rbx)
movl 0x4(%rsp), %ebp
movq (%rcx), %r12
je 0x60b8
pushq $0x2
popq %r13
movq %r14, %rdi
movl %r13d, %esi
callq 0x594d
leaq 0x116ec(%rip), %rax     # 0x17648
movq (%rax), %rax
movl 0x8(%rax), %esi
leaq 0x9a3f(%rip), %r8       # 0xf9a8
movq %r15, %rdi
movl %ebp, %edx
movl %r13d, %ecx
callq 0x7517
leaq 0x116cb(%rip), %rax     # 0x17648
movq (%rax), %rsi
addq $0x8, %rsi
movq %r14, %rdi
movl %r13d, %edx
movl %ebp, %ecx
movq %r12, %r8
callq 0xbfb1
jmp 0x612f
pushq $0x2
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %ecx
callq 0x59c5
jmp 0x612f
cmpl $0x0, 0x4(%rbx)
movq 0x8(%rbx), %r12
je 0x60a5
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0x594d
movq %r12, %rdi
callq 0x5ad5
leaq 0x14(%rsp), %r13
movq %r13, %rdi
callq 0xc44b
movq %r13, %rdi
movq %r12, %rsi
callq 0x5c93
testl %eax, %eax
je 0x60e7
leaq 0x11652(%rip), %r12     # 0x17648
movq (%r12), %rax
movl 0x8(%rax), %esi
leaq 0x9979(%rip), %r8       # 0xf97d
pushq $0x2
popq %rbp
movq %r15, %rdi
xorl %edx, %edx
movl %ebp, %ecx
callq 0x7517
movq (%r12), %rsi
addq $0x8, %rsi
leaq 0x14(%rsp), %rcx
movq %r14, %rdi
movl %ebp, %edx
xorl %r8d, %r8d
callq 0xc6d4
jmp 0x612f
leaq 0x1160f(%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 0x60cd
addl %ecx, %ebp
movq (%rsi), %r12
testl %edx, %edx
je 0x6108
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0x594d
movq (%r13), %rax
movl 0x8(%rax), %esi
leaq 0x9281(%rip), %r8       # 0xf2f8
movq %r15, %rdi
movl %ebp, %edx
pushq $0x2
popq %r15
movl %r15d, %ecx
callq 0x7517
movq (%r13), %rsi
addq $0x8, %rsi
movq %r14, %rdi
movl %r15d, %edx
movl %ebp, %ecx
movq %r12, %r8
callq 0xc3c0
jmp 0x612f
pushq $0x2
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rcx
callq 0x6278
jmp 0x612f
pushq $0x2
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %ecx
movq %r12, %r8
callq 0x6149
jmp 0x612f
testl %edx, %edx
je 0x611d
addl %ebp, %ecx
subl 0x8(%rax), %ecx
addl $-0x2, %ecx
pushq $0x2
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
jmp 0x5fa4
leaq 0x920c(%rip), %rsi      # 0xf2fa
movq %r15, %rdi
xorl %eax, %eax
callq 0x7668
pushq $0x2
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
jmp 0x5fa4
pushq $0x2
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %ecx
movq %r12, %r8
callq 0x620d
jmp 0x612f
addl %ecx, %ebp
pushq $0x2
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %ecx
callq 0x61b4
movq %rbx, %rdi
callq 0x5a8f
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq