// File: /workspace/github_c_makefile_star2_O3/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 0x6a7a
movq %rdi, %rsi
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0xc348
leaq 0xf207(%rip), %rax      # 0x15b90
movq (%rax), %rsi
movq %rbx, %rdi
callq 0xc419
leaq 0xf1fd(%rip), %rax      # 0x15b98
movq (%rax), %rsi
testq %rsi, %rsi
je 0x69ad
leaq 0x20(%rsp), %rdi
callq 0xc4fa
leaq 0xf0bc(%rip), %r12      # 0x15a70
cmpl $0x0, (%r12)
jle 0x6a5f
xorl %r13d, %r13d
leaq 0x20(%rsp), %rbx
leaq 0x10cc2(%rip), %r14     # 0x17690
leaq 0x10(%rsp), %r15
leaq 0xe896(%rip), %rax      # 0x15270
movq (%rax,%r13,8), %rbp
movq (%rbp), %rsi
movl 0xc(%rbp), %edx
movl 0x14(%rbp), %ecx
movq %rbx, %rdi
callq 0xc4ed
movl %r13d, 0x18(%rbp)
movl $0x0, 0x10(%rbp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x9ef7
testq %rax, %rax
je 0x6a4f
movl 0x10(%rax), %ecx
testb $0x2, %cl
je 0x6a42
movq 0x18(%rax), %rdx
cmpq %rbp, %rdx
jne 0x6a42
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 0xc4e0
movq %r14, %rdi
movq %r15, %rsi
callq 0x9ea4
jmp 0x6a06
incq %r13
movslq (%r12), %rax
cmpq %rax, %r13
jl 0x69d3
leaq 0xf13a(%rip), %rax      # 0x15ba0
movq (%rax), %rdi
cmpl $0x1, (%rdi)
jne 0x6aaa
movl 0x10(%rdi), %edx
leaq 0x974c(%rip), %rsi      # 0x101c4
jmp 0x6ad0
leaq 0xefef(%rip), %rax      # 0x15a70
movslq (%rax), %rax
testq %rax, %rax
jle 0x6aef
xorl %ecx, %ecx
leaq 0xe7de(%rip), %rdx      # 0x15270
movq (%rdx,%rcx,8), %rsi
movl %ecx, 0x18(%rsi)
movl $0x0, 0x10(%rsi)
incq %rcx
cmpq %rcx, %rax
jne 0x6a92
jmp 0x6aef
leaq 0x8(%rsp), %rsi
leaq 0x4(%rsp), %rdx
callq 0x5e3d
testl %eax, %eax
je 0x6b01
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rcx
movq (%rcx), %rsi
movl 0x4(%rsp), %edx
addl 0x8(%rax), %edx
leaq 0x20(%rsp), %rdi
callq 0xc4ce
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0xc35c
movq %rbx, %rdi
callq 0xc518
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x97a2(%rip), %rsi      # 0x102aa
xorl %edi, %edi
xorl %eax, %eax
callq 0x7a34
jmp 0x6ada
nop