// File: khedoros[P]khednes/rom.cpp
// Function: rom::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
bool rom::load(std::string& filename) {
    std::ifstream filein;
    filein.open(filename.c_str(),std::ios::binary|std::ios::in);
    if(!(filein&&filein.is_open())) {
        filein.close();
        return false;
    }
    //get filesize
    filein.seekg(0,std::ios::end);
    filesize=int(filein.tellg());
    filein.seekg(0,std::ios::beg);
    if(filesize<MIN_FILE_SIZE) {
        filein.close();
        return false;
    }
    //parse the header, assign appropriate values to properties
    header.resize(16,0);
    filein.read(reinterpret_cast<char*>(&header[0]),16);

    std::cout<<"Header: ";
    for(int i=0;i<16;++i) {
        printf(" %02x ",header[i]);
    }
    std::cout<<"\n        ";
    for(int i=0;i<16;++i) {
        printf("%03d ", header[i]);
    }
    std::cout<<"\n        ";;
    for(int i=0;i<16;++i) {
        if(header[i] >= 32 && header[i] < 127)
            printf("  %c ", header[i]);
        else printf("    ");
    }
    std::cout<<std::endl;

    if(header[0]!='N'||header[1]!='E'||header[2]!='S'||header[3]!=0x1a) {
        printf("(%02x)  (%02x)  (%02x)  (%02x)", header[0],header[1],header[2],header[3]);
        filein.close();
        return false;
    }

    prom_pages=(int)header[4];
    crom_pages=(int)header[5];

    if(0x01&header[6]) {
        mirror_mode=VERT; //vertical mirrored
    }
    else if(0x08&header[6]) {
        mirror_mode=FOUR_SCR; //4 screen mirror
    }
    else {
        mirror_mode=HORIZ; //horizontal mirror
    }

    if(mapper_num == 0) {
        //std::cout<<std::hex<<(header[6]>>(4))<<" "<<(header[7]&0xF0)<<std::endl;
        mapper_num=((header[6]>>(4)));//|(header[7]&0xF0));//often incorrect
        if(header[7] != 'D') mapper_num |= (header[7]/16)<<(4);
    }
    if(mapper_num == 0 && (prom_pages > 2 || crom_pages != 1)) {
        std::cout<<"It's not possible that this is mapper 0. Taking a guess! =/"<<std::endl;
        mapper_num = mapper_guess();
    }

    sram=((0x02&header[6])>0)?true:false;
    trainer=((0x04&header[6])>0)?true:false;

    prom.resize(prom_pages*PRG_PAGE_SIZE);
    //prom_w = new unsigned int[prom_pages*PRG_PAGE_SIZE];
    prom_w.resize(prom_pages * PRG_PAGE_SIZE);
    filein.read(reinterpret_cast<char*>(&prom[0]),PRG_PAGE_SIZE*prom_pages);
    for(int i=0;i<prom_pages*PRG_PAGE_SIZE-1;++i)
        prom_w[i] = prom[i] | (prom[i+1]<<(8));

    if(crom_pages == 0) {//For ROMs with no CHR-ROM, create one page of RAM for the PRG to fill
        crom.resize(CHR_PAGE_SIZE,0);
    }
    else {//Read in the appropriate number of CHROM pages, if any exist.
          //cpage can be used for bank switching if necessary.
        crom.resize(crom_pages * CHR_PAGE_SIZE, 0);
        filein.read(reinterpret_cast<char*>(&crom[0]),CHR_PAGE_SIZE*crom_pages);
    }

    switch(mapper_num) {
    case 0:
        map = new mapper(this);
        break;
    case 1:
        map = new mapper_001(this);
        break;
    case 2:
        map = new mapper_002(this);
        break;
    case 3:
        map = new mapper_003(this);
        break;
    case 11:
        map = new mapper_011(this);
        break;
    default:
        std::cout<<"Mapper not implemented yet."<<std::endl;
        filein.close();
        return false;
    }

    filein.close();

    //Find the reset.power-on bit vector
    int startl=get_pbyte(RST_INT_INSERTION);
    int starth=get_pbyte(RST_INT_INSERTION+1);
    rst_addr=startl|starth<<8;
    //if(get_pword(RST_INT_INSERTION) != rst_addr) std::cout<<"Unexpected error!"<<std::endl;

    //Find the IRQ bit vector
    startl=get_pbyte(IRQ_INT_INSERTION);
    starth=get_pbyte(IRQ_INT_INSERTION+1);
    irq_addr=startl|starth<<8;
    //if(get_pword(IRQ_INT_INSERTION) != irq_addr) std::cout<<"Unexpected error!"<<std::endl;

    //Find the NMI bit vector
    startl=get_pbyte(NM_INT_INSERTION);
    starth=get_pbyte(NM_INT_INSERTION+1);
    nmi_addr=startl|starth<<8;
    //if(get_pword(NM_INT_INSERTION) != nmi_addr) std::cout<<"Unexpected error!"<<std::endl;

    return true;
}

// Assembly:
subq $0x328, %rsp            # imm = 0x328
movq %rdi, 0x318(%rsp)
movq %rsi, 0x310(%rsp)
movq 0x318(%rsp), %rax
movq %rax, 0xb0(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x4430
movq 0x310(%rsp), %rdi
callq 0x41a0
movq %rax, 0xb8(%rsp)
movl $0x4, %edi
movl $0x8, %esi
callq 0x113b0
movl %eax, 0xc4(%rsp)
jmp 0xedb1
movl 0xc4(%rsp), %edx
movq 0xb8(%rsp), %rsi
leaq 0x108(%rsp), %rdi
callq 0x4250
jmp 0xedcf
movq 0x108(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x108(%rsp,%rax), %rdi
callq 0x4480
movb %al, 0xaf(%rsp)
jmp 0xedf1
movb 0xaf(%rsp), %al
testb $0x1, %al
jne 0xedfe
jmp 0xee21
leaq 0x108(%rsp), %rdi
callq 0x45e0
movb %al, 0xae(%rsp)
jmp 0xee14
movb 0xae(%rsp), %al
testb $0x1, %al
jne 0xee61
jmp 0xee21
leaq 0x108(%rsp), %rdi
callq 0x40d0
jmp 0xee30
movb $0x0, 0x327(%rsp)
movl $0x1, 0xf8(%rsp)
jmp 0xf9ed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xfa0b
xorl %eax, %eax
movl %eax, %esi
leaq 0x108(%rsp), %rdi
movl $0x2, %edx
callq 0x44d0
jmp 0xee79
leaq 0x108(%rsp), %rdi
callq 0x4670
movq %rdx, 0x98(%rsp)
movq %rax, 0xa0(%rsp)
jmp 0xee98
movq 0x98(%rsp), %rax
movq 0xa0(%rsp), %rcx
movq %rcx, 0xe8(%rsp)
movq %rax, 0xf0(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x113d0
movq %rax, 0x90(%rsp)
jmp 0xeecf
movq 0xb0(%rsp), %rax
movq 0x90(%rsp), %rcx
movl %ecx, 0x8c(%rax)
xorl %edx, %edx
movl %edx, %esi
leaq 0x108(%rsp), %rdi
callq 0x44d0
jmp 0xeef8
movq 0xb0(%rsp), %rax
cmpl $0x4010, 0x8c(%rax)     # imm = 0x4010
jge 0xef33
leaq 0x108(%rsp), %rdi
callq 0x40d0
jmp 0xef1b
movb $0x0, 0x327(%rsp)
movl $0x1, 0xf8(%rsp)
jmp 0xf9ed
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movb $0x0, 0xe7(%rsp)
movl $0x10, %esi
leaq 0xe7(%rsp), %rdx
callq 0x113e0
jmp 0xef5b
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x114a0
movq %rax, %rsi
leaq 0x108(%rsp), %rdi
movl $0x10, %edx
callq 0x4490
jmp 0xef87
movq 0x28022(%rip), %rdi     # 0x36fb0
leaq 0x1c500(%rip), %rsi     # 0x2b495
callq 0x43c0
jmp 0xef9c
movl $0x0, 0xe0(%rsp)
cmpl $0x10, 0xe0(%rsp)
jge 0xeff2
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movslq 0xe0(%rsp), %rsi
callq 0x114a0
movzbl (%rax), %esi
leaq 0x1c4ca(%rip), %rdi     # 0x2b49e
xorl %eax, %eax
callq 0x4050
jmp 0xefdd
jmp 0xefdf
movl 0xe0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe0(%rsp)
jmp 0xefa7
movq 0x27fb7(%rip), %rdi     # 0x36fb0
leaq 0x1c4a5(%rip), %rsi     # 0x2b4a5
callq 0x43c0
jmp 0xf007
movl $0x0, 0xdc(%rsp)
cmpl $0x10, 0xdc(%rsp)
jge 0xf05d
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movslq 0xdc(%rsp), %rsi
callq 0x114a0
movzbl (%rax), %esi
leaq 0x1c470(%rip), %rdi     # 0x2b4af
xorl %eax, %eax
callq 0x4050
jmp 0xf048
jmp 0xf04a
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0xf012
movq 0x27f4c(%rip), %rdi     # 0x36fb0
leaq 0x1c43a(%rip), %rsi     # 0x2b4a5
callq 0x43c0
jmp 0xf072
movl $0x0, 0xd8(%rsp)
cmpl $0x10, 0xd8(%rsp)
jge 0xf125
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movslq 0xd8(%rsp), %rsi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x20, %eax
jl 0xf0fb
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movslq 0xd8(%rsp), %rsi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x7f, %eax
jge 0xf0fb
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movslq 0xd8(%rsp), %rsi
callq 0x114a0
movzbl (%rax), %esi
leaq 0x1c3c5(%rip), %rdi     # 0x2b4b5
xorl %eax, %eax
callq 0x4050
jmp 0xf0f9
jmp 0xf10d
leaq 0x1c3a8(%rip), %rdi     # 0x2b4aa
xorl %eax, %eax
callq 0x4050
jmp 0xf10b
jmp 0xf10d
jmp 0xf10f
movl 0xd8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd8(%rsp)
jmp 0xf07d
movq 0x27e84(%rip), %rdi     # 0x36fb0
movq 0x27e5d(%rip), %rsi     # 0x36f90
callq 0x4400
jmp 0xf13a
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x4e, %eax
jne 0xf1b5
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movl $0x1, %esi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x45, %eax
jne 0xf1b5
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movl $0x2, %esi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x53, %eax
jne 0xf1b5
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movl $0x3, %esi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x1a, %eax
je 0xf279
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movq %rdi, 0x78(%rsp)
xorl %eax, %eax
movl %eax, 0x8c(%rsp)
movl %eax, %esi
callq 0x114a0
movq 0x78(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x80(%rsp)
movl $0x1, %esi
callq 0x114a0
movq 0x78(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x84(%rsp)
movl $0x2, %esi
callq 0x114a0
movq 0x78(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x88(%rsp)
movl $0x3, %esi
callq 0x114a0
movl 0x80(%rsp), %esi
movl 0x84(%rsp), %edx
movl 0x88(%rsp), %ecx
movq %rax, %rdi
movl 0x8c(%rsp), %eax
movzbl (%rdi), %r8d
leaq 0x1c270(%rip), %rdi     # 0x2b4bb
callq 0x4050
jmp 0xf252
leaq 0x108(%rsp), %rdi
callq 0x40d0
jmp 0xf261
movb $0x0, 0x327(%rsp)
movl $0x1, 0xf8(%rsp)
jmp 0xf9ed
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movl $0x4, %esi
callq 0x114a0
movq 0xb0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x78(%rdi)
addq $0x10, %rdi
movl $0x5, %esi
callq 0x114a0
movq 0xb0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x7c(%rdi)
addq $0x10, %rdi
movl $0x6, %esi
callq 0x114a0
movzbl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xf2e6
movq 0xb0(%rsp), %rax
movl $0x0, 0x88(%rax)
jmp 0xf32f
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movl $0x6, %esi
callq 0x114a0
movzbl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xf31b
movq 0xb0(%rsp), %rax
movl $0x2, 0x88(%rax)
jmp 0xf32d
movq 0xb0(%rsp), %rax
movl $0x1, 0x88(%rax)
jmp 0xf32f
movq 0xb0(%rsp), %rax
cmpl $0x0, 0x90(%rax)
jne 0xf3bc
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movl $0x6, %esi
callq 0x114a0
movq 0xb0(%rsp), %rdi
movzbl (%rax), %eax
sarl $0x4, %eax
movl %eax, 0x90(%rdi)
addq $0x10, %rdi
movl $0x7, %esi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x44, %eax
je 0xf3ba
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movl $0x7, %esi
callq 0x114a0
movzbl (%rax), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0xb0(%rsp), %rax
shll $0x4, %ecx
orl 0x90(%rax), %ecx
movl %ecx, 0x90(%rax)
jmp 0xf3bc
movq 0xb0(%rsp), %rax
cmpl $0x0, 0x90(%rax)
jne 0xf433
movq 0xb0(%rsp), %rax
cmpl $0x2, 0x78(%rax)
jg 0xf3e9
movq 0xb0(%rsp), %rax
cmpl $0x1, 0x7c(%rax)
je 0xf433
movq 0x27bc0(%rip), %rdi     # 0x36fb0
leaq 0x1c0e3(%rip), %rsi     # 0x2b4da
callq 0x43c0
movq %rax, 0x70(%rsp)
jmp 0xf403
movq 0x70(%rsp), %rdi
movq 0x27b81(%rip), %rsi     # 0x36f90
callq 0x4400
jmp 0xf416
movq 0xb0(%rsp), %rdi
callq 0x10ec0
movl %eax, %ecx
movq 0xb0(%rsp), %rax
movl %ecx, 0x90(%rax)
movq 0xb0(%rsp), %rdi
addq $0x10, %rdi
movq %rdi, 0x60(%rsp)
movl $0x6, %esi
movq %rsi, 0x68(%rsp)
callq 0x114a0
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq %rax, %rcx
movq 0xb0(%rsp), %rax
movzbl (%rcx), %ecx
testb $0x2, %cl
setg 0xa0(%rax)
callq 0x114a0
movq %rax, %rcx
movq 0xb0(%rsp), %rax
movzbl (%rcx), %ecx
testb $0x4, %cl
setg 0xa1(%rax)
movq %rax, %rdi
addq $0x28, %rdi
movl 0x78(%rax), %eax
shll $0xe, %eax
movslq %eax, %rsi
callq 0x114c0
jmp 0xf4a9
movq 0xb0(%rsp), %rax
movq %rax, %rdi
addq $0x40, %rdi
movl 0x78(%rax), %eax
shll $0xe, %eax
movslq %eax, %rsi
callq 0x11560
jmp 0xf4c8
movq 0xb0(%rsp), %rdi
addq $0x28, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x114a0
movq %rax, %rsi
movq 0xb0(%rsp), %rax
movl 0x78(%rax), %eax
shll $0xe, %eax
movslq %eax, %rdx
leaq 0x108(%rsp), %rdi
callq 0x4490
jmp 0xf500
movl $0x0, 0xd4(%rsp)
movq 0xb0(%rsp), %rcx
movl 0xd4(%rsp), %eax
movl 0x78(%rcx), %ecx
shll $0xe, %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xf5b1
movq 0xb0(%rsp), %rdi
addq $0x28, %rdi
movslq 0xd4(%rsp), %rsi
callq 0x114a0
movq 0xb0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x58(%rsp)
addq $0x28, %rdi
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x114a0
movq 0xb0(%rsp), %rdi
movq %rax, %rcx
movl 0x58(%rsp), %eax
movzbl (%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movl %eax, 0x5c(%rsp)
addq $0x40, %rdi
movslq 0xd4(%rsp), %rsi
callq 0x11600
movl 0x5c(%rsp), %ecx
movl %ecx, (%rax)
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0xf50b
movq 0xb0(%rsp), %rax
cmpl $0x0, 0x7c(%rax)
jne 0xf5e9
movq 0xb0(%rsp), %rdi
addq $0x58, %rdi
movb $0x0, 0xd3(%rsp)
movl $0x2000, %esi           # imm = 0x2000
leaq 0xd3(%rsp), %rdx
callq 0x113e0
jmp 0xf5e7
jmp 0xf652
movq 0xb0(%rsp), %rax
movq %rax, %rdi
addq $0x58, %rdi
movl 0x7c(%rax), %eax
shll $0xd, %eax
movslq %eax, %rsi
movb $0x0, 0xd2(%rsp)
leaq 0xd2(%rsp), %rdx
callq 0x113e0
jmp 0xf618
movq 0xb0(%rsp), %rdi
addq $0x58, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x114a0
movq %rax, %rsi
movq 0xb0(%rsp), %rax
movl 0x7c(%rax), %eax
shll $0xd, %eax
movslq %eax, %rdx
leaq 0x108(%rsp), %rdi
callq 0x4490
jmp 0xf650
jmp 0xf652
movq 0xb0(%rsp), %rax
movl 0x90(%rax), %eax
movq %rax, 0x50(%rsp)
subq $0xb, %rax
ja 0xf852
movq 0x50(%rsp), %rax
leaq 0x1bd8d(%rip), %rcx     # 0x2b408
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x10, %edi
callq 0x43d0
movq %rax, 0x48(%rsp)
jmp 0xf695
movq 0xb0(%rsp), %rsi
movq 0x48(%rsp), %rdi
callq 0x26a50
jmp 0xf6a9
movq 0xb0(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %rcx, (%rax)
jmp 0xf8a6
movq 0x48(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
callq 0x4390
jmp 0xfa0b
movl $0x58, %edi
callq 0x43d0
movq %rax, 0x40(%rsp)
jmp 0xf6f2
movq 0xb0(%rsp), %rsi
movq 0x40(%rsp), %rdi
callq 0x26d40
jmp 0xf706
movq 0xb0(%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rcx, (%rax)
jmp 0xf8a6
movq 0x40(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
callq 0x4390
jmp 0xfa0b
movl $0x18, %edi
callq 0x43d0
movq %rax, 0x38(%rsp)
jmp 0xf74f
movq 0xb0(%rsp), %rsi
movq 0x38(%rsp), %rdi
callq 0x27e80
jmp 0xf763
movq 0xb0(%rsp), %rax
movq 0x38(%rsp), %rcx
movq %rcx, (%rax)
jmp 0xf8a6
movq 0x38(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
callq 0x4390
jmp 0xfa0b
movl $0x30, %edi
callq 0x43d0
movq %rax, 0x30(%rsp)
jmp 0xf7ac
movq 0xb0(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0x28120
jmp 0xf7c0
movq 0xb0(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, (%rax)
jmp 0xf8a6
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
callq 0x4390
jmp 0xfa0b
movl $0x38, %edi
callq 0x43d0
movq %rax, 0x28(%rsp)
jmp 0xf809
movq 0xb0(%rsp), %rsi
movq 0x28(%rsp), %rdi
callq 0x28f10
jmp 0xf81d
movq 0xb0(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rcx, (%rax)
jmp 0xf8a6
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
callq 0x4390
jmp 0xfa0b
movq 0x27757(%rip), %rdi     # 0x36fb0
leaq 0x1bcb6(%rip), %rsi     # 0x2b516
callq 0x43c0
movq %rax, 0x20(%rsp)
jmp 0xf86c
movq 0x20(%rsp), %rdi
movq 0x27718(%rip), %rsi     # 0x36f90
callq 0x4400
jmp 0xf87f
leaq 0x108(%rsp), %rdi
callq 0x40d0
jmp 0xf88e
movb $0x0, 0x327(%rsp)
movl $0x1, 0xf8(%rsp)
jmp 0xf9ed
leaq 0x108(%rsp), %rdi
callq 0x40d0
jmp 0xf8b5
movq 0xb0(%rsp), %rdi
movl $0xfffc, %esi           # imm = 0xFFFC
callq 0x10ed0
movl %eax, 0x1c(%rsp)
jmp 0xf8cd
movq 0xb0(%rsp), %rdi
movl 0x1c(%rsp), %eax
movl %eax, 0xcc(%rsp)
movl $0xfffd, %esi           # imm = 0xFFFD
callq 0x10ed0
movl %eax, 0x18(%rsp)
jmp 0xf8f0
movq 0xb0(%rsp), %rdi
movl 0x18(%rsp), %eax
movl %eax, 0xc8(%rsp)
movl 0xcc(%rsp), %eax
movl 0xc8(%rsp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movl %eax, 0x94(%rdi)
movl $0xfffe, %esi           # imm = 0xFFFE
callq 0x10ed0
movl %eax, 0x14(%rsp)
jmp 0xf92c
movq 0xb0(%rsp), %rdi
movl 0x14(%rsp), %eax
movl %eax, 0xcc(%rsp)
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x10ed0
movl %eax, 0x10(%rsp)
jmp 0xf94f
movq 0xb0(%rsp), %rdi
movl 0x10(%rsp), %eax
movl %eax, 0xc8(%rsp)
movl 0xcc(%rsp), %eax
movl 0xc8(%rsp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movl %eax, 0x9c(%rdi)
movl $0xfffa, %esi           # imm = 0xFFFA
callq 0x10ed0
movl %eax, 0xc(%rsp)
jmp 0xf98b
movq 0xb0(%rsp), %rdi
movl 0xc(%rsp), %eax
movl %eax, 0xcc(%rsp)
movl $0xfffb, %esi           # imm = 0xFFFB
callq 0x10ed0
movl %eax, 0x8(%rsp)
jmp 0xf9ae
movq 0xb0(%rsp), %rax
movl 0x8(%rsp), %ecx
movl %ecx, 0xc8(%rsp)
movl 0xcc(%rsp), %ecx
movl 0xc8(%rsp), %edx
shll $0x8, %edx
orl %edx, %ecx
movl %ecx, 0x98(%rax)
movb $0x1, 0x327(%rsp)
movl $0x1, 0xf8(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x4100
movb 0x327(%rsp), %al
andb $0x1, %al
addq $0x328, %rsp            # imm = 0x328
retq
leaq 0x108(%rsp), %rdi
callq 0x4100
movq 0x100(%rsp), %rdi
callq 0x4680
nopw %cs:(%rax,%rax)