// File: /workspace/github_c_makefile_star2_O0/AK6DN[P]dec-utilities-for-pdp/d8tape/dasm.c
// Function: xrefs
static void
xrefs (int addr)
{
    int     i;
    int     eff;
    int     count;

    count = 0;
    for (i = 0; i < CORE_SIZE; i++) {
        if (core [i] < 0) {
            continue;
        }

        if (tags [i] & TAG_DATA) {
//printf ("+XREF ADDR %04o CHECK %04o IS DATA\n", addr, i);
            continue;
        }


        if ((core [i] & 07400) == 04000) {  // direct JMS
            eff = ea (i, core [i], NULL, NULL);
//printf ("+XREF ADDR %04o CHECK %04o %04o JMS EA %04o\n", addr, i, core [i], eff);
            if (eff == addr) {
                if (!count) {
                    printf ("/\tCalled from:\n/\t");
                }
                printf ("%04o ", i);
                count++;
                if ((count % 15) == 0) {
                    printf ("\n/\t");
                }
            }
        } else if ((core [i] & 07400) == 04400) {   // indirect JMS
            eff = ea (i, core [i], NULL, NULL);
//printf ("+XREF ADDR %04o CHECK %04o %04o JMS I EA %04o\n", addr, i, core [i], eff);
            if (tags [eff] & TAG_WRITABLE) {
                continue;
            }
//printf ("+XREF ADDR %04o CHECK %04o %04o JMS I is not writable\n", addr, i, core [i]);
            if (core [eff] < 0) {
                continue;
            }
//printf ("+XREF ADDR %04o CHECK %04o %04o JMS I has valid indirect value\n", addr, i, core [i]);
            if (core [eff] == addr) {
                if (!count) {
                    printf ("/\tCalled from:\n/\t");
                }
                printf ("%04o ", i);
                count++;
                if ((count % 15) == 0) {
                    printf ("\n/\t");
                }
            }
        }
    }
    if (count) {
        printf ("\n");
        printf ("/\tTotal %04o (%d) calls\n", count, count);
    } else {
        printf ("/\tNever called\n");
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
movl $0x0, -0x10(%rbp)
movl $0x0, -0x8(%rbp)
cmpl $0x1000, -0x8(%rbp)     # imm = 0x1000
jge 0x5ea9
movslq -0x8(%rbp), %rcx
leaq 0x925f(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
jge 0x5d0f
jmp 0x5e9b
movslq -0x8(%rbp), %rcx
leaq 0xb246(%rip), %rax      # 0x10f60
movzwl (%rax,%rcx,2), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x5d2b
jmp 0x5e9b
movslq -0x8(%rbp), %rcx
leaq 0x922a(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %eax
andl $0xf00, %eax            # imm = 0xF00
cmpl $0x800, %eax            # imm = 0x800
jne 0x5dc2
movl -0x8(%rbp), %edi
movslq -0x8(%rbp), %rcx
leaq 0x920c(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x5c40
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x4(%rbp), %eax
jne 0x5dbd
cmpl $0x0, -0x10(%rbp)
jne 0x5d83
leaq 0x5f19(%rip), %rdi      # 0xbc95
movb $0x0, %al
callq 0x30a0
movl -0x8(%rbp), %esi
leaq 0x5950(%rip), %rdi      # 0xb6dd
movb $0x0, %al
callq 0x30a0
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl $0xf, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x5dbb
leaq 0x5eef(%rip), %rdi      # 0xbca3
movb $0x0, %al
callq 0x30a0
jmp 0x5dbd
jmp 0x5e99
movslq -0x8(%rbp), %rcx
leaq 0x9193(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %eax
andl $0xf00, %eax            # imm = 0xF00
cmpl $0x900, %eax            # imm = 0x900
jne 0x5e97
movl -0x8(%rbp), %edi
movslq -0x8(%rbp), %rcx
leaq 0x9171(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x5c40
movl %eax, -0xc(%rbp)
movslq -0xc(%rbp), %rcx
leaq 0xb153(%rip), %rax      # 0x10f60
movzwl (%rax,%rcx,2), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x5e1d
jmp 0x5e9b
movslq -0xc(%rbp), %rcx
leaq 0x9138(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
jge 0x5e33
jmp 0x5e9b
movslq -0xc(%rbp), %rcx
leaq 0x9122(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %eax
cmpl -0x4(%rbp), %eax
jne 0x5e95
cmpl $0x0, -0x10(%rbp)
jne 0x5e5b
leaq 0x5e41(%rip), %rdi      # 0xbc95
movb $0x0, %al
callq 0x30a0
movl -0x8(%rbp), %esi
leaq 0x5878(%rip), %rdi      # 0xb6dd
movb $0x0, %al
callq 0x30a0
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl $0xf, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x5e93
leaq 0x5e17(%rip), %rdi      # 0xbca3
movb $0x0, %al
callq 0x30a0
jmp 0x5e95
jmp 0x5e97
jmp 0x5e99
jmp 0x5e9b
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x5ce9
cmpl $0x0, -0x10(%rbp)
je 0x5ed3
leaq 0x230d(%rip), %rdi      # 0x81c3
movb $0x0, %al
callq 0x30a0
movl -0x10(%rbp), %esi
movl -0x10(%rbp), %edx
leaq 0x5ddd(%rip), %rdi      # 0xbca7
movb $0x0, %al
callq 0x30a0
jmp 0x5ee1
leaq 0x5de6(%rip), %rdi      # 0xbcc0
movb $0x0, %al
callq 0x30a0
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)