// File: /workspace/github_c_makefile_star2_O0/AK6DN[P]dec-utilities-for-pdp/d8tape/flow.c
// Function: pass1
static void
pass1 (void)
{
    int     addr, eff;

    for (addr = 0; addr < CORE_SIZE; addr++) {
        // skip unused
        if (core [addr] == -1) {
            continue;
        }
        // handle IOTs
        if ((core [addr] & 07000) == 06000) {
            // if we can't decode it, it's not valid
            if (!fetch_iot (core [addr], NULL, NULL)) {
                tags [addr] |= TAG_DATA;
            }
            continue;
        }
        // check OPRs; if they're invalid, tag as DATA, else skip
        if ((core [addr] & 07000) == 07000) {
            if (!valid_opr (core [addr])) {
                tags [addr] |= TAG_DATA;
                if (optv > 1) {
                    printf ("+FLOW1 %04o %04o has invalid OPR -> DATA\n", addr, core [addr]);
                }
            }
            // done OPRs, skip
            continue;   // @@@ NOTE:  this does not work with EAE OPRs that take the next location as their parameter...
        }

        // ea() is always valid for opcodes < 06000
        eff = ea (addr, core [addr], NULL, NULL);

        // if the instruction should have a valid EA and doesn't...
        if (core [eff] == -1) {
            // then it's not an instruction
            tags [addr] |= TAG_DATA;
            if (optv > 1) {
                printf ("+FLOW1 %04o %04o has EA %04o (invalid or not in core) and OP < 6000 -> DATA\n", addr, core [addr], eff);
            }
            continue;
        }

        // if it's a plain JMS
        if ((core [addr] & 07400) == 04000) {
            // and the target isn't zero or it's not the same as the address
            if (core [eff] && core [eff] != eff) {
                tags [addr] |= TAG_DATA;
                if (optv > 1) {
                    printf ("+FLOW1 %04o %04o JMS target not 0000 or ADDR (EA %04o is %04o)\n", addr, core [addr], eff, core [eff]);
                }
                continue;
            }
            // else, if it's ok, then the target is writable, after all (JMS drops the return address there)
            tags [eff] |= TAG_WRITABLE;
            if (optv > 1) {
                printf ("+FLOW1 %04o %04o JMS target is 0000 or ADDR, marking EA %04o as WRITABLE\n", addr, core [addr], eff);
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl $0x0, -0x4(%rbp)
cmpl $0x1000, -0x4(%rbp)     # imm = 0x1000
jge 0x66c0
movslq -0x4(%rbp), %rcx
leaq 0x8b29(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %eax
cmpl $-0x1, %eax
jne 0x6445
jmp 0x66b2
movslq -0x4(%rbp), %rcx
leaq 0x8b10(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %eax
andl $0xe00, %eax            # imm = 0xE00
cmpl $0xc00, %eax            # imm = 0xC00
jne 0x64a5
movslq -0x4(%rbp), %rcx
leaq 0x8af5(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %edi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x5ef0
cmpl $0x0, %eax
jne 0x64a0
movslq -0x4(%rbp), %rcx
leaq 0xaad5(%rip), %rax      # 0x10f60
movzwl (%rax,%rcx,2), %eax
orl $0x1, %eax
movw %ax, %dx
leaq 0xaac4(%rip), %rax      # 0x10f60
movw %dx, (%rax,%rcx,2)
jmp 0x66b2
movslq -0x4(%rbp), %rcx
leaq 0x8ab0(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %eax
andl $0xe00, %eax            # imm = 0xE00
cmpl $0xe00, %eax            # imm = 0xE00
jne 0x652c
movslq -0x4(%rbp), %rcx
leaq 0x8a95(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %edi
callq 0x7110
cmpl $0x0, %eax
jne 0x6527
movslq -0x4(%rbp), %rcx
leaq 0xaa7c(%rip), %rax      # 0x10f60
movzwl (%rax,%rcx,2), %eax
orl $0x1, %eax
movw %ax, %dx
leaq 0xaa6b(%rip), %rax      # 0x10f60
movw %dx, (%rax,%rcx,2)
leaq 0x8a50(%rip), %rax      # 0xef50
cmpl $0x1, (%rax)
jle 0x6525
movl -0x4(%rbp), %esi
movslq -0x4(%rbp), %rcx
leaq 0x8a4d(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %edx
leaq 0x57b2(%rip), %rdi      # 0xbcd0
movb $0x0, %al
callq 0x30a0
jmp 0x6527
jmp 0x66b2
movl -0x4(%rbp), %edi
movslq -0x4(%rbp), %rcx
leaq 0x8a26(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %esi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x5c40
movl %eax, -0x8(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0x8a08(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %eax
cmpl $-0x1, %eax
jne 0x65b5
movslq -0x4(%rbp), %rcx
leaq 0xa9f4(%rip), %rax      # 0x10f60
movzwl (%rax,%rcx,2), %eax
orl $0x1, %eax
movw %ax, %dx
leaq 0xa9e3(%rip), %rax      # 0x10f60
movw %dx, (%rax,%rcx,2)
leaq 0x89c8(%rip), %rax      # 0xef50
cmpl $0x1, (%rax)
jle 0x65b0
movl -0x4(%rbp), %esi
movslq -0x4(%rbp), %rcx
leaq 0x89c5(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %edx
movl -0x8(%rbp), %ecx
leaq 0x5751(%rip), %rdi      # 0xbcfa
movb $0x0, %al
callq 0x30a0
jmp 0x66b2
movslq -0x4(%rbp), %rcx
leaq 0x89a0(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %eax
andl $0xf00, %eax            # imm = 0xF00
cmpl $0x800, %eax            # imm = 0x800
jne 0x66b0
movslq -0x8(%rbp), %rcx
leaq 0x8981(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
je 0x665d
movslq -0x8(%rbp), %rcx
leaq 0x896d(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %eax
cmpl -0x8(%rbp), %eax
je 0x665d
movslq -0x4(%rbp), %rcx
leaq 0xa959(%rip), %rax      # 0x10f60
movzwl (%rax,%rcx,2), %eax
orl $0x1, %eax
movw %ax, %dx
leaq 0xa948(%rip), %rax      # 0x10f60
movw %dx, (%rax,%rcx,2)
leaq 0x892d(%rip), %rax      # 0xef50
cmpl $0x1, (%rax)
jle 0x665b
movl -0x4(%rbp), %esi
movslq -0x4(%rbp), %rcx
leaq 0x892a(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %edx
movl -0x8(%rbp), %ecx
movslq -0x8(%rbp), %rdi
leaq 0x8918(%rip), %rax      # 0xef60
movswl (%rax,%rdi,2), %r8d
leaq 0x56f3(%rip), %rdi      # 0xbd47
movb $0x0, %al
callq 0x30a0
jmp 0x66b2
movslq -0x8(%rbp), %rcx
leaq 0xa8f8(%rip), %rax      # 0x10f60
movzwl (%rax,%rcx,2), %eax
orl $0x100, %eax            # imm = 0x100
movw %ax, %dx
leaq 0xa8e5(%rip), %rax      # 0x10f60
movw %dx, (%rax,%rcx,2)
leaq 0x88ca(%rip), %rax      # 0xef50
cmpl $0x1, (%rax)
jle 0x66ae
movl -0x4(%rbp), %esi
movslq -0x4(%rbp), %rcx
leaq 0x88c7(%rip), %rax      # 0xef60
movswl (%rax,%rcx,2), %edx
movl -0x8(%rbp), %ecx
leaq 0x56e0(%rip), %rdi      # 0xbd87
movb $0x0, %al
callq 0x30a0
jmp 0x66b0
jmp 0x66b2
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x641f
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)