// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/crossassemblers/macro11/symbols.c
// Function: list_symbol_table
void list_symbol_table(
    void)
{
    SYMBOL_ITER iter;
    SYMBOL *sym;
    int skip_locals = 0;
    int longest_symbol = symbol_len;

    fprintf(lstfile,"\n\nSymbol table\n\n");

    /* Count the symbols in the table */
    int nsyms = 0;
    for (sym = first_sym(&symbol_st, &iter); sym != NULL; sym = next_sym(&symbol_st, &iter)) {
        if (skip_locals && sym->flags & SYMBOLFLAG_LOCAL) {
            continue;
        }
        nsyms++;
        int len = strlen(sym->label);
        if (len > longest_symbol) {
            longest_symbol = len;
        }
    }

    /* Sort them by name */
    SYMBOL **symbols = malloc(nsyms * sizeof (SYMBOL *));
    SYMBOL **symbolp = symbols;

    for (sym = first_sym(&symbol_st, &iter); sym != NULL; sym = next_sym(&symbol_st, &iter)) {
        if (skip_locals && sym->flags & SYMBOLFLAG_LOCAL) {
            continue;
        }
        *symbolp++ = sym;
    }

    qsort(symbols, nsyms, sizeof(SYMBOL *), symbol_compar);

    symbolp = symbols;

    /* Print the listing in NCOLS columns. */
    int ncols = (132 / (longest_symbol + 18));
    int nlines = (nsyms + ncols - 1) / ncols;
    int line;
    /*
     * DIRER$  004562RGX    006
     * ^       ^     ^      ^-- for R symbols: program segment number
     * |       |     +-- Flags: R = relocatable
     * |       |                G = global
     * |       |                X = implicit global
     * |       |                L = local
     * |       |                W = weak
     * |       +- value, ****** for if it was not a definition
     * +- label name
     */

    for (line = 0; line < nlines; line++) {
        int i;
        for (i = line; i < nsyms; i += nlines) {
            sym = symbols[i];

            fprintf(lstfile,"%-*s", longest_symbol, sym->label);
            fprintf(lstfile,"%c", (sym->section->flags & PSECT_REL) ? ' ' : '=');
            if (!(sym->flags & SYMBOLFLAG_DEFINITION)) {
                fprintf(lstfile,"******");
            } else {
                fprintf(lstfile,"%06o", sym->value & 0177777);
            }
            fprintf(lstfile,"%c", (sym->section->flags & PSECT_REL) ? 'R' : ' ');
            fprintf(lstfile,"%c", (sym->flags & SYMBOLFLAG_GLOBAL) ?  'G' : ' ');
            fprintf(lstfile,"%c", (sym->flags & SYMBOLFLAG_IMPLICIT_GLOBAL) ? 'X' : ' ');
            fprintf(lstfile,"%c", (sym->flags & SYMBOLFLAG_LOCAL) ?   'L' : ' ');
            fprintf(lstfile,"%c", (sym->flags & SYMBOLFLAG_WEAK) ?    'W' : ' ');
            if (sym->section->sector != 0) {
                fprintf(lstfile,"  %03d ", sym->section->sector);
            } else {
                fprintf(lstfile,"      ");
            }
        }
        fprintf(lstfile,"\n");
    }

    /* List sections */

    fprintf(lstfile,"\n\nProgram sections:\n\n");

    int i;
    for (i = 0; i < sector; i++) {
        list_section(sections[i]);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, -0x1c(%rbp)
movl 0x98b3(%rip), %eax      # 0x19ad8
movl %eax, -0x20(%rbp)
leaq 0xb451(%rip), %rax      # 0x1b680
movq (%rax), %rdi
leaq 0x597e(%rip), %rsi      # 0x15bb7
movb $0x0, %al
callq 0x21c0
movl $0x0, -0x24(%rbp)
leaq 0xb462(%rip), %rdi      # 0x1b6b0
leaq -0x10(%rbp), %rsi
callq 0xe150
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x102b7
cmpl $0x0, -0x1c(%rbp)
je 0x10279
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x10279
jmp 0x102a1
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x20c0
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
jle 0x1029f
movl -0x28(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x102a1
leaq 0xb408(%rip), %rdi      # 0x1b6b0
leaq -0x10(%rbp), %rsi
callq 0xe0c0
movq %rax, -0x18(%rbp)
jmp 0x1025b
movslq -0x24(%rbp), %rdi
shlq $0x3, %rdi
callq 0x2220
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq 0xb3d9(%rip), %rdi      # 0x1b6b0
leaq -0x10(%rbp), %rsi
callq 0xe150
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1032e
cmpl $0x0, -0x1c(%rbp)
je 0x10302
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x10302
jmp 0x10318
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x38(%rbp)
movq %rcx, (%rax)
leaq 0xb391(%rip), %rdi      # 0x1b6b0
leaq -0x10(%rbp), %rsi
callq 0xe0c0
movq %rax, -0x18(%rbp)
jmp 0x102e4
movq -0x30(%rbp), %rdi
movslq -0x24(%rbp), %rsi
movl $0x8, %edx
leaq 0x2de(%rip), %rcx       # 0x10620
callq 0x2090
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x20(%rbp), %ecx
addl $0x12, %ecx
movl $0x84, %eax
cltd
idivl %ecx
movl %eax, -0x3c(%rbp)
movl -0x24(%rbp), %eax
addl -0x3c(%rbp), %eax
subl $0x1, %eax
cltd
idivl -0x3c(%rbp)
movl %eax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x105ca
movl -0x44(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x105a4
movq -0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
leaq 0xb2d4(%rip), %rax      # 0x1b680
movq (%rax), %rdi
movl -0x20(%rbp), %edx
movq -0x18(%rbp), %rax
movq (%rax), %rcx
leaq 0x5808(%rip), %rsi      # 0x15bc8
movb $0x0, %al
callq 0x21c0
leaq 0xb2b2(%rip), %rax      # 0x1b680
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl 0xc(%rax), %ecx
andl $0x20, %ecx
movl $0x3d, %edx
movl $0x20, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edx
leaq 0x57d7(%rip), %rsi      # 0x15bcd
movb $0x0, %al
callq 0x21c0
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0x10426
leaq 0xb26d(%rip), %rax      # 0x1b680
movq (%rax), %rdi
leaq 0x57b3(%rip), %rsi      # 0x15bd0
movb $0x0, %al
callq 0x21c0
jmp 0x1044b
leaq 0xb253(%rip), %rax      # 0x1b680
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
leaq 0x5793(%rip), %rsi      # 0x15bd7
movb $0x0, %al
callq 0x21c0
leaq 0xb22e(%rip), %rax      # 0x1b680
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl 0xc(%rax), %ecx
andl $0x20, %ecx
movl $0x20, %edx
movl $0x52, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edx
leaq 0x5753(%rip), %rsi      # 0x15bcd
movb $0x0, %al
callq 0x21c0
leaq 0xb1f8(%rip), %rax      # 0x1b680
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %ecx
andl $0x2, %ecx
movl $0x20, %edx
movl $0x47, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edx
leaq 0x5721(%rip), %rsi      # 0x15bcd
movb $0x0, %al
callq 0x21c0
leaq 0xb1c6(%rip), %rax      # 0x1b680
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %ecx
andl $0x40, %ecx
movl $0x20, %edx
movl $0x58, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edx
leaq 0x56ef(%rip), %rsi      # 0x15bcd
movb $0x0, %al
callq 0x21c0
leaq 0xb194(%rip), %rax      # 0x1b680
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %ecx
andl $0x20, %ecx
movl $0x20, %edx
movl $0x4c, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edx
leaq 0x56bd(%rip), %rsi      # 0x15bcd
movb $0x0, %al
callq 0x21c0
leaq 0xb162(%rip), %rax      # 0x1b680
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %ecx
andl $0x4, %ecx
movl $0x20, %edx
movl $0x57, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edx
leaq 0x568b(%rip), %rsi      # 0x15bcd
movb $0x0, %al
callq 0x21c0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
cmpl $0x0, 0x18(%rax)
je 0x1057c
leaq 0xb122(%rip), %rax      # 0x1b680
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x18(%rax), %edx
leaq 0x5669(%rip), %rsi      # 0x15bdc
movb $0x0, %al
callq 0x21c0
jmp 0x10594
leaq 0xb0fd(%rip), %rax      # 0x1b680
movq (%rax), %rdi
leaq 0x5657(%rip), %rsi      # 0x15be4
movb $0x0, %al
callq 0x21c0
jmp 0x10596
movl -0x40(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x10389
leaq 0xb0d5(%rip), %rax      # 0x1b680
movq (%rax), %rdi
leaq 0x564a(%rip), %rsi      # 0x15bff
movb $0x0, %al
callq 0x21c0
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x10377
leaq 0xb0af(%rip), %rax      # 0x1b680
movq (%rax), %rdi
leaq 0x5610(%rip), %rsi      # 0x15beb
movb $0x0, %al
callq 0x21c0
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
leaq 0x946d(%rip), %rcx      # 0x19a60
cmpl (%rcx), %eax
jge 0x10616
movslq -0x4c(%rbp), %rcx
leaq 0x8c5e(%rip), %rax      # 0x19260
movq (%rax,%rcx,8), %rdi
callq 0x10660
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x105e9
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)