// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/crossassemblers/macro1/macro1.c
// Function: read_symbols
void
read_symbols(char *fname)
{
    FILE *f;

    f = fopen(fname, "rb");
    if (!f) {
	perror(fname);
	exit(1);
    }

    /* skip loader */
    for (;;) {
	WORD32 w;

	w = getw(f);
	if (w == -1)
	    goto err;			/* XXX complain? */
	if ((w & OP_CODE) == JMP)
	    break;
	if ((w & OP_CODE) != DIO)
	    goto err;			/* XXX complain? */
	w = getw(f);
	if (w == -1)
	    goto err;			/* XXX complain? */
    }


    /* XXX should push block reader down into a co-routine */
    for (;;) {
	WORD32 start, end, sum;

	start = getw(f);
	if ((start & OP_CODE) == JMP) {
	    fclose(f);
	    return;
	}

	if (start == -1 || (start & OP_CODE) != DIO)
	    goto err;

	end = getw(f);
	if (end == -1 || (end & OP_CODE) != DIO)
	    goto err;			/* XXX complain? */

	sum = start + end;
	while (start < end) {
	    WORD32 sym, val;
	    sym = getw(f);
	    if (sym == -1)
		goto err;
	    sum += sym;
	    start++;
	    /* XXX handle block boundaries? */
	    if (start >= end)
		goto err;
	    val = getw(f);
	    if (val == -1)
		goto err;
	    /*printf("%06o %06o\n", sym, val);*/
	    addsym(sym, val);
	    sum += val;
	    start++;
	}
	start = getw(f);		/* eat checksum XXX verify? */
	if (start == -1)
	    goto err;
	/* roll over all the overflows at once */
	if (sum & ~0777777) {
	    sum = (sum & 0777777) + (sum >> 18);
	    if (sum & 01000000)			/* one more time */
		sum++;
	}
	if (start != sum)
	    goto err;
    }
err:
    fprintf(stderr, "error reading symbol file %s\n", fname);
    exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x4d97(%rip), %rsi      # 0x864e
callq 0x2150
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x38da
movq -0x8(%rbp), %rdi
callq 0x2160
movl $0x1, %edi
callq 0x2190
jmp 0x38dc
movq -0x10(%rbp), %rdi
callq 0x3750
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x38f3
jmp 0x3a72
movl -0x14(%rbp), %eax
andl $0x3e000, %eax          # imm = 0x3E000
cmpl $0x30000, %eax          # imm = 0x30000
jne 0x3904
jmp 0x3931
movl -0x14(%rbp), %eax
andl $0x3e000, %eax          # imm = 0x3E000
cmpl $0x1a000, %eax          # imm = 0x1A000
je 0x3918
jmp 0x3a72
movq -0x10(%rbp), %rdi
callq 0x3750
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x392f
jmp 0x3a72
jmp 0x38dc
jmp 0x3933
movq -0x10(%rbp), %rdi
callq 0x3750
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
andl $0x3e000, %eax          # imm = 0x3E000
cmpl $0x30000, %eax          # imm = 0x30000
jne 0x395d
movq -0x10(%rbp), %rdi
callq 0x2080
addq $0x30, %rsp
popq %rbp
retq
cmpl $-0x1, -0x18(%rbp)
je 0x3972
movl -0x18(%rbp), %eax
andl $0x3e000, %eax          # imm = 0x3E000
cmpl $0x1a000, %eax          # imm = 0x1A000
je 0x3977
jmp 0x3a72
movq -0x10(%rbp), %rdi
callq 0x3750
movl %eax, -0x1c(%rbp)
cmpl $-0x1, -0x1c(%rbp)
je 0x3998
movl -0x1c(%rbp), %eax
andl $0x3e000, %eax          # imm = 0x3E000
cmpl $0x1a000, %eax          # imm = 0x1A000
je 0x399d
jmp 0x3a72
movl -0x18(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x3a17
movq -0x10(%rbp), %rdi
callq 0x3750
movl %eax, -0x24(%rbp)
cmpl $-0x1, -0x24(%rbp)
jne 0x39c5
jmp 0x3a72
movl -0x24(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jl 0x39e4
jmp 0x3a72
movq -0x10(%rbp), %rdi
callq 0x3750
movl %eax, -0x28(%rbp)
cmpl $-0x1, -0x28(%rbp)
jne 0x39f8
jmp 0x3a72
movl -0x24(%rbp), %edi
movl -0x28(%rbp), %esi
callq 0x3820
movl -0x28(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x39a6
movq -0x10(%rbp), %rdi
callq 0x3750
movl %eax, -0x18(%rbp)
cmpl $-0x1, -0x18(%rbp)
jne 0x3a2b
jmp 0x3a72
movl -0x20(%rbp), %eax
andl $0xfffc0000, %eax       # imm = 0xFFFC0000
cmpl $0x0, %eax
je 0x3a63
movl -0x20(%rbp), %eax
andl $0x3ffff, %eax          # imm = 0x3FFFF
movl -0x20(%rbp), %ecx
sarl $0x12, %ecx
addl %ecx, %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
andl $0x40000, %eax          # imm = 0x40000
cmpl $0x0, %eax
je 0x3a61
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x3a63
movl -0x18(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x3a6d
jmp 0x3a72
jmp 0x3933
movq 0x757f(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x4bca(%rip), %rsi      # 0x8651
movb $0x0, %al
callq 0x2110
movl $0x1, %edi
callq 0x2190
nopl (%rax,%rax)