// File: besm6[P]pascal-re/dtran.cc
// Function: Dtran::Dtran(char const*, unsigned int, bool, bool, bool)
Dtran(const char * fname, uint b, bool n, bool e, bool o) :
        basereg(b), baseaddr(~0u), nolabels(n), noequs(e), nooctal(o) {

    unsigned int addr = 0;
    struct stat st;

    FILE * textfd = fopen (fname, "r");
    if (! textfd) {
        fprintf (stderr, "dtran: %s not found\n", fname);
        exit(1);
    }
    stat (fname, &st);
    uint codelen = st.st_size / 6;

    if (codelen >= 32768) {
        fprintf(stderr, "File too large\n");
        exit(1);
    }
    while (!feof(textfd) && addr < 0100000) {
        memory[addr++] = freadw (textfd);
    }

    fill_lengths();
    if (codelen < comment_off) {
        fprintf(stderr, "File was too short: %d, expected %d\n", codelen, comment_off);
        exit (EXIT_FAILURE);
    }
    symtab.resize(head_len + sym_len);
    labels.resize(cmd_len + const_len + bss_len + data_len);
    fclose (textfd);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movl %r8d, -0xfc(%rbp)
movl %ecx, %eax
movl -0xfc(%rbp), %ecx
movl %eax, -0xf8(%rbp)
movl %edx, %eax
movl -0xf8(%rbp), %edx
movl %eax, -0xf4(%rbp)
movq %rsi, %rax
movl -0xf4(%rbp), %esi
movq %rax, -0xf0(%rbp)
movq %rdi, %r8
movq -0xf0(%rbp), %rdi
movb %r9b, %al
movq %r8, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
andb $0x1, %dl
movb %dl, -0x15(%rbp)
andb $0x1, %cl
movb %cl, -0x16(%rbp)
andb $0x1, %al
movb %al, -0x17(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
movl -0x14(%rbp), %eax
movl %eax, 0x34(%rdi)
movl $0xffffffff, 0x38(%rdi) # imm = 0xFFFFFFFF
movb -0x15(%rbp), %al
andb $0x1, %al
movb %al, 0x40(%rdi)
movb -0x16(%rbp), %al
andb $0x1, %al
movb %al, 0x41(%rdi)
movb -0x17(%rbp), %al
andb $0x1, %al
movb %al, 0x42(%rdi)
addq $0x40048, %rdi          # imm = 0x40048
movq %rdi, -0xe8(%rbp)
callq 0x4900
movq -0xe0(%rbp), %rdi
addq $0x40060, %rdi          # imm = 0x40060
movq %rdi, -0xd8(%rbp)
callq 0x4900
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x4903(%rip), %rsi      # 0x8329
callq 0x3230
movq %rax, -0xd0(%rbp)
jmp 0x3a34
movq -0xd0(%rbp), %rax
movq %rax, -0xb8(%rbp)
cmpq $0x0, -0xb8(%rbp)
jne 0x3aa1
movq 0x7585(%rip), %rax      # 0xafd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x48ca(%rip), %rsi      # 0x832b
movb $0x0, %al
callq 0x32e0
movl $0x1, %edi
callq 0x3250
movq -0xd8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc0(%rbp)
movl %eax, -0xc4(%rbp)
callq 0x4c70
movq -0xe8(%rbp), %rdi
callq 0x4c70
jmp 0x3c20
movq -0x10(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3190
movq -0x80(%rbp), %rax
movl $0x6, %ecx
cqto
idivq %rcx
movl %eax, -0xc8(%rbp)
cmpl $0x8000, -0xc8(%rbp)    # imm = 0x8000
jb 0x3af3
movq 0x7500(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x485e(%rip), %rsi      # 0x8340
movb $0x0, %al
callq 0x32e0
movl $0x1, %edi
callq 0x3250
jmp 0x3af5
movq -0xb8(%rbp), %rdi
callq 0x3310
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xfd(%rbp)
jne 0x3b20
cmpl $0x8000, -0x1c(%rbp)    # imm = 0x8000
setb %al
movb %al, -0xfd(%rbp)
movb -0xfd(%rbp), %al
testb $0x1, %al
jne 0x3b2c
jmp 0x3b6a
movq -0xe0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0x4920
movq %rax, -0x108(%rbp)
jmp 0x3b48
movq -0xe0(%rbp), %rax
movq -0x108(%rbp), %rdx
movl -0x1c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rbp)
movl %ecx, %ecx
movq %rdx, 0x48(%rax,%rcx,8)
jmp 0x3af5
movq -0xe0(%rbp), %rdi
callq 0x4980
jmp 0x3b78
movq -0xe0(%rbp), %rcx
movl -0xc8(%rbp), %eax
cmpl 0x30(%rcx), %eax
jae 0x3bbc
movq -0xe0(%rbp), %rax
movq 0x7440(%rip), %rcx      # 0xafd8
movq (%rcx), %rdi
movl -0xc8(%rbp), %edx
movl 0x30(%rax), %ecx
leaq 0x47a5(%rip), %rsi      # 0x8350
movb $0x0, %al
callq 0x32e0
movl $0x1, %edi
callq 0x3250
movq -0xe0(%rbp), %rcx
movq %rcx, %rdi
addq $0x40048, %rdi          # imm = 0x40048
movl (%rcx), %eax
movl 0x4(%rcx), %ecx
addl %ecx, %eax
movl %eax, %esi
callq 0x4be0
jmp 0x3bdd
movq -0xe0(%rbp), %rdx
movq %rdx, %rdi
addq $0x40060, %rdi          # imm = 0x40060
movl 0xc(%rdx), %ecx
movl 0x18(%rdx), %eax
movl 0x20(%rdx), %esi
addl %esi, %eax
movl 0x1c(%rdx), %edx
addl %edx, %eax
addl %ecx, %eax
movl %eax, %esi
callq 0x4be0
jmp 0x3c09
movq -0xb8(%rbp), %rdi
callq 0x31b0
jmp 0x3c17
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0xc0(%rbp), %rdi
callq 0x3370
nopl (%rax)