// File: khedoros[P]khednes/rom.cpp
// Function: rom::load_nsf(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
bool rom::load_nsf(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<0x100) {
        filein.close();
        return false;
    }
    //parse the header, assign appropriate values to properties
    header.resize(0x80,0);
    filein.read(reinterpret_cast<char*>(&header[0]),0x80);

    std::cout<<"Header: ";
    for(int i=0;i<0x20;++i) {
        printf(" %02x ",header[i]);
    }
    std::cout<<"\n        ";
    for(int i=0;i<0x20;++i) {
        printf("%03d ", header[i]);
    }
    std::cout<<"\n        ";;
    for(int i=0;i<0x20;++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]!='M'||header[4]!=0x1a) {
        printf("(%02x)  (%02x)  (%02x)  (%02x) (%02x)", header[0],header[1],header[2],header[3],header[4]);
        printf("Header doesn't match expected NSF header.\n");
        filein.close();
        return false;
    }
    
    if(header[5] != 1) {
        printf("I don't handle files of version %d.\n", header[5]);
        filein.close();
        return false;
    }
    song_count = header[6];

    song_index = header[7] - 1;

    //Find the load addr
    int startl=header[0x08];
    int starth=header[0x09];
    load_addr=startl|starth<<8;

    //Find the song-init/power-on vector
    startl=header[0x0a];
    starth=header[0x0b];
    rst_addr=startl|starth<<8;

    //Find the NMI bit vector/song iteration vector
    startl=header[0x0c];
    starth=header[0x0d];
    nmi_addr=startl|starth<<8;
    //if(get_pword(NM_INT_INSERTION) != nmi_addr) std::cout<<"Unexpected error!"<<std::endl;

    //Ticks for PAL+NTSC in 1uS increments (play speed)
    startl=header[0x6e];
    starth=header[0x6f];
    ntsc_ticks = startl|starth<<8;

    startl=header[0x78];
    starth=header[0x79];
    pal_ticks = startl|starth<<8;

    if(header[0x7a] & 0x2) {
        pal = ntsc = true;
    }
    else {
        pal = (header[0x7a] & 0x1);
        ntsc = !pal;
    }

    if(!ntsc) {
        printf("NTSC not available, and that's all I'm supporting right now.\n");
        return false;
    }

    uses_banks = false;
    map = new mapper_nsf(this);
    for(int i=0;i<8;++i) {
        if(header[0x70+i]) uses_banks = true;
    }

    if(uses_banks) {
        std::cout<<std::hex<<load_addr<<"\t"<<filesize-0x80<<" "<<filesize/0x1000<<filesize % 0x1000<<std::endl;
        load_addr &= 0xfff;
        size_t prom_size = filesize - 0x80 + (load_addr&0xFFF);
        //assert(prom_size > 0 && prom_size + 0x8000 > rst_addr);
        if(prom_size < 0x8000) prom_size = 0x8000;
        prom.resize(prom_size, 0);
        for(int i=0;i<8;++i) {
            map->put_pbyte(0, header[0x70+i], 0x5ff8+i);
        }
        load_addr += 0x8000;
    }
    else {
        size_t prom_size = 0x8000;
        //size_t prom_size = filesize - 0x80 + load_addr;
        //assert(prom_size > 0 && prom_size + 0x8000 > rst_addr);
        prom.resize(prom_size, 0);
        //prom.resize(0x8000,0);
    }
    std::cout<<"PROM size: "<<std::dec<<prom.size()<<"(0x"<<std::hex<<prom.size()<<")"<<std::endl;
    prom_w.resize(prom.size());

    filein.read(reinterpret_cast<char*>(&prom[load_addr-0x8000]),filesize-0x80);
    for(unsigned int i=0;i<prom.size()-1;++i) {
        prom_w[i] = prom[i] | (prom[i+1]<<(8));
    }

    mirror_mode=VERT; //vertical mirrored
    crom.resize(CHR_PAGE_SIZE,0);

    filein.close();

    nsf = true;
    sram = true;

    return true;
}

// Assembly:
subq $0x378, %rsp            # imm = 0x378
movq %rdi, 0x368(%rsp)
movq %rsi, 0x360(%rsp)
movq 0x368(%rsp), %rax
movq %rax, 0xe0(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x4430
movq 0x360(%rsp), %rdi
callq 0x41a0
movq %rax, 0xe8(%rsp)
movl $0x4, %edi
movl $0x8, %esi
callq 0x113b0
movl %eax, 0xf0(%rsp)
jmp 0xfd91
movl 0xf0(%rsp), %edx
movq 0xe8(%rsp), %rsi
leaq 0x158(%rsp), %rdi
callq 0x4250
jmp 0xfdaf
movq 0x158(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x158(%rsp,%rax), %rdi
callq 0x4480
movb %al, 0xdf(%rsp)
jmp 0xfdd1
movb 0xdf(%rsp), %al
testb $0x1, %al
jne 0xfdde
jmp 0xfe01
leaq 0x158(%rsp), %rdi
callq 0x45e0
movb %al, 0xde(%rsp)
jmp 0xfdf4
movb 0xde(%rsp), %al
testb $0x1, %al
jne 0xfe41
jmp 0xfe01
leaq 0x158(%rsp), %rdi
callq 0x40d0
jmp 0xfe10
movb $0x0, 0x377(%rsp)
movl $0x1, 0x148(%rsp)
jmp 0x10b99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
jmp 0x10bb7
xorl %eax, %eax
movl %eax, %esi
leaq 0x158(%rsp), %rdi
movl $0x2, %edx
callq 0x44d0
jmp 0xfe59
leaq 0x158(%rsp), %rdi
callq 0x4670
movq %rdx, 0xc8(%rsp)
movq %rax, 0xd0(%rsp)
jmp 0xfe78
movq 0xc8(%rsp), %rax
movq 0xd0(%rsp), %rcx
movq %rcx, 0x138(%rsp)
movq %rax, 0x140(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x113d0
movq %rax, 0xc0(%rsp)
jmp 0xfeaf
movq 0xe0(%rsp), %rax
movq 0xc0(%rsp), %rcx
movl %ecx, 0x8c(%rax)
xorl %edx, %edx
movl %edx, %esi
leaq 0x158(%rsp), %rdi
callq 0x44d0
jmp 0xfed8
movq 0xe0(%rsp), %rax
cmpl $0x100, 0x8c(%rax)      # imm = 0x100
jge 0xff13
leaq 0x158(%rsp), %rdi
callq 0x40d0
jmp 0xfefb
movb $0x0, 0x377(%rsp)
movl $0x1, 0x148(%rsp)
jmp 0x10b99
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movb $0x0, 0x137(%rsp)
movl $0x80, %esi
leaq 0x137(%rsp), %rdx
callq 0x113e0
jmp 0xff3b
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x114a0
movq %rax, %rsi
leaq 0x158(%rsp), %rdi
movl $0x80, %edx
callq 0x4490
jmp 0xff67
movq 0x27042(%rip), %rdi     # 0x36fb0
leaq 0x1b520(%rip), %rsi     # 0x2b495
callq 0x43c0
jmp 0xff7c
movl $0x0, 0x130(%rsp)
cmpl $0x20, 0x130(%rsp)
jge 0xffd2
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movslq 0x130(%rsp), %rsi
callq 0x114a0
movzbl (%rax), %esi
leaq 0x1b4ea(%rip), %rdi     # 0x2b49e
xorl %eax, %eax
callq 0x4050
jmp 0xffbd
jmp 0xffbf
movl 0x130(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x130(%rsp)
jmp 0xff87
movq 0x26fd7(%rip), %rdi     # 0x36fb0
leaq 0x1b4c5(%rip), %rsi     # 0x2b4a5
callq 0x43c0
jmp 0xffe7
movl $0x0, 0x12c(%rsp)
cmpl $0x20, 0x12c(%rsp)
jge 0x1003d
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movslq 0x12c(%rsp), %rsi
callq 0x114a0
movzbl (%rax), %esi
leaq 0x1b490(%rip), %rdi     # 0x2b4af
xorl %eax, %eax
callq 0x4050
jmp 0x10028
jmp 0x1002a
movl 0x12c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x12c(%rsp)
jmp 0xfff2
movq 0x26f6c(%rip), %rdi     # 0x36fb0
leaq 0x1b45a(%rip), %rsi     # 0x2b4a5
callq 0x43c0
jmp 0x10052
movl $0x0, 0x128(%rsp)
cmpl $0x20, 0x128(%rsp)
jge 0x10105
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movslq 0x128(%rsp), %rsi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x20, %eax
jl 0x100db
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movslq 0x128(%rsp), %rsi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x7f, %eax
jge 0x100db
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movslq 0x128(%rsp), %rsi
callq 0x114a0
movzbl (%rax), %esi
leaq 0x1b3e5(%rip), %rdi     # 0x2b4b5
xorl %eax, %eax
callq 0x4050
jmp 0x100d9
jmp 0x100ed
leaq 0x1b3c8(%rip), %rdi     # 0x2b4aa
xorl %eax, %eax
callq 0x4050
jmp 0x100eb
jmp 0x100ed
jmp 0x100ef
movl 0x128(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x128(%rsp)
jmp 0x1005d
movq 0x26ea4(%rip), %rdi     # 0x36fb0
movq 0x26e7d(%rip), %rsi     # 0x36f90
callq 0x4400
jmp 0x1011a
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x4e, %eax
jne 0x101b3
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movl $0x1, %esi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x45, %eax
jne 0x101b3
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movl $0x2, %esi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x53, %eax
jne 0x101b3
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movl $0x3, %esi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x4d, %eax
jne 0x101b3
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movl $0x4, %esi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x1a, %eax
je 0x102b7
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movq %rdi, 0xa0(%rsp)
xorl %eax, %eax
movl %eax, 0xbc(%rsp)
movl %eax, %esi
callq 0x114a0
movq 0xa0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0xac(%rsp)
movl $0x1, %esi
callq 0x114a0
movq 0xa0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0xb0(%rsp)
movl $0x2, %esi
callq 0x114a0
movq 0xa0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0xb4(%rsp)
movl $0x3, %esi
callq 0x114a0
movq 0xa0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0xb8(%rsp)
movl $0x4, %esi
callq 0x114a0
movl 0xac(%rsp), %esi
movl 0xb0(%rsp), %edx
movl 0xb4(%rsp), %ecx
movl 0xb8(%rsp), %r8d
movq %rax, %rdi
movl 0xbc(%rsp), %eax
movzbl (%rdi), %r9d
leaq 0x1b2b9(%rip), %rdi     # 0x2b532
callq 0x4050
jmp 0x10280
leaq 0x1b2d1(%rip), %rdi     # 0x2b558
xorl %eax, %eax
callq 0x4050
jmp 0x10290
leaq 0x158(%rsp), %rdi
callq 0x40d0
jmp 0x1029f
movb $0x0, 0x377(%rsp)
movl $0x1, 0x148(%rsp)
jmp 0x10b99
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movl $0x5, %esi
callq 0x114a0
movzbl (%rax), %eax
cmpl $0x1, %eax
je 0x10325
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movl $0x5, %esi
callq 0x114a0
movzbl (%rax), %esi
leaq 0x1b28e(%rip), %rdi     # 0x2b583
xorl %eax, %eax
callq 0x4050
jmp 0x102fe
leaq 0x158(%rsp), %rdi
callq 0x40d0
jmp 0x1030d
movb $0x0, 0x377(%rsp)
movl $0x1, 0x148(%rsp)
jmp 0x10b99
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movl $0x6, %esi
callq 0x114a0
movq 0xe0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0xbc(%rdi)
addq $0x10, %rdi
movl $0x7, %esi
callq 0x114a0
movq 0xe0(%rsp), %rdi
movzbl (%rax), %eax
subl $0x1, %eax
movl %eax, 0xc0(%rdi)
addq $0x10, %rdi
movl $0x8, %esi
callq 0x114a0
movq 0xe0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x124(%rsp)
addq $0x10, %rdi
movl $0x9, %esi
callq 0x114a0
movq 0xe0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x120(%rsp)
movl 0x124(%rsp), %eax
movl 0x120(%rsp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movl %eax, 0xb8(%rdi)
addq $0x10, %rdi
movl $0xa, %esi
callq 0x114a0
movq 0xe0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x124(%rsp)
addq $0x10, %rdi
movl $0xb, %esi
callq 0x114a0
movq 0xe0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x120(%rsp)
movl 0x124(%rsp), %eax
movl 0x120(%rsp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movl %eax, 0x94(%rdi)
addq $0x10, %rdi
movl $0xc, %esi
callq 0x114a0
movq 0xe0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x124(%rsp)
addq $0x10, %rdi
movl $0xd, %esi
callq 0x114a0
movq 0xe0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x120(%rsp)
movl 0x124(%rsp), %eax
movl 0x120(%rsp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movl %eax, 0x98(%rdi)
addq $0x10, %rdi
movl $0x6e, %esi
callq 0x114a0
movq 0xe0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x124(%rsp)
addq $0x10, %rdi
movl $0x6f, %esi
callq 0x114a0
movq 0xe0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x120(%rsp)
movl 0x124(%rsp), %eax
movl 0x120(%rsp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movl %eax, 0xc4(%rdi)
addq $0x10, %rdi
movl $0x78, %esi
callq 0x114a0
movq 0xe0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x124(%rsp)
addq $0x10, %rdi
movl $0x79, %esi
callq 0x114a0
movq 0xe0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x120(%rsp)
movl 0x124(%rsp), %eax
movl 0x120(%rsp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movl %eax, 0xc8(%rdi)
addq $0x10, %rdi
movl $0x7a, %esi
callq 0x114a0
movzbl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1055c
movq 0xe0(%rsp), %rax
movb $0x1, 0xcd(%rax)
movb $0x1, 0xcc(%rax)
jmp 0x105a4
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movl $0x7a, %esi
callq 0x114a0
movq %rax, %rcx
movq 0xe0(%rsp), %rax
movzbl (%rcx), %ecx
andl $0x1, %ecx
cmpl $0x0, %ecx
setne %cl
andb $0x1, %cl
movb %cl, 0xcc(%rax)
movb 0xcc(%rax), %cl
xorb $-0x1, %cl
andb $0x1, %cl
movb %cl, 0xcd(%rax)
movq 0xe0(%rsp), %rax
testb $0x1, 0xcd(%rax)
jne 0x105dd
leaq 0x1afec(%rip), %rdi     # 0x2b5a8
xorl %eax, %eax
callq 0x4050
jmp 0x105c5
movb $0x0, 0x377(%rsp)
movl $0x1, 0x148(%rsp)
jmp 0x10b99
movq 0xe0(%rsp), %rax
movb $0x0, 0xcf(%rax)
movl $0x38, %edi
callq 0x43d0
movq %rax, 0x98(%rsp)
jmp 0x10600
movq 0xe0(%rsp), %rsi
movq 0x98(%rsp), %rdi
callq 0x29da0
jmp 0x10617
movq 0xe0(%rsp), %rax
movq 0x98(%rsp), %rcx
movq %rcx, (%rax)
movl $0x0, 0x11c(%rsp)
cmpl $0x8, 0x11c(%rsp)
jge 0x106ae
movq 0xe0(%rsp), %rdi
addq $0x10, %rdi
movl 0x11c(%rsp), %eax
addl $0x70, %eax
movslq %eax, %rsi
callq 0x114a0
cmpb $0x0, (%rax)
je 0x10699
movq 0xe0(%rsp), %rax
movb $0x1, 0xcf(%rax)
jmp 0x10699
movq 0x98(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x150(%rsp)
movl %eax, 0x14c(%rsp)
callq 0x4390
jmp 0x10bb7
jmp 0x1069b
movl 0x11c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x11c(%rsp)
jmp 0x10635
movq 0xe0(%rsp), %rax
testb $0x1, 0xcf(%rax)
je 0x108e5
movq 0x268e6(%rip), %rdi     # 0x36fb0
leaq 0xf4f(%rip), %rsi       # 0x11620
callq 0x4150
movq %rax, 0x90(%rsp)
jmp 0x106e0
movq 0x90(%rsp), %rdi
movq 0xe0(%rsp), %rax
movl 0xb8(%rax), %esi
callq 0x4660
movq %rax, 0x88(%rsp)
jmp 0x10705
movq 0x88(%rsp), %rdi
leaq 0x1aa58(%rip), %rsi     # 0x2b16c
callq 0x43c0
movq %rax, 0x80(%rsp)
jmp 0x10723
movq 0x80(%rsp), %rdi
movq 0xe0(%rsp), %rax
movl 0x8c(%rax), %esi
addl $-0x80, %esi
callq 0x4660
movq %rax, 0x78(%rsp)
jmp 0x10748
movq 0x78(%rsp), %rdi
leaq 0x1ad59(%rip), %rsi     # 0x2b4ad
callq 0x43c0
movq %rax, 0x70(%rsp)
jmp 0x10760
movq 0x70(%rsp), %rdi
movq 0xe0(%rsp), %rax
movl 0x8c(%rax), %esi
movl %esi, %eax
addl $0xfff, %eax            # imm = 0xFFF
testl %esi, %esi
cmovsl %eax, %esi
sarl $0xc, %esi
callq 0x4660
movq %rax, 0x68(%rsp)
jmp 0x1078e
movq 0x68(%rsp), %rdi
movq 0xe0(%rsp), %rax
movl 0x8c(%rax), %esi
movl %esi, %ecx
addl $0xfff, %ecx            # imm = 0xFFF
testl %esi, %esi
movl %esi, %eax
cmovsl %ecx, %eax
andl $0xfffff000, %eax       # imm = 0xFFFFF000
subl %eax, %esi
callq 0x4660
movq %rax, 0x60(%rsp)
jmp 0x107c3
movq 0x60(%rsp), %rdi
movq 0x267c1(%rip), %rsi     # 0x36f90
callq 0x4400
jmp 0x107d6
movq 0xe0(%rsp), %rcx
movl 0xb8(%rcx), %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, 0xb8(%rcx)
movl 0x8c(%rcx), %eax
subl $0x80, %eax
movl 0xb8(%rcx), %ecx
andl $0xfff, %ecx            # imm = 0xFFF
addl %ecx, %eax
cltq
movq %rax, 0x110(%rsp)
cmpq $0x8000, 0x110(%rsp) # imm = 0x8000
jae 0x1082c
movq $0x8000, 0x110(%rsp) # imm = 0x8000
movq 0xe0(%rsp), %rdi
addq $0x28, %rdi
movq 0x110(%rsp), %rsi
movb $0x0, 0x10f(%rsp)
leaq 0x10f(%rsp), %rdx
callq 0x113e0
jmp 0x10857
movl $0x0, 0x108(%rsp)
cmpl $0x8, 0x108(%rsp)
jge 0x108c9
movq 0xe0(%rsp), %rdi
movq (%rdi), %rax
movq %rax, 0x58(%rsp)
addq $0x10, %rdi
movl 0x108(%rsp), %eax
addl $0x70, %eax
movslq %eax, %rsi
callq 0x114a0
movq 0x58(%rsp), %rdi
movzbl (%rax), %edx
movl 0x108(%rsp), %ecx
addl $0x5ff8, %ecx           # imm = 0x5FF8
movq (%rdi), %rax
movq 0x20(%rax), %rax
xorl %esi, %esi
callq *%rax
jmp 0x108b4
jmp 0x108b6
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0x10862
movq 0xe0(%rsp), %rax
movl 0xb8(%rax), %ecx
addl $0x8000, %ecx           # imm = 0x8000
movl %ecx, 0xb8(%rax)
jmp 0x1091e
movq 0xe0(%rsp), %rdi
movq $0x8000, 0x100(%rsp) # imm = 0x8000
addq $0x28, %rdi
movq 0x100(%rsp), %rsi
movb $0x0, 0xff(%rsp)
leaq 0xff(%rsp), %rdx
callq 0x113e0
jmp 0x1091c
jmp 0x1091e
movq 0x2668b(%rip), %rdi     # 0x36fb0
leaq 0x1acba(%rip), %rsi     # 0x2b5e6
callq 0x43c0
movq %rax, 0x50(%rsp)
jmp 0x10938
movq 0x50(%rsp), %rdi
leaq -0x1ec4(%rip), %rsi     # 0xea80
callq 0x4150
movq %rax, 0x48(%rsp)
jmp 0x10950
movq 0xe0(%rsp), %rdi
addq $0x28, %rdi
callq 0x11640
movq 0x48(%rsp), %rdi
movq %rax, %rsi
callq 0x40f0
movq %rax, 0x40(%rsp)
jmp 0x10975
movq 0x40(%rsp), %rdi
leaq 0x1ac71(%rip), %rsi     # 0x2b5f2
callq 0x43c0
movq %rax, 0x38(%rsp)
jmp 0x1098d
movq 0x38(%rsp), %rdi
leaq 0xc87(%rip), %rsi       # 0x11620
callq 0x4150
movq %rax, 0x30(%rsp)
jmp 0x109a5
movq 0xe0(%rsp), %rdi
addq $0x28, %rdi
callq 0x11640
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x40f0
movq %rax, 0x28(%rsp)
jmp 0x109ca
movq 0x28(%rsp), %rdi
leaq 0x1bb0c(%rip), %rsi     # 0x2c4e2
callq 0x43c0
movq %rax, 0x20(%rsp)
jmp 0x109e2
movq 0x20(%rsp), %rdi
movq 0x265a2(%rip), %rsi     # 0x36f90
callq 0x4400
jmp 0x109f5
movq 0xe0(%rsp), %rdi
movq %rdi, %rax
addq $0x40, %rax
movq %rax, 0x18(%rsp)
addq $0x28, %rdi
callq 0x11640
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x11560
jmp 0x10a21
movq 0xe0(%rsp), %rax
movq %rax, %rdi
addq $0x28, %rdi
movl 0xb8(%rax), %eax
addl $0xffff8000, %eax       # imm = 0xFFFF8000
movslq %eax, %rsi
callq 0x114a0
movq %rax, %rsi
movq 0xe0(%rsp), %rax
movl 0x8c(%rax), %eax
addl $-0x80, %eax
movslq %eax, %rdx
leaq 0x158(%rsp), %rdi
callq 0x4490
jmp 0x10a69
movl $0x0, 0xf8(%rsp)
movq 0xe0(%rsp), %rdi
movl 0xf8(%rsp), %eax
movq %rax, 0x10(%rsp)
addq $0x28, %rdi
callq 0x11640
movq %rax, %rcx
movq 0x10(%rsp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x10b2f
movq 0xe0(%rsp), %rdi
addq $0x28, %rdi
movl 0xf8(%rsp), %eax
movl %eax, %esi
callq 0x114a0
movq 0xe0(%rsp), %rdi
movzbl (%rax), %eax
movl %eax, 0x8(%rsp)
addq $0x28, %rdi
movl 0xf8(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x114a0
movq 0xe0(%rsp), %rdi
movq %rax, %rcx
movl 0x8(%rsp), %eax
movzbl (%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movl %eax, 0xc(%rsp)
addq $0x40, %rdi
movl 0xf8(%rsp), %eax
movl %eax, %esi
callq 0x11600
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
movl 0xf8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xf8(%rsp)
jmp 0x10a74
movq 0xe0(%rsp), %rdi
movl $0x0, 0x88(%rdi)
addq $0x58, %rdi
movb $0x0, 0xf7(%rsp)
movl $0x2000, %esi           # imm = 0x2000
leaq 0xf7(%rsp), %rdx
callq 0x113e0
jmp 0x10b61
leaq 0x158(%rsp), %rdi
callq 0x40d0
jmp 0x10b70
movq 0xe0(%rsp), %rax
movb $0x1, 0xce(%rax)
movb $0x1, 0xa0(%rax)
movb $0x1, 0x377(%rsp)
movl $0x1, 0x148(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x4100
movb 0x377(%rsp), %al
andb $0x1, %al
addq $0x378, %rsp            # imm = 0x378
retq
leaq 0x158(%rsp), %rdi
callq 0x4100
movq 0x150(%rsp), %rdi
callq 0x4680
nopw %cs:(%rax,%rax)