// File: /workspace/github_c_makefile_star2_O3/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 0x637d
movq %rdx, %r15
cmpl $0x1, (%rdi)
jne 0x6131
cmpl $0x0, 0x4(%rbx)
movl 0x10(%rdi), %ebp
je 0x61bd
movq %r14, %rdi
movl $0x2, %esi
callq 0x5b6b
leaq 0x11550(%rip), %r12     # 0x17648
movq (%r12), %rax
movl 0x8(%rax), %esi
leaq 0xa1c6(%rip), %r8       # 0x102cc
movq %r15, %rdi
movl %ebp, %edx
movl $0x2, %ecx
callq 0x78b7
movq (%r12), %rsi
addq $0x8, %rsi
movq %r14, %rdi
movl $0x2, %edx
movl %ebp, %ecx
callq 0xc8bb
jmp 0x636f
leaq 0x8(%rsp), %rsi
leaq 0x4(%rsp), %rdx
callq 0x5e3d
testl %eax, %eax
je 0x61d4
movq 0x8(%rsp), %rcx
movl 0x10(%rcx), %eax
andl $0xa, %eax
cmpl $0x2, %eax
jne 0x625d
cmpl $0x0, 0x4(%rbx)
movl 0x4(%rsp), %ebp
movq (%rcx), %r12
je 0x62ee
movq %r14, %rdi
movl $0x2, %esi
callq 0x5b6b
leaq 0x114c7(%rip), %r13     # 0x17648
movq (%r13), %rax
movl 0x8(%rax), %esi
leaq 0xa7c9(%rip), %r8       # 0x10958
movq %r15, %rdi
movl %ebp, %edx
movl $0x2, %ecx
callq 0x78b7
movq (%r13), %rsi
addq $0x8, %rsi
movq %r14, %rdi
movl $0x2, %edx
movl %ebp, %ecx
movq %r12, %r8
callq 0xcc73
jmp 0x636f
movq %r15, %rdi
movq %r14, %rsi
movl $0x2, %edx
movl %ebp, %ecx
callq 0x5be3
jmp 0x636f
cmpl $0x0, 0x4(%rbx)
movq 0x8(%rbx), %r12
je 0x62d6
movq %r14, %rdi
movl $0x2, %esi
callq 0x5b6b
movq %r12, %rdi
callq 0x5cfe
leaq 0x14(%rsp), %r13
movq %r13, %rdi
callq 0xd623
movq %r13, %rdi
movq %r12, %rsi
callq 0x5ecb
testl %eax, %eax
je 0x6321
leaq 0x1142a(%rip), %r12     # 0x17648
movq (%r12), %rax
movl 0x8(%rax), %esi
leaq 0xa701(%rip), %r8       # 0x1092d
movq %r15, %rdi
xorl %edx, %edx
movl $0x2, %ecx
callq 0x78b7
movq (%r12), %rsi
addq $0x8, %rsi
leaq 0x14(%rsp), %rcx
movq %r14, %rdi
movl $0x2, %edx
xorl %r8d, %r8d
callq 0xd92a
jmp 0x636f
leaq 0x113e4(%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 0x6305
addl %ecx, %ebp
movq (%rsi), %r12
testl %edx, %edx
je 0x6344
movq %r14, %rdi
movl $0x2, %esi
callq 0x5b6b
movq (%r13), %rax
movl 0x8(%rax), %esi
leaq 0xa024(%rip), %r8       # 0x102cc
movq %r15, %rdi
movl %ebp, %edx
movl $0x2, %ecx
callq 0x78b7
movq (%r13), %rsi
addq $0x8, %rsi
movq %r14, %rdi
movl $0x2, %edx
movl %ebp, %ecx
movq %r12, %r8
callq 0xd4be
jmp 0x636f
movq %r15, %rdi
movq %r14, %rsi
movl $0x2, %edx
movq %r12, %rcx
callq 0x64c6
jmp 0x636f
movq %r15, %rdi
movq %r14, %rsi
movl $0x2, %edx
movl %ebp, %ecx
movq %r12, %r8
callq 0x6397
jmp 0x636f
testl %edx, %edx
je 0x635b
addl %ebp, %ecx
subl 0x8(%rax), %ecx
addl $-0x2, %ecx
movq %r15, %rdi
movq %r14, %rsi
movl $0x2, %edx
jmp 0x61ca
leaq 0x9fa6(%rip), %rsi      # 0x102ce
movq %r15, %rdi
xorl %eax, %eax
callq 0x7a34
movq %r15, %rdi
movq %r14, %rsi
movl $0x2, %edx
xorl %ecx, %ecx
jmp 0x61ca
movq %r15, %rdi
movq %r14, %rsi
movl $0x2, %edx
movl %ebp, %ecx
movq %r12, %r8
callq 0x645b
jmp 0x636f
addl %ecx, %ebp
movq %r15, %rdi
movq %r14, %rsi
movl $0x2, %edx
movl %ebp, %ecx
callq 0x6402
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x637d
callq 0x6d77
movq $0x0, 0x8(%rbx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq