// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/crossassemblers/macro11/assemble_aux.c
// Function: write_globals
void write_globals(
    FILE *obj)
{
    GSD             gsd;
    SYMBOL         *sym;
    SECTION        *psect;
    SYMBOL_ITER     sym_iter;
    int             isect;

    if (obj == NULL) {
        for (isect = 0; isect < sector; isect++) {
            psect = sections[isect];

            psect->sector = isect;     /* Assign it a sector */
            psect->pc = 0;             /* Reset its PC for second pass */
        }
        return;                        /* Nothing more to do if no OBJ file. */
    }

    gsd_init(&gsd, obj);

    gsd_mod(&gsd, module_name);

    if (ident)
        gsd_ident(&gsd, ident);

    /* write out each PSECT with it's global stuff */
    /* Sections must be written out in the order that they
       appear in the assembly file.  */
    for (isect = 0; isect < sector; isect++) {
        psect = sections[isect];

        gsd_psect(&gsd, psect->label, psect->flags, psect->size);
        psect->sector = isect;         /* Assign it a sector */
        psect->pc = 0;                 /* Reset its PC for second pass */

        sym = first_sym(&symbol_st, &sym_iter);
        while (sym) {
            if ((sym->flags & SYMBOLFLAG_GLOBAL) && sym->section == psect) {
                gsd_global(&gsd, sym->label,
                           (sym->
                            flags & SYMBOLFLAG_DEFINITION ? GLOBAL_DEF : 0) | ((sym->
                                                                                flags & SYMBOLFLAG_WEAK) ?
                                                                               GLOBAL_WEAK : 0)
                           | ((sym->section->flags & PSECT_REL) ? GLOBAL_REL : 0) | 0100,
                           /* Looks undefined, but add it in anyway */
                           sym->value);
            }
            sym = next_sym(&symbol_st, &sym_iter);
        }
    }

    /* Now write out the transfer address */
    if (xfer_address->type == EX_LIT) {
        gsd_xfer(&gsd, ". ABS.", xfer_address->data.lit);
    } else {
        SYMBOL         *lsym;
        unsigned        offset;

        if (!express_sym_offset(xfer_address, &lsym, &offset)) {
            report(NULL, "Illegal program transfer address\n");
        } else {
            gsd_xfer(&gsd, lsym->section->label, lsym->value + offset);
        }
    }

    gsd_flush(&gsd);

    gsd_end(&gsd);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
testq %rdi, %rdi
je 0x681b
movq %rdi, %rsi
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0xb9d0
leaq 0xf45d(%rip), %rax      # 0x15b90
movq (%rax), %rsi
movq %rbx, %rdi
callq 0xba9e
leaq 0xf453(%rip), %rax      # 0x15b98
movq (%rax), %rsi
testq %rsi, %rsi
je 0x6757
leaq 0x20(%rsp), %rdi
callq 0xbb71
xorl %r12d, %r12d
leaq 0xf30f(%rip), %r13      # 0x15a70
leaq 0x20(%rsp), %rbx
leaq 0x10f23(%rip), %r14     # 0x17690
leaq 0x10(%rsp), %r15
movslq (%r13), %rax
cmpq %rax, %r12
jge 0x6800
leaq 0xeaea(%rip), %rax      # 0x15270
movq (%rax,%r12,8), %rbp
movq (%rbp), %rsi
movl 0xc(%rbp), %edx
movl 0x14(%rbp), %ecx
movq %rbx, %rdi
callq 0xbb66
movl %r12d, 0x18(%rbp)
andl $0x0, 0x10(%rbp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x97be
testq %rax, %rax
je 0x67f8
movl 0x10(%rax), %ecx
testb $0x2, %cl
je 0x67eb
movq 0x18(%rax), %rdx
cmpq %rbp, %rdx
jne 0x67eb
movq (%rax), %rsi
movl %ecx, %edi
andl $0x8, %edi
shrl $0x2, %ecx
andl $0x1, %ecx
orl %edi, %ecx
movl 0xc(%rdx), %edx
andl $0x20, %edx
addl %ecx, %edx
addl $0x40, %edx
movl 0x8(%rax), %ecx
movq %rbx, %rdi
callq 0xbb5b
movq %r14, %rdi
movq %r15, %rsi
callq 0x9789
jmp 0x67af
incq %r12
jmp 0x6772
leaq 0xf399(%rip), %rax      # 0x15ba0
movq (%rax), %rdi
cmpl $0x1, (%rdi)
jne 0x6847
movl 0x10(%rdi), %edx
leaq 0x89ab(%rip), %rsi      # 0xf1c4
jmp 0x686d
leaq 0xf24e(%rip), %rax      # 0x15a70
movl (%rax), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
leaq 0xea3e(%rip), %rdx      # 0x15270
cmpq %rcx, %rax
je 0x688c
movq (%rdx,%rcx,8), %rsi
movl %ecx, 0x18(%rsi)
andl $0x0, 0x10(%rsi)
incq %rcx
jmp 0x6832
leaq 0x8(%rsp), %rsi
leaq 0x4(%rsp), %rdx
callq 0x5c07
testl %eax, %eax
je 0x689e
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rcx
movq (%rcx), %rsi
movl 0x4(%rsp), %edx
addl 0x8(%rax), %edx
leaq 0x20(%rsp), %rdi
callq 0xbb4d
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0xb9e4
movq %rbx, %rdi
callq 0xbb8b
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8a31(%rip), %rsi      # 0xf2d6
xorl %edi, %edi
xorl %eax, %eax
callq 0x7668
jmp 0x6877