// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x8cee
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
leaq 0x10dc3(%rip), %rcx     # 0x19a60
cmpl (%rcx), %eax
jge 0x8ce9
movslq -0xb4(%rbp), %rcx
leaq 0x105b1(%rip), %rax     # 0x19260
movq (%rax,%rcx,8), %rax
movq %rax, -0xa0(%rbp)
movl -0xb4(%rbp), %ecx
movq -0xa0(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0xa0(%rbp), %rax
movl $0x0, 0x10(%rax)
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x8c90
jmp 0x8f62
movq -0x8(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x112b0
leaq 0x10eab(%rip), %rax     # 0x19bb0
movq (%rax), %rsi
leaq -0x90(%rbp), %rdi
callq 0x11490
leaq 0x10e9d(%rip), %rax     # 0x19bb8
cmpq $0x0, (%rax)
je 0x8d37
leaq 0x10e90(%rip), %rax     # 0x19bb8
movq (%rax), %rsi
leaq -0x90(%rbp), %rdi
callq 0x11760
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
leaq 0x10d12(%rip), %rcx     # 0x19a60
cmpl (%rcx), %eax
jge 0x8eb7
movslq -0xb4(%rbp), %rcx
leaq 0x104fc(%rip), %rax     # 0x19260
movq (%rax,%rcx,8), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq (%rax), %rsi
movq -0xa0(%rbp), %rax
movl 0xc(%rax), %edx
movq -0xa0(%rbp), %rax
movl 0x14(%rax), %ecx
leaq -0x90(%rbp), %rdi
callq 0x11720
movl -0xb4(%rbp), %ecx
movq -0xa0(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0xa0(%rbp), %rax
movl $0x0, 0x10(%rax)
leaq 0x128f2(%rip), %rdi     # 0x1b6b0
leaq -0xb0(%rbp), %rsi
callq 0xe150
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x98(%rbp)
je 0x8ea1
movq -0x98(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x8e82
movq -0x98(%rbp), %rax
movq 0x18(%rax), %rax
cmpq -0xa0(%rbp), %rax
jne 0x8e82
movq -0x98(%rbp), %rax
movq (%rax), %rsi
movq -0x98(%rbp), %rax
movl 0x10(%rax), %ecx
andl $0x8, %ecx
xorl %edx, %edx
movl $0x8, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edx
movq -0x98(%rbp), %rax
movl 0x10(%rax), %edi
andl $0x4, %edi
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edi
cmovnel %ecx, %eax
orl %eax, %edx
movq -0x98(%rbp), %rax
movq 0x18(%rax), %rax
movl 0xc(%rax), %edi
andl $0x20, %edi
xorl %eax, %eax
movl $0x20, %ecx
cmpl $0x0, %edi
cmovnel %ecx, %eax
orl %eax, %edx
orl $0x40, %edx
movq -0x98(%rbp), %rax
movl 0x8(%rax), %ecx
leaq -0x90(%rbp), %rdi
callq 0x116e0
leaq 0x12827(%rip), %rdi     # 0x1b6b0
leaq -0xb0(%rbp), %rsi
callq 0xe0c0
movq %rax, -0x98(%rbp)
jmp 0x8dd1
jmp 0x8ea3
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x8d41
leaq 0x10d02(%rip), %rax     # 0x19bc0
movq (%rax), %rax
cmpl $0x1, (%rax)
jne 0x8ee8
leaq 0x10cf3(%rip), %rax     # 0x19bc0
movq (%rax), %rax
movl 0x10(%rax), %edx
leaq -0x90(%rbp), %rdi
leaq 0xc362(%rip), %rsi      # 0x15243
callq 0x116a0
jmp 0x8f4a
leaq 0x10cd1(%rip), %rax     # 0x19bc0
movq (%rax), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0xc4(%rbp), %rdx
callq 0x7b20
cmpl $0x0, %eax
jne 0x8f1e
xorl %eax, %eax
movl %eax, %edi
leaq 0xc48d(%rip), %rsi      # 0x153a2
movb $0x0, %al
callq 0xa890
jmp 0x8f48
movq -0xc0(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rsi
movq -0xc0(%rbp), %rax
movl 0x8(%rax), %edx
addl -0xc4(%rbp), %edx
leaq -0x90(%rbp), %rdi
callq 0x116a0
jmp 0x8f4a
leaq -0x90(%rbp), %rdi
callq 0x112f0
leaq -0x90(%rbp), %rdi
callq 0x117d0
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax,%rax)