// File: besm6[P]pascal-re/dtran.cc
// Function: Dtran::prinsn(unsigned int, unsigned int)
void
prinsn (uint32 memaddr, uint32 opcode)
{
    int i;

    uint reg = opcode >> 20;
    int arg1 = (opcode & 07777) + (opcode & 0x040000 ? 070000 : 0);
    int arg2 = opcode & 077777;
    int struc = opcode & 02000000;

    for (i=0; op[i].mask; i++)
        if ((opcode & op[i].mask) == op[i].opcode)
            break;
    opcode_e type = op[i].type;
    std::string opname = op[i].name;
    if (type == OPCODE_ILLEGAL) {
        opname = struc ? strprintf("%2o", (opcode >> 15) & 037)
            : strprintf("%03o", (opcode >> 12) & 0177);
    }
    std::string operand;
    if (struc && arg2 >= 074000) {
        operand = strprintf("%s", symtab[arg2 & 03777].c_str());
    } else if (struc && arg2 >= 040000 && (arg2 & 037777) < labels.size()) {
        uint off = arg2 & 037777;
        if (labels[off].empty())
            labels[off] = off < 010000 ?
                                strprintf("*%04oB", off) :
                                strprintf("*%05o", off);
        operand = labels[off];
    } else if (!struc && arg1 >= 04000 && arg1 < 010000) {
        operand = symtab[arg2 & 03777];
    } else if (!struc && arg1 >= 070000) {
        operand = "dunno";
    } else {
        if (uint val = struc ? arg2 : arg1) {
            if (type == OPCODE_REG1 || val < 8)
                operand = strprintf("%d", val);
            else if (type == OPCODE_IMM64) {
                operand = strprintf("64%+d", val-64);
            } else
                operand = strprintf(nooctal ? "%d" : "%oB", val);
        }
    }

    if (basereg && reg == basereg) {
        if (op[i].opcode == 02400000) {
            opname = "BASE";
        } else {
            reg = 0;
            operand = labels[baseaddr + arg1];
        }
    }
    if (nolabels && operand[0] == '*' && !strchr(operand.c_str(), '+')) {
        char * end;
        int off = strtol(operand.c_str()+1, &end, 8);
        if (end - operand.c_str() > 4)
            operand = strprintf(nooctal ? "/+%d" : "/+%oB", off);
    }
    if (reg) printf("%d,", reg); else printf(",");
    printf("%s,%s\n", opname.c_str(), operand.c_str());
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x188(%rbp)
movl -0x10(%rbp), %eax
shrl $0x14, %eax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %eax
andl $0xfff, %eax            # imm = 0xFFF
movl -0x10(%rbp), %esi
andl $0x40000, %esi          # imm = 0x40000
xorl %ecx, %ecx
movl $0x7000, %edx           # imm = 0x7000
cmpl $0x0, %esi
cmovnel %edx, %ecx
addl %ecx, %eax
movl %eax, -0x1c(%rbp)
movl -0x10(%rbp), %eax
andl $0x7fff, %eax           # imm = 0x7FFF
movl %eax, -0x20(%rbp)
movl -0x10(%rbp), %eax
andl $0x80000, %eax          # imm = 0x80000
movl %eax, -0x24(%rbp)
movl $0x0, -0x14(%rbp)
movslq -0x14(%rbp), %rcx
leaq 0x48fc(%rip), %rax      # 0xb1f0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0xc(%rax)
je 0x693f
movl -0x10(%rbp), %eax
movslq -0x14(%rbp), %rdx
leaq 0x48e1(%rip), %rcx      # 0xb1f0
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
andl 0xc(%rcx), %eax
movslq -0x14(%rbp), %rdx
leaq 0x48cc(%rip), %rcx      # 0xb1f0
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
jne 0x6932
jmp 0x693f
jmp 0x6934
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x68e9
movslq -0x14(%rbp), %rax
leaq (%rax,%rax,2), %rcx
leaq 0x48a2(%rip), %rax      # 0xb1f0
movl 0x10(%rax,%rcx,8), %ecx
movl %ecx, -0x28(%rbp)
movslq -0x14(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x198(%rbp)
leaq -0x49(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x3380
movq -0x198(%rbp), %rsi
movq -0x190(%rbp), %rdx
leaq -0x48(%rbp), %rdi
callq 0x4ee0
jmp 0x6991
leaq -0x49(%rbp), %rdi
callq 0x31f0
cmpl $0x0, -0x28(%rbp)
jne 0x6a2b
cmpl $0x0, -0x24(%rbp)
je 0x69c9
movl -0x10(%rbp), %edx
shrl $0xf, %edx
andl $0x1f, %edx
leaq 0x1d5e(%rip), %rsi      # 0x8718
xorl %eax, %eax
leaq -0x80(%rbp), %rdi
callq 0x34c0
jmp 0x69c7
jmp 0x69e8
movl -0x10(%rbp), %edx
shrl $0xc, %edx
andl $0x7f, %edx
leaq 0x1d43(%rip), %rsi      # 0x871c
xorl %eax, %eax
leaq -0x80(%rbp), %rdi
callq 0x34c0
jmp 0x69e6
jmp 0x69e8
leaq -0x48(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x3260
leaq -0x80(%rbp), %rdi
callq 0x3110
jmp 0x6a2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x49(%rbp), %rdi
callq 0x31f0
jmp 0x6fc3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x6fba
leaq -0xa0(%rbp), %rdi
callq 0x32b0
cmpl $0x0, -0x24(%rbp)
je 0x6ace
cmpl $0x7800, -0x20(%rbp)    # imm = 0x7800
jl 0x6ace
movq -0x188(%rbp), %rdi
addq $0x40048, %rdi          # imm = 0x40048
movl -0x20(%rbp), %eax
andl $0x7ff, %eax            # imm = 0x7FF
movl %eax, %esi
callq 0x6380
movq %rax, %rdi
callq 0x30c0
movq %rax, %rdx
leaq 0x1ca4(%rip), %rsi      # 0x8721
xorl %eax, %eax
leaq -0xc0(%rbp), %rdi
callq 0x34c0
jmp 0x6a8d
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x3260
leaq -0xc0(%rbp), %rdi
callq 0x3110
jmp 0x6da5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x3110
jmp 0x6fba
cmpl $0x0, -0x24(%rbp)
je 0x6c07
cmpl $0x4000, -0x20(%rbp)    # imm = 0x4000
jl 0x6c07
movq -0x188(%rbp), %rdi
movl -0x20(%rbp), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cltq
movq %rax, -0x1a0(%rbp)
addq $0x40060, %rdi          # imm = 0x40060
callq 0x5230
movq %rax, %rcx
movq -0x1a0(%rbp), %rax
cmpq %rcx, %rax
jae 0x6c07
movq -0x188(%rbp), %rdi
movl -0x20(%rbp), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
movl %eax, -0xc4(%rbp)
addq $0x40060, %rdi          # imm = 0x40060
movl -0xc4(%rbp), %eax
movl %eax, %esi
callq 0x6380
movq %rax, %rdi
callq 0x3360
testb $0x1, %al
jne 0x6b56
jmp 0x6bd6
cmpl $0x1000, -0xc4(%rbp)    # imm = 0x1000
jae 0x6b81
movl -0xc4(%rbp), %edx
leaq 0x19ce(%rip), %rsi      # 0x853d
xorl %eax, %eax
leaq -0xe8(%rbp), %rdi
callq 0x34c0
jmp 0x6b7f
jmp 0x6ba0
movl -0xc4(%rbp), %edx
leaq 0x19b6(%rip), %rsi      # 0x8544
xorl %eax, %eax
leaq -0xe8(%rbp), %rdi
callq 0x34c0
jmp 0x6b9e
jmp 0x6ba0
movq -0x188(%rbp), %rdi
addq $0x40060, %rdi          # imm = 0x40060
movl -0xc4(%rbp), %eax
movl %eax, %esi
callq 0x6380
movq %rax, %rdi
leaq -0xe8(%rbp), %rsi
callq 0x3260
leaq -0xe8(%rbp), %rdi
callq 0x3110
movq -0x188(%rbp), %rdi
addq $0x40060, %rdi          # imm = 0x40060
movl -0xc4(%rbp), %eax
movl %eax, %esi
callq 0x6380
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x3030
jmp 0x6c02
jmp 0x6da3
cmpl $0x0, -0x24(%rbp)
jne 0x6c52
cmpl $0x800, -0x1c(%rbp)     # imm = 0x800
jl 0x6c52
cmpl $0x1000, -0x1c(%rbp)    # imm = 0x1000
jge 0x6c52
movq -0x188(%rbp), %rdi
addq $0x40048, %rdi          # imm = 0x40048
movl -0x20(%rbp), %eax
andl $0x7ff, %eax            # imm = 0x7FF
movl %eax, %esi
callq 0x6380
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x3030
jmp 0x6c4d
jmp 0x6da1
cmpl $0x0, -0x24(%rbp)
jne 0x6c7b
cmpl $0x7000, -0x1c(%rbp)    # imm = 0x7000
jl 0x6c7b
leaq 0x1abc(%rip), %rsi      # 0x8724
leaq -0xa0(%rbp), %rdi
callq 0x32a0
jmp 0x6c76
jmp 0x6d9f
cmpl $0x0, -0x24(%rbp)
je 0x6c8c
movl -0x20(%rbp), %eax
movl %eax, -0x1a4(%rbp)
jmp 0x6c95
movl -0x1c(%rbp), %eax
movl %eax, -0x1a4(%rbp)
movl -0x1a4(%rbp), %eax
movl %eax, -0xec(%rbp)
cmpl $0x0, -0xec(%rbp)
je 0x6d9d
cmpl $0x4, -0x28(%rbp)
je 0x6cbd
cmpl $0x8, -0xec(%rbp)
jae 0x6cfe
movl -0xec(%rbp), %edx
leaq 0x1a6d(%rip), %rsi      # 0x8737
xorl %eax, %eax
leaq -0x110(%rbp), %rdi
callq 0x34c0
jmp 0x6cda
leaq -0xa0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x3260
leaq -0x110(%rbp), %rdi
callq 0x3110
jmp 0x6d9b
cmpl $0x8, -0x28(%rbp)
jne 0x6d45
movl -0xec(%rbp), %edx
addl $-0x40, %edx
leaq 0x1a16(%rip), %rsi      # 0x872a
xorl %eax, %eax
leaq -0x130(%rbp), %rdi
callq 0x34c0
jmp 0x6d24
leaq -0xa0(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x3260
leaq -0x130(%rbp), %rdi
callq 0x3110
jmp 0x6d99
movq -0x188(%rbp), %rax
movb 0x42(%rax), %cl
leaq 0x19e1(%rip), %rax      # 0x8737
leaq 0x19df(%rip), %rsi      # 0x873c
testb $0x1, %cl
cmovneq %rax, %rsi
movl -0xec(%rbp), %edx
xorl %eax, %eax
leaq -0x150(%rbp), %rdi
callq 0x34c0
jmp 0x6d7a
leaq -0xa0(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x3260
leaq -0x150(%rbp), %rdi
callq 0x3110
jmp 0x6d9b
jmp 0x6d9d
jmp 0x6d9f
jmp 0x6da1
jmp 0x6da3
jmp 0x6da5
movq -0x188(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0x6e2c
movq -0x188(%rbp), %rcx
movl -0x18(%rbp), %eax
cmpl 0x34(%rcx), %eax
jne 0x6e2c
movslq -0x14(%rbp), %rcx
leaq 0x4424(%rip), %rax      # 0xb1f0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $0xa0000, 0x8(%rax)     # imm = 0xA0000
jne 0x6df0
leaq 0x194d(%rip), %rsi      # 0x8730
leaq -0x48(%rbp), %rdi
callq 0x32a0
jmp 0x6dee
jmp 0x6e2a
movq -0x188(%rbp), %rax
movl $0x0, -0x18(%rbp)
movq %rax, %rdi
addq $0x40060, %rdi          # imm = 0x40060
movl 0x38(%rax), %eax
movl -0x1c(%rbp), %ecx
addl %ecx, %eax
movl %eax, %esi
callq 0x6380
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x3030
jmp 0x6e28
jmp 0x6e2a
jmp 0x6e2c
movq -0x188(%rbp), %rax
testb $0x1, 0x40(%rax)
je 0x6f39
xorl %eax, %eax
movl %eax, %esi
leaq -0xa0(%rbp), %rdi
callq 0x33b0
movq %rax, -0x1b0(%rbp)
jmp 0x6e56
movq -0x1b0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2a, %eax
jne 0x6f39
leaq -0xa0(%rbp), %rdi
callq 0x30c0
movq %rax, %rdi
movl $0x2b, %esi
callq 0x30a0
cmpq $0x0, %rax
jne 0x6f39
leaq -0xa0(%rbp), %rdi
callq 0x30c0
movq %rax, %rdi
addq $0x1, %rdi
leaq -0x158(%rbp), %rsi
movl $0x8, %edx
callq 0x32d0
movl %eax, -0x15c(%rbp)
movq -0x158(%rbp), %rax
movq %rax, -0x1b8(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x30c0
movq %rax, %rcx
movq -0x1b8(%rbp), %rax
subq %rcx, %rax
cmpq $0x4, %rax
jle 0x6f37
movq -0x188(%rbp), %rax
movb 0x42(%rax), %cl
leaq 0x1841(%rip), %rax      # 0x8735
leaq 0x183f(%rip), %rsi      # 0x873a
testb $0x1, %cl
cmovneq %rax, %rsi
movl -0x15c(%rbp), %edx
xorl %eax, %eax
leaq -0x180(%rbp), %rdi
callq 0x34c0
jmp 0x6f18
leaq -0xa0(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x3260
leaq -0x180(%rbp), %rdi
callq 0x3110
jmp 0x6f39
cmpl $0x0, -0x18(%rbp)
je 0x6f54
movl -0x18(%rbp), %esi
leaq 0x17f7(%rip), %rdi      # 0x8740
xorl %eax, %eax
callq 0x3040
jmp 0x6f52
jmp 0x6f66
leaq 0x163f(%rip), %rdi      # 0x859a
xorl %eax, %eax
callq 0x3040
jmp 0x6f64
jmp 0x6f66
leaq -0x48(%rbp), %rdi
callq 0x30c0
movq %rax, -0x1c0(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x30c0
movq -0x1c0(%rbp), %rsi
movq %rax, %rdx
leaq 0x17b1(%rip), %rdi      # 0x8744
xorl %eax, %eax
callq 0x3040
jmp 0x6f9c
leaq -0xa0(%rbp), %rdi
callq 0x3110
leaq -0x48(%rbp), %rdi
callq 0x3110
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x3110
movq -0x58(%rbp), %rdi
callq 0x3370
nopl (%rax)