// File: /workspace/github_c_makefile_star2_O1/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 0x6b77
movq %rdi, %rsi
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0xc5b0
leaq 0xf10a(%rip), %rax      # 0x15b90
movq (%rax), %rsi
movq %rbx, %rdi
callq 0xc681
leaq 0xf100(%rip), %rax      # 0x15b98
movq (%rax), %rsi
testq %rsi, %rsi
je 0x6aaa
leaq 0x20(%rsp), %rdi
callq 0xc762
leaq 0xefbf(%rip), %r12      # 0x15a70
cmpl $0x0, (%r12)
jle 0x6b5c
xorl %r13d, %r13d
leaq 0x20(%rsp), %rbx
leaq 0x10bc5(%rip), %r14     # 0x17690
leaq 0x10(%rsp), %r15
leaq 0xe799(%rip), %rax      # 0x15270
movq (%rax,%r13,8), %rbp
movq (%rbp), %rsi
movl 0xc(%rbp), %edx
movl 0x14(%rbp), %ecx
movq %rbx, %rdi
callq 0xc755
movl %r13d, 0x18(%rbp)
movl $0x0, 0x10(%rbp)
movq %r14, %rdi
movq %r15, %rsi
callq 0xa0bb
testq %rax, %rax
je 0x6b4c
movl 0x10(%rax), %ecx
testb $0x2, %cl
je 0x6b3f
movq 0x18(%rax), %rdx
cmpq %rbp, %rdx
jne 0x6b3f
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 0xc748
movq %r14, %rdi
movq %r15, %rsi
callq 0xa064
jmp 0x6b03
incq %r13
movslq (%r12), %rax
cmpq %rax, %r13
jl 0x6ad0
leaq 0xf03d(%rip), %rax      # 0x15ba0
movq (%rax), %rdi
cmpl $0x1, (%rdi)
jne 0x6ba7
movl 0x10(%rdi), %edx
leaq 0x9636(%rip), %rsi      # 0x101ab
jmp 0x6bcd
leaq 0xeef2(%rip), %rax      # 0x15a70
movslq (%rax), %rax
testq %rax, %rax
jle 0x6bec
xorl %ecx, %ecx
leaq 0xe6e1(%rip), %rdx      # 0x15270
movq (%rdx,%rcx,8), %rsi
movl %ecx, 0x18(%rsi)
movl $0x0, 0x10(%rsi)
incq %rcx
cmpq %rcx, %rax
jne 0x6b8f
jmp 0x6bec
leaq 0x8(%rsp), %rsi
leaq 0x4(%rsp), %rdx
callq 0x5f2d
testl %eax, %eax
je 0x6bfe
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rcx
movq (%rcx), %rsi
movl 0x4(%rsp), %edx
addl 0x8(%rax), %edx
leaq 0x20(%rsp), %rdi
callq 0xc736
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0xc5c4
movq %rbx, %rdi
callq 0xc780
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x968d(%rip), %rsi      # 0x10292
xorl %edi, %edi
xorl %eax, %eax
callq 0x7b5a
jmp 0x6bd7