LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/ekg[P]fastahack/Fasta.cpp
// Function: FastaReference::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void FastaReference::open(string reffilename) {
    filename = reffilename;
    if (!(file = fopen(filename.c_str(), "r"))) {
        cerr << "could not open " << filename << endl;
        exit(1);
    }
    index = new FastaIndex();
    struct stat stFileInfo; 
    string indexFileName = filename + index->indexFileExtension(); 
    // if we can find an index file, use it
    if(stat(indexFileName.c_str(), &stFileInfo) == 0) { 
        index->readIndexFile(indexFileName);
    } else { // otherwise, read the reference and generate the index file in the cwd
        cerr << "index file " << indexFileName << " not found, generating..." << endl;
        index->indexReference(filename);
        index->writeIndexFile(indexFileName);
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x130, %rsp            # imm = 0x130
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
movq %r14, %rdi
callq 0x3150
movq 0x8(%rbx), %rdi
leaq 0x3efd(%rip), %rsi      # 0x814f
callq 0x32c0
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x4374
movl $0x280, %edi            # imm = 0x280
callq 0x3270
movq %rax, %r15
movq %rax, %rdi
callq 0x3750
movq %r15, 0x40(%rbx)
leaq 0x40(%rsp), %r15
movq %r15, %rdi
callq 0x420a
movq %rsp, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4a9c
leaq 0x40(%rsp), %rdi
callq 0x3120
movq (%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x3230
testl %eax, %eax
je 0x4335
movq 0x7d32(%rip), %rdi      # 0xbff0
leaq 0x3d5b(%rip), %rsi      # 0x8020
callq 0x3250
movq %rsp, %rsi
movq %rax, %rdi
callq 0x3220
leaq 0x3e85(%rip), %rsi      # 0x8161
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
movq 0x40(%rbx), %r15
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x3330
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0x3c2c
leaq 0x20(%rsp), %rdi
callq 0x3120
movq 0x40(%rbx), %r14
leaq 0x60(%rsp), %rbx
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3330
movq %r14, %rdi
movq %rbx, %rsi
callq 0x40a4
jmp 0x4357
movq 0x40(%rbx), %r14
leaq 0x80(%rsp), %rbx
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3330
movq %r14, %rdi
movq %rbx, %rsi
callq 0x37ca
movq %rbx, %rdi
callq 0x3120
movq %rsp, %rdi
callq 0x3120
addq $0x130, %rsp            # imm = 0x130
popq %rbx
popq %r14
popq %r15
retq
movq 0x7c75(%rip), %rdi      # 0xbff0
leaq 0x3dcf(%rip), %rsi      # 0x8151
callq 0x3250
movq %rax, %rdi
movq %r14, %rsi
callq 0x3220
movq %rax, %rdi
callq 0x3130
pushq $0x1
popq %rdi
callq 0x32f0
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0x43c1
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0x43c1
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x3120
jmp 0x43e7
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
jmp 0x43ea
movq %rax, %rbx
movl $0x280, %esi            # imm = 0x280
movq %r15, %rdi
callq 0x3280
jmp 0x43ef
movq %rax, %rbx
movq %rsp, %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x3430
nop
// File: /workspace/github_cpp_makefile_star2_O2/ekg[P]fastahack/Fasta.cpp
// Function: FastaReference::~FastaReference()
FastaReference::~FastaReference(void) {
    if (file != NULL)
      fclose(file);
    if (index != NULL)
      delete index;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x28(%rdi), %rdi
testq %rdi, %rdi
je 0x440d
callq 0x3260
movq 0x40(%rbx), %r14
testq %r14, %r14
je 0x442b
movq %r14, %rdi
callq 0x414e
movl $0x280, %esi            # imm = 0x280
movq %r14, %rdi
callq 0x3280
addq $0x8, %rbx
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x3120
// File: /workspace/github_cpp_makefile_star2_O2/ekg[P]fastahack/Fasta.cpp
// Function: FastaReference::getSequence(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
string FastaReference::getSequence(string seqname) {
    FastaIndexEntry entry = index->entry(seqname);
    int bytes_per_newline = entry.line_len - entry.line_blen;
    int newline_bytes_in_sequence = entry.length / entry.line_blen * bytes_per_newline;
    int seqlen = newline_bytes_in_sequence + entry.length;
    char* seq = (char*) calloc (seqlen + 1, sizeof(char));
    fseek64(file, entry.offset, SEEK_SET);
    string s;
    if (fread(seq, sizeof(char), seqlen, file)) {
        seq[seqlen] = '\0';
        char* pbegin = seq;
        char* pend = seq + (seqlen/sizeof(char));
        pend = remove(pbegin, pend, '\r');
        pend = remove(pbegin, pend, '\n');
        pend = remove(pbegin, pend, '\0');
        s = seq;
        free(seq);
        s.resize((pend - pbegin)/sizeof(char));
    }
    return s;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movq 0x40(%rsi), %r15
leaq 0x48(%rsp), %r13
movq %r13, %rdi
movq %rdx, %rsi
callq 0x3330
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4192
leaq 0x48(%rsp), %rdi
callq 0x3120
movl 0x44(%rsp), %esi
movl 0x30(%rsp), %ecx
movl 0x40(%rsp), %edi
subl %edi, %esi
movl %ecx, %eax
cltd
idivl %edi
imull %esi, %eax
leal (%rax,%rcx), %r13d
addl %ecx, %eax
incl %eax
movslq %eax, %rdi
pushq $0x1
popq %rbp
movq %rbp, %rsi
callq 0x3190
movq %rax, %r15
movq 0x28(%r12), %rdi
movq 0x38(%rsp), %rsi
xorl %edx, %edx
callq 0x3170
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
andq $0x0, 0x8(%rbx)
movb $0x0, 0x10(%rbx)
movslq %r13d, %r13
movq 0x28(%r12), %rcx
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x3380
testq %rax, %rax
je 0x4551
leaq (%r15,%r13), %rsi
movb $0x0, (%r15,%r13)
leaq 0xf(%rsp), %rdx
movb $0xd, (%rdx)
movq %r15, %rdi
callq 0x6056
leaq 0xf(%rsp), %rdx
movb $0xa, (%rdx)
movq %r15, %rdi
movq %rax, %rsi
callq 0x6056
leaq 0xf(%rsp), %rdx
movb $0x0, (%rdx)
movq %r15, %rdi
movq %rax, %rsi
callq 0x6056
movq %rax, %r12
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3470
movq %r15, %rdi
callq 0x32d0
subq %r15, %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3340
leaq 0x10(%rsp), %rdi
callq 0x3120
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x457b
jmp 0x457b
jmp 0x457b
movq %rax, %r15
movq %r13, %r14
jmp 0x4586
movq %rax, %r15
movq %rbx, %rdi
callq 0x3120
movq %r14, %rdi
callq 0x3120
movq %r15, %rdi
callq 0x3430
// File: /workspace/github_cpp_makefile_star2_O2/ekg[P]fastahack/Fasta.cpp
// Function: FastaReference::sequenceNameStartingWith(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
string FastaReference::sequenceNameStartingWith(string seqnameStart) {
    try {
        return (*index)[seqnameStart].name;
    } catch (exception& e) {
        cerr << e.what() << ": unable to find index entry for " << seqnameStart << endl;
        exit(1);
    }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rdi, %r14
movq 0x40(%rsi), %rdi
movq %rdx, %rsi
callq 0x49d8
movq %r14, %rdi
movq %rax, %rsi
callq 0x3330
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq %rax, %r14
cmpl $0x1, %edx
jne 0x461c
movq %r14, %rdi
callq 0x3100
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0x7a0e(%rip), %rdi      # 0xbff0
movq %rax, %rsi
callq 0x3250
leaq 0x3b8a(%rip), %rsi      # 0x817b
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3220
movq %rax, %rdi
callq 0x3130
pushq $0x1
popq %rdi
callq 0x32f0
movq %rax, %r14
callq 0x33f0
movq %r14, %rdi
callq 0x3430
movq %rax, %rdi
callq 0x4a69
// File: /workspace/github_cpp_makefile_star2_O2/ekg[P]fastahack/Fasta.cpp
// Function: FastaReference::getTargetSubSequence[abi:cxx11](FastaRegion&)
string FastaReference::getTargetSubSequence(FastaRegion& target) {
    if (target.startPos == -1) {
        return getSequence(target.startSeq);
    } else {
        return getSubSequence(target.startSeq, target.startPos - 1, target.length());
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
cmpl $-0x1, 0x20(%rdx)
je 0x4682
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x3330
movl 0x20(%r12), %ecx
movl 0x24(%r12), %eax
movl %eax, %edx
subl %ecx, %edx
decl %ecx
incl %edx
testl %eax, %eax
pushq $0x1
popq %r8
cmovgl %edx, %r8d
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x46d6
jmp 0x46a0
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x3330
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x443e
movq %r14, %rdi
callq 0x3120
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x46c9
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x3430
// File: /workspace/github_cpp_makefile_star2_O2/ekg[P]fastahack/FastaHack.cpp
// Function: printSummary()
void printSummary() {
    cerr << "usage: fastahack [options] <fasta reference>" << endl
         << endl
         << "options:" << endl 
         << "    -i, --index          generate fasta index <fasta reference>.fai" << endl
         << "    -r, --region REGION  print the specified region" << endl
         << "    -c, --stdin          read a stream of line-delimited region specifiers on stdin" << endl
         << "                         and print the corresponding sequence for each on stdout" << endl
         << "    -e, --entropy        print the shannon entropy of the specified region" << endl
         << "    -d, --dump           print the fasta file in the form 'seq_name <tab> sequence'" << endl
         << endl
         << "REGION is of the form <seq>, <seq>:<start>[sep]<end>, <seq1>:<start>[sep]<seq2>:<end>" << endl
         << "where start and end are 1-based, and the region includes the end position." << endl
         << "[sep] is \"-\" or \"..\"" << endl
         << endl
         << "Specifying a sequence name alone will return the entire sequence, specifying" << endl
         << "range will return that range, and specifying a single coordinate pair, e.g." << endl
         << "<seq>:<start> will return just that base." << endl
         << endl
         << "author: Erik Garrison <erik.garrison@bc.edu>" << endl;
}

// Assembly:
pushq %rax
movq 0x5ecc(%rip), %rdi      # 0xbff0
leaq 0x211d(%rip), %rsi      # 0x8248
callq 0x3250
movq %rax, %rdi
callq 0x3130
movq %rax, %rdi
callq 0x3130
leaq 0x212e(%rip), %rsi      # 0x8275
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x2120(%rip), %rsi      # 0x827e
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x214d(%rip), %rsi      # 0x82c2
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x216a(%rip), %rsi      # 0x82f6
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x21a7(%rip), %rsi      # 0x834a
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x21e1(%rip), %rsi      # 0x839b
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x2215(%rip), %rsi      # 0x83e6
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
movq %rax, %rdi
callq 0x3130
leaq 0x224a(%rip), %rsi      # 0x843a
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x2289(%rip), %rsi      # 0x8490
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x22bd(%rip), %rsi      # 0x84db
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
movq %rax, %rdi
callq 0x3130
leaq 0x22b3(%rip), %rsi      # 0x84f0
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x22e9(%rip), %rsi      # 0x853d
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
leaq 0x231e(%rip), %rsi      # 0x8589
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
movq %rax, %rdi
callq 0x3130
leaq 0x2329(%rip), %rsi      # 0x85b3
movq %rax, %rdi
callq 0x3250
movq %rax, %rdi
popq %rax
jmp 0x3130
// File: /workspace/github_cpp_makefile_star2_O2/ekg[P]fastahack/disorder.c
// Function: shannon_H(char*, long long)
float
shannon_H(char* buf, 
	  long long length)
{
  int i = 0;
  float bits = 0.0;
  char* itr=NULL; //values of itr should be zero to 255
  unsigned char token;
  int num_events = 0; //`length' parameter
  float freq = 0.0; //loop variable for holding freq from m_token_freq[]
  float entropy = 0.0; //running entropy sum

  if(NULL==buf || 0==length)
    return 0.0;

  if(0==LIBDISORDER_INITIALIZED)
    initialize_lib();

  itr = buf;
  m_maxent = 0.0;
  m_ratio = 0.0;
  num_events = length;
  get_token_frequencies(itr, num_events); //modifies m_token_freqs[]
  //set m_num_tokens by counting unique m_token_freqs entries
  count_num_tokens(); 

  if(m_num_tokens>LIBDO_MAX_BYTES)
  {
    //report error somehow?
    return 0.0;
  }

  //iterate through whole m_token_freq array, but only count
  //spots that have a registered token (i.e., freq>0)
  for(i=0;i<LIBDO_MAX_BYTES;i++)
  {
    if(0!=m_token_freqs[i])
    {
      token = i;
      freq = ((float)m_token_freqs[token]); 
      m_token_probs[token] = (freq / ((float)num_events));
      entropy += m_token_probs[token] * log2(m_token_probs[token]);
    }
  }

  bits = -1.0 * entropy;
  m_maxent = log2(m_num_tokens);
  m_ratio = bits / m_maxent;

  return bits;
}

// Assembly:
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
xorps %xmm2, %xmm2
jne 0x7145
cmpb $0x0, 0x532e(%rip)      # 0xc340
jne 0x7036
xorl %eax, %eax
leaq 0x5333(%rip), %rcx      # 0xc350
cmpq $0x400, %rax            # imm = 0x400
je 0x702f
andl $0x0, (%rax,%rcx)
addq $0x4, %rax
jmp 0x701d
movb $0x1, 0x530a(%rip)      # 0xc340
pushq %r14
pushq %rbx
subq $0x28, %rsp
andl $0x0, 0x5300(%rip)      # 0xc344
andl $0x0, 0x52fd(%rip)      # 0xc348
movq %rsi, %rax
shlq $0x20, %rax
xorl %ecx, %ecx
leaq 0x52f5(%rip), %rbx      # 0xc350
cmpq $0x400, %rcx            # imm = 0x400
je 0x706e
andl $0x0, (%rcx,%rbx)
addq $0x4, %rcx
jmp 0x705b
sarq $0x20, %rax
xorl %ecx, %ecx
testq %rax, %rax
cmovleq %rcx, %rax
cmpq %rcx, %rax
je 0x708c
movzbl (%rdi,%rcx), %edx
incl (%rbx,%rdx,4)
incq %rcx
jmp 0x707b
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0x400, %rax            # imm = 0x400
je 0x70a5
cmpl $0x1, (%rax,%rbx)
sbbl $-0x1, %ecx
addq $0x4, %rax
jmp 0x7090
movl %ecx, 0x52a1(%rip)      # 0xc34c
cmpl $0x100, %ecx            # imm = 0x100
ja 0x713e
cvtsi2ss %esi, %xmm0
movss %xmm0, 0x8(%rsp)
xorps %xmm1, %xmm1
xorl %r14d, %r14d
cmpq $0x400, %r14            # imm = 0x400
je 0x7107
movl (%r14,%rbx), %eax
testl %eax, %eax
je 0x7101
cvtsi2ss %eax, %xmm0
divss 0x8(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
movaps %xmm1, 0x10(%rsp)
callq 0x3320
movaps 0x10(%rsp), %xmm1
mulss 0xc(%rsp), %xmm0
addss %xmm0, %xmm1
addq $0x4, %r14
jmp 0x70c7
xorps 0x1572(%rip), %xmm1     # 0x8680
movaps %xmm1, 0x10(%rsp)
movl 0x5233(%rip), %edi      # 0xc34c
callq 0x7162
movaps 0x10(%rsp), %xmm2
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x5215(%rip)     # 0xc344
movaps %xmm2, %xmm1
divss %xmm0, %xmm1
movss %xmm1, 0x520a(%rip)     # 0xc348
addq $0x28, %rsp
popq %rbx
popq %r14
movaps %xmm2, %xmm0
retq
// File: /workspace/github_cpp_makefile_star2_O2/t0mm4rx[P]piscine_cpp/day06/ex01/main.cpp
// Function: serialize()
void	*serialize(void)
{
	const char	alph[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	char		*res = new char[16 + sizeof(int)];

	for (int i = 0; i < 8; i++)
		res[i] = alph[std::rand() % 62];
	*reinterpret_cast<int*>(res + 8) = std::rand();
	for (int i = 8 + sizeof(int); (unsigned int)i < 16 + sizeof(int); i++)
		res[i] = alph[std::rand() % 62];
	return ((void*)res);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq $0x14
popq %rdi
callq 0x1030
movq %rax, %rbx
xorl %r12d, %r12d
pushq $0x3e
popq %r14
leaq 0xd60(%rip), %r15       # 0x2010
callq 0x1040
cmpq $0x8, %r12
je 0x12cf
cltd
idivl %r14d
movslq %edx, %rax
movb (%rax,%r15), %al
movb %al, (%rbx,%r12)
incq %r12
jmp 0x12b0
movl %eax, 0x8(%rbx)
pushq $0xc
popq %r12
cmpq $0x14, %r12
je 0x12f5
callq 0x1040
cltd
idivl %r14d
movslq %edx, %rax
movb (%rax,%r15), %al
movb %al, (%rbx,%r12)
incq %r12
jmp 0x12d6
movq %rbx, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/t0mm4rx[P]piscine_cpp/day06/ex01/main.cpp
// Function: deserialize(void*)
Data 	*deserialize(void *addr)
{
	Data	*data = new Data;
	char	*raw = reinterpret_cast<char*>(addr);

	data->s1 = std::string(raw, 8);
	data->s2 = std::string(raw + 8 + sizeof(int), 8);
	data->n = *reinterpret_cast<int *>(raw + 8);
	return (data);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
pushq $0x48
popq %rdi
callq 0x10e0
movq %rax, %r14
addq $0x10, %rax
movq %rax, (%r14)
andq $0x0, 0x8(%r14)
xorl %eax, %eax
movb %al, 0x10(%r14)
leaq 0x28(%r14), %r15
leaq 0x38(%r14), %rcx
movq %rcx, 0x28(%r14)
andq $0x0, 0x30(%r14)
movb %al, 0x38(%r14)
leaq -0x38(%rbp), %r13
movq %r13, -0x10(%r13)
leaq 0x8(%rbx), %rdx
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1496
movq %r14, %rdi
movq %r12, %rsi
callq 0x1100
movq %r12, %rdi
callq 0x1050
leaq 0xc(%rbx), %rsi
movq %r13, (%r12)
leaq 0x14(%rbx), %rdx
movq %r12, %rdi
callq 0x1496
movq %r15, %rdi
movq %r12, %rsi
callq 0x1100
movq %r12, %rdi
callq 0x1050
movl 0x8(%rbx), %eax
movl %eax, 0x20(%r14)
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/t0mm4rx[P]piscine_cpp/day06/ex01/main.cpp
// Function: main
int		main(void)
{
	void	*addr = serialize();
	Data	*data = deserialize(addr);

	std::srand(time(0));
	std::cout << "s1: " << data->s1 << std::endl;
	std::cout << "s2: " << data->s2 << std::endl;
	std::cout << "n : " << data->n << std::endl;

	delete []reinterpret_cast<char*>(addr);
	delete data;
	return (0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
callq 0x128c
movq %rax, %r14
movq %rax, %rdi
callq 0x1301
movq %rax, %rbx
xorl %edi, %edi
callq 0x10b0
movl %eax, %edi
callq 0x10c0
movq 0x2bf1(%rip), %r15      # 0x3fd8
leaq 0xc61(%rip), %rsi       # 0x204f
movq %r15, %rdi
callq 0x10d0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10a0
movq %rax, %rdi
callq 0x1060
leaq 0xc44(%rip), %rsi       # 0x2054
movq %r15, %rdi
callq 0x10d0
leaq 0x28(%rbx), %rsi
movq %rax, %rdi
callq 0x10a0
movq %rax, %rdi
callq 0x1060
leaq 0xc26(%rip), %rsi       # 0x2059
movq %r15, %rdi
callq 0x10d0
movl 0x20(%rbx), %esi
movq %rax, %rdi
callq 0x1130
movq %rax, %rdi
callq 0x1060
movq %r14, %rdi
callq 0x1110
movq %rbx, %rdi
callq 0x1476
pushq $0x48
popq %rsi
movq %rbx, %rdi
callq 0x10f0
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/ikatanic[P]lcskpp/./utils.h
// Function: product_fits_in_63bits(unsigned long, unsigned long, unsigned long*)
bool product_fits_in_63bits(uint64_t a, uint64_t b, uint64_t* c) {
  if (a <= LLONG_MAX / b) {
    *c = a * b;
    return true;
  }
  return false;
}

// Assembly:
movq %rdx, %rcx
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
xorl %edx, %edx
divq %rsi
cmpq %rdi, %rax
jb 0x239a
imulq %rdi, %rsi
movq %rsi, (%rcx)
cmpq %rdi, %rax
setae %al
retq
// File: /workspace/github_cpp_makefile_star2_O2/ikatanic[P]lcskpp/./utils.h
// Function: power_fits_in_63bits(unsigned long, unsigned long, unsigned long*)
bool power_fits_in_63bits(uint64_t a, uint64_t b, uint64_t* c) {
  *c = 1;
  while (b > 0) {
    if (!product_fits_in_63bits(*c, a, c)) return false;
    b--;
  }
  return true;
}

// Assembly:
movq %rdx, %rcx
movq $0x1, (%rdx)
pushq $0x1
popq %r9
movabsq $0x7fffffffffffffff, %r8 # imm = 0x7FFFFFFFFFFFFFFF
movq %rsi, %r10
subq $0x1, %r10
jb 0x23db
movq %r8, %rax
xorl %edx, %edx
divq %rdi
cmpq %r9, %rax
jb 0x23db
imulq %rdi, %r9
movq %r9, (%rcx)
movq %r10, %rsi
jmp 0x23bc
testq %rsi, %rsi
sete %al
retq
// File: /workspace/github_cpp_makefile_star2_O2/ikatanic[P]lcskpp/./utils.h
// Function: radix_sort(std::vector<std::pair<unsigned long, int>, std::allocator<std::pair<unsigned long, int>>>&, unsigned long)
void radix_sort(vector<pair<uint64_t, int>> &v, uint64_t maks) {
  const int len = 9;
  const int sz = 1 << len;
  const int mask = sz - 1;
  static int pos[sz + 1];

  vector<pair<uint64_t, int>> w(v.size());

  int n_blocks = 0;
  while (maks > 1) {
    n_blocks++;
    maks >>= len;
  }

  for (int block = 0; block < n_blocks; ++block) {
    memset(pos, 0, sizeof pos);

    for (auto &x : v)
      ++pos[((x.first >> (block * len)) & mask) + 1];

    for (int i = 0; i < sz; ++i)
      pos[i + 1] += pos[i];

    for (auto &x : v)
      w[pos[(x.first >> (block * len)) & mask]++] = x;

    v.swap(w);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq 0x8(%rdi), %rsi
movq %rdi, 0x8(%rsp)
subq (%rdi), %rsi
sarq $0x4, %rsi
leaq 0x10(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x36c0
xorl %edx, %edx
cmpq $0x1, %r14
jbe 0x2442
shrq $0x9, %r14
incq %rdx
jmp 0x2433
movq 0x8(%rsp), %rax
movq (%rax), %rbp
movq 0x8(%rax), %r12
movq 0x10(%rax), %rsi
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rax
xorl %r11d, %r11d
leaq 0x5cea(%rip), %r14      # 0x8150
movq %rdx, 0x28(%rsp)
cmpq %r11, %rdx
je 0x2556
movq %rcx, %r15
movq %rax, %r13
movq %rsi, 0x30(%rsp)
movl $0x804, %edx            # imm = 0x804
movq %r14, %rdi
xorl %esi, %esi
movq %r11, %rbx
callq 0x20d0
movq %rbx, %r11
leaq (%rbx,%rbx,8), %rcx
movq %rbp, %rax
cmpq %r12, %rax
je 0x24b7
movq (%rax), %rdx
shrq %cl, %rdx
andl $0x1ff, %edx            # imm = 0x1FF
incl 0x4(%r14,%rdx,4)
addq $0x10, %rax
jmp 0x249b
xorl %eax, %eax
xorl %edx, %edx
movq 0x30(%rsp), %r10
cmpq $0x200, %rdx            # imm = 0x200
je 0x24d8
addl 0x4(%r14,%rdx,4), %eax
movl %eax, 0x4(%r14,%rdx,4)
incq %rdx
jmp 0x24c0
movq 0x10(%rsp), %rax
movq %rbp, %rdx
cmpq %r12, %rdx
je 0x2516
movq (%rdx), %rsi
movq %rsi, %rdi
shrq %cl, %rdi
andl $0x1ff, %edi            # imm = 0x1FF
movslq (%r14,%rdi,4), %r8
leal 0x1(%r8), %r9d
movl %r9d, (%r14,%rdi,4)
shlq $0x4, %r8
movq %rsi, (%rax,%r8)
movl 0x8(%rdx), %esi
movl %esi, 0x8(%rax,%r8)
addq $0x10, %rdx
jmp 0x24e0
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rax
movq %rdx, (%rax)
movq %r15, 0x8(%rax)
movq %r13, 0x10(%rax)
movq %rbp, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq %r10, 0x20(%rsp)
incq %r11
movq %r10, %rax
movq %r12, %rcx
movq %r13, %rsi
movq %r15, %r12
movq %rdx, %rbp
movq 0x28(%rsp), %rdx
jmp 0x246b
leaq 0x10(%rsp), %rdi
callq 0x3a30
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/ikatanic[P]lcskpp/./utils.h
// Function: radix_sort(std::vector<unsigned long, std::allocator<unsigned long>>&, unsigned long)
void radix_sort(vector<uint64_t> &v, uint64_t maks) {
  const int max_len = 9;
  static int pos[(1 << max_len) + 1];

  vector<uint64_t> w(v.size());

  int n_bits = log2(maks);

  int shift = 0;
  while (n_bits > 0) {
    int len = min(max_len, n_bits);
    int sz = 1 << len;
    int mask = sz - 1;

    memset(pos, 0, sz * sizeof(int));

    for (auto &x : v)
      ++pos[((x >> shift) & mask) + 1];

    for (int i = 0; i < sz; ++i)
      pos[i + 1] += pos[i];

    for (auto &x : v)
      w[pos[(x >> shift) & mask]++] = x;
    shift += len;
    n_bits -= len;

    v.swap(w);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x8(%rdi), %rsi
subq (%rdi), %rsi
sarq $0x3, %rsi
leaq 0x10(%rsp), %r15
leaq 0x7(%rsp), %rdx
movq %r15, %rdi
callq 0x3712
movq %r14, %rdi
callq 0x23f1
movq (%rbx), %r8
movq 0x8(%rbx), %r12
movq %rbx, 0x28(%rsp)
movq 0x10(%rbx), %rdi
movq 0x8(%r15), %rcx
movq 0x10(%r15), %rsi
xorl %r11d, %r11d
leaq 0x6396(%rip), %r14      # 0x8960
testl %eax, %eax
jle 0x26d4
movq %rsi, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdi, 0x40(%rsp)
cmpl $0x9, %eax
pushq $0x9
popq %rcx
movl %eax, 0xc(%rsp)
cmovbl %eax, %ecx
pushq $0x1
popq %rax
movl %eax, %r13d
shll %cl, %r13d
leal -0x1(%r13), %ebp
pushq $0x4
popq %rax
movl %eax, %edx
movl %ecx, 0x8(%rsp)
shll %cl, %edx
movq %r14, %rdi
xorl %esi, %esi
movq %r8, %r15
movq %r11, %rbx
callq 0x20d0
movq %rbx, %r11
movl %r11d, %ecx
movq %r15, %rax
cmpq %r12, %rax
je 0x2639
movq (%rax), %rdx
shrq %cl, %rdx
movl %ebp, %esi
andl %edx, %esi
incl 0x4(%r14,%rsi,4)
addq $0x8, %rax
jmp 0x261f
movl %r13d, %eax
xorl %edx, %edx
movq 0x40(%rsp), %r10
cmpq %rdx, %rax
je 0x2656
movl (%r14,%rdx,4), %esi
addl %esi, 0x4(%r14,%rdx,4)
incq %rdx
jmp 0x2643
movq 0x10(%rsp), %rax
movq %r15, %rdx
cmpq %r12, %rdx
je 0x2688
movq (%rdx), %rsi
movq %rsi, %rdi
shrq %cl, %rdi
movl %ebp, %r8d
andl %edi, %r8d
movslq (%r14,%r8,4), %rdi
leal 0x1(%rdi), %r9d
movl %r9d, (%r14,%r8,4)
movq %rsi, (%rax,%rdi,8)
addq $0x8, %rdx
jmp 0x265e
movl 0x8(%rsp), %ecx
addl %ecx, %r11d
movl 0xc(%rsp), %eax
subl %ecx, %eax
movq 0x10(%rsp), %rdx
movq 0x28(%rsp), %rcx
movq %rdx, (%rcx)
movq 0x38(%rsp), %r8
movq %r8, 0x8(%rcx)
movq 0x30(%rsp), %rdi
movq %rdi, 0x10(%rcx)
movq %r15, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %r10, %rsi
movq %r12, %rcx
movq %r8, %r12
movq %rdx, %r8
jmp 0x25ca
leaq 0x10(%rsp), %rdi
callq 0x3ae8
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/main.cpp
// Function: Rnes::md5OfFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
std::string md5OfFile(std::string file) {
  std::string salt = "$1$$";
  struct crypt_data data = {0};
  std::string contents;

  using namespace std;
  namespace io = boost::iostreams;

  io::stream<io::mapped_file_source> stream(file);
  stream >> contents;

  auto ret = std::string(crypt_r(contents.c_str(), salt.c_str(), &data));
  for_each(begin(ret), end(ret), [](char &c) {
    if (c == '/' or c == '.') {
      c = 'x';
    }
  });
  return ret.substr(salt.size());
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x8210, %rsp           # imm = 0x8210
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x19dae(%rip), %rsi     # 0x2a024
leaq -0x78(%rbp), %rdi
leaq -0x8218(%rbp), %rdx
callq 0x10d2c
leaq -0x8218(%rbp), %rdi
movl $0x8000, %edx           # imm = 0x8000
xorl %esi, %esi
callq 0xb2b0
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x218(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x10d68
leaq -0x218(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xb3a0
movq -0x58(%rbp), %rdi
movq -0x78(%rbp), %rsi
leaq -0x8218(%rbp), %rdx
callq 0xb9a0
leaq -0x38(%rbp), %rdi
leaq -0x11(%rbp), %rdx
movq %rax, %rsi
callq 0x10d2c
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x10314
movb (%rax,%rdx), %sil
andb $-0x2, %sil
cmpb $0x2e, %sil
jne 0x1030f
movb $0x78, (%rax,%rdx)
incq %rdx
jmp 0x102f8
movq -0x70(%rbp), %rdx
leaq -0x38(%rbp), %rsi
pushq $-0x1
popq %rcx
movq %rbx, %rdi
callq 0xb7d0
leaq -0x38(%rbp), %rdi
callq 0xb9d8
leaq -0x218(%rbp), %rdi
callq 0x10e1e
leaq -0x58(%rbp), %rdi
callq 0xb9d8
leaq -0x78(%rbp), %rdi
callq 0xb9d8
movq %rbx, %rax
addq $0x8210, %rsp           # imm = 0x8210
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0xb9d8
jmp 0x10370
jmp 0x1036d
movq %rax, %rbx
leaq -0x218(%rbp), %rdi
callq 0x10e1e
jmp 0x10381
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0xb9d8
leaq -0x78(%rbp), %rdi
callq 0xb9d8
movq %rbx, %rdi
callq 0xb4e0
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/main.cpp
// Function: Rnes::getUserHomeDir[abi:cxx11]()
std::string getUserHomeDir() {
  struct passwd pwd = {0};
  struct passwd *pwdRet;
  char buf[1024];

  getpwuid_r(getuid(), &pwd, buf, sizeof(buf), &pwdRet);

  using namespace std;
  string homeDir(pwdRet->pw_dir);
  return homeDir;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq -0x60(%rbp), %r14
movaps %xmm0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
callq 0xb2e0
leaq -0x460(%rbp), %rdx
leaq -0x28(%rbp), %r15
movl $0x400, %ecx            # imm = 0x400
movl %eax, %edi
movq %r14, %rsi
movq %r15, %r8
callq 0xb570
movq (%r15), %rax
movq 0x20(%rax), %rsi
leaq -0x19(%rbp), %rdx
movq %rbx, %rdi
callq 0x10d2c
movq %rbx, %rax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/main.cpp
// Function: Rnes::setupDirectories(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void setupDirectories(std::string romMd5) {
  namespace fs = boost::filesystem;

  fs::path homeDir(getUserHomeDir());
  fs::path rnesDir(homeDir);
  rnesDir /= ".rnes";

  if (not fs::exists(rnesDir)) {
    fs::create_directories(rnesDir);
  }

  fs::path gamePath(rnesDir);
  gamePath /= fs::path(romMd5);
  if (not fs::exists(gamePath)) {
    fs::create_directories(gamePath);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x80, %rsp
movq %rdi, %rbx
leaq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0x1039b
leaq -0x90(%rbp), %rdi
movq %r14, %rsi
callq 0xb430
leaq -0x30(%rbp), %rdi
callq 0xb9d8
leaq -0x30(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xb430
leaq 0x19ad9(%rip), %rsi     # 0x2a037
leaq -0x30(%rbp), %rdi
callq 0xb740
leaq -0x30(%rbp), %rdi
callq 0x10ed2
testb %al, %al
jne 0x1057d
leaq -0x30(%rbp), %rdi
callq 0x10ef6
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xb430
leaq -0x70(%rbp), %rdi
movq %rbx, %rsi
callq 0xb430
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xb910
leaq -0x70(%rbp), %rdi
callq 0xb9d8
leaq -0x50(%rbp), %rdi
callq 0x10ed2
testb %al, %al
jne 0x105c2
leaq -0x50(%rbp), %rdi
callq 0x10ef6
leaq -0x50(%rbp), %rdi
callq 0xb9d8
leaq -0x30(%rbp), %rdi
callq 0xb9d8
leaq -0x90(%rbp), %rdi
callq 0xb9d8
addq $0x80, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0xb9d8
jmp 0x1060f
jmp 0x1060c
jmp 0x1061a
movq %rax, %rbx
jmp 0x10626
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
jmp 0x1062d
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0xb9d8
jmp 0x1061d
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0xb9d8
leaq -0x90(%rbp), %rdi
callq 0xb9d8
movq %rbx, %rdi
callq 0xb4e0
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/main.cpp
// Function: Rnes::verifyRomExists(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void verifyRomExists(std::string romFile) {
  namespace fs = boost::filesystem;
  using namespace std;

  fs::path path(romFile);
  if (not fs::exists(path) or not fs::is_regular_file(path)) {
    cerr << "specified rom file does not exist: " << romFile << endl;
    exit(-1);
  }
  cerr << "rom md5: " << md5OfFile(romFile) << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x60, %rsp
movq %rdi, %rbx
leaq -0x70(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xb430
movq %r14, %rdi
callq 0x10ed2
testb %al, %al
je 0x106d7
leaq -0x70(%rbp), %rdi
callq 0x10f02
testb %al, %al
je 0x106d7
movq 0x30971(%rip), %rdi     # 0x40fe8
leaq 0x199e3(%rip), %rsi     # 0x2a061
callq 0xb450
movq %rax, %r14
leaq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0xb430
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1025b
leaq -0x50(%rbp), %rsi
movq %r14, %rdi
callq 0xb280
movq %rax, %rdi
callq 0xb7e0
leaq -0x50(%rbp), %rdi
callq 0xb9d8
leaq -0x30(%rbp), %rdi
callq 0xb9d8
leaq -0x70(%rbp), %rdi
callq 0xb9d8
addq $0x60, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq 0x3090a(%rip), %rdi     # 0x40fe8
leaq 0x19958(%rip), %rsi     # 0x2a03d
callq 0xb450
movq %rax, %rdi
movq %rbx, %rsi
callq 0xb280
movq %rax, %rdi
callq 0xb7e0
pushq $-0x1
popq %rdi
callq 0xb510
movq %rax, %rbx
jmp 0x10718
jmp 0x10723
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0xb9d8
leaq -0x30(%rbp), %rdi
callq 0xb9d8
jmp 0x10726
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0xb9d8
movq %rbx, %rdi
callq 0xb4e0
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/main.cpp
// Function: Rnes::loadNesState(Rnes::Nes*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void loadNesState(Nes *nes, std::string saveFile) {
  namespace io = boost::iostreams;
  namespace fs = boost::filesystem;
  using namespace std;

  try {
    io::stream<io::mapped_file_source> stream(saveFile);
    unique_ptr<SaveState> gameState{new SaveState{}};

    // Read out state from save file.
    gameState->ParseFromIstream(&stream);

    // Restore nes state.
    nes->restore(*gameState.get());

    cerr << "State restored" << endl;
  } catch (const std::ios_base::failure &exception) {
    cerr << "Exception: " << exception.what() << endl;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rdi, %rbx
leaq -0x1c0(%rbp), %rdi
xorl %edx, %edx
callq 0x10d68
pushq $0x60
popq %rdi
callq 0xb140
movq %rax, %r15
movq %rax, %rdi
callq 0x10f26
movq %r15, -0x20(%rbp)
leaq -0x1c0(%rbp), %rsi
movq %r15, %rdi
callq 0xb050
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1b2e4
movq 0x30858(%rip), %rdi     # 0x40fe8
leaq 0x198d4(%rip), %rsi     # 0x2a06b
callq 0xb450
movq %rax, %rdi
callq 0xb7e0
leaq -0x20(%rbp), %rdi
callq 0x10f32
leaq -0x1c0(%rbp), %rdi
callq 0x10e1e
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r14
movq %rax, %rbx
pushq $0x60
popq %rsi
movq %r15, %rdi
callq 0xb0f0
jmp 0x107f9
movq %rdx, %r14
movq %rax, %rbx
jmp 0x107f9
movq %rdx, %r14
movq %rax, %rbx
jmp 0x10805
movq %rdx, %r14
movq %rax, %rbx
leaq -0x20(%rbp), %rdi
callq 0x10f32
leaq -0x1c0(%rbp), %rdi
callq 0x10e1e
cmpl $0x1, %r14d
jne 0x1085a
movq %rbx, %rdi
callq 0xb060
movq %rax, %rbx
movq 0x307cb(%rip), %rdi     # 0x40fe8
leaq 0x19856(%rip), %rsi     # 0x2a07a
callq 0xb450
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0xb450
movq %rax, %rdi
callq 0xb7e0
callq 0xb5d0
jmp 0x107b9
movq %rax, %rbx
callq 0xb5d0
movq %rbx, %rdi
callq 0xb4e0
movq %rax, %rdi
callq 0x10d1e
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/main.cpp
// Function: Rnes::saveNesState(Rnes::Nes*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void saveNesState(Nes *nes, std::string saveFile) {
  namespace io = boost::iostreams;
  namespace fs = boost::filesystem;
  using namespace std;

  // Useless comment.

  try {
    io::stream<io::file_sink> stream(saveFile);
    unique_ptr<SaveState> gameState{new SaveState{}};

    // Save nes state.
    nes->save(*gameState.get());

    // Serialize save to file.
    gameState->SerializeToOstream(&stream);

    cerr << "state saved." << endl;
  } catch (const std::ios_base::failure &exception) {
    cerr << "Exception: " << exception.what() << endl;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rdi, %rbx
leaq -0x1b8(%rbp), %rdi
xorl %edx, %edx
callq 0x10f56
pushq $0x60
popq %rdi
callq 0xb140
movq %rax, %r15
movq %rax, %rdi
callq 0x10f26
movq %r15, -0x20(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1b208
leaq -0x1b8(%rbp), %rsi
movq %r15, %rdi
callq 0xb860
movq 0x30725(%rip), %rdi     # 0x40fe8
leaq 0x197bc(%rip), %rsi     # 0x2a086
callq 0xb450
movq %rax, %rdi
callq 0xb7e0
leaq -0x20(%rbp), %rdi
callq 0x10f32
leaq -0x1b8(%rbp), %rdi
callq 0x11006
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r14
movq %rax, %rbx
pushq $0x60
popq %rsi
movq %r15, %rdi
callq 0xb0f0
jmp 0x1092c
movq %rdx, %r14
movq %rax, %rbx
jmp 0x1092c
movq %rdx, %r14
movq %rax, %rbx
jmp 0x10938
movq %rdx, %r14
movq %rax, %rbx
leaq -0x20(%rbp), %rdi
callq 0x10f32
leaq -0x1b8(%rbp), %rdi
callq 0x11006
cmpl $0x1, %r14d
jne 0x1098d
movq %rbx, %rdi
callq 0xb060
movq %rax, %rbx
movq 0x30698(%rip), %rdi     # 0x40fe8
leaq 0x19723(%rip), %rsi     # 0x2a07a
callq 0xb450
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0xb450
movq %rax, %rdi
callq 0xb7e0
callq 0xb5d0
jmp 0x108ec
movq %rax, %rbx
callq 0xb5d0
movq %rbx, %rdi
callq 0xb4e0
movq %rax, %rdi
callq 0x10d1e
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/ppu.cpp
// Function: Rnes::Ppu::getBgColor()
uint32_t Ppu::getBgColor() {
  uint8_t memColor = load(backColorAddr);
  assert(memColor < sizeof(nesPaletteLut) / sizeof(nesPaletteLut[0]));
  if (isMonochromeMode()) {
    memColor &= 0x30;
  } else {
    memColor &= 0x3f;
  }
  return nesPaletteLut[memColor];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl $0x3f00, %esi           # imm = 0x3F00
callq 0x13440
cmpb $0x40, %al
jae 0x13422
movzbl %al, %ecx
andb $0x30, %al
testb $0x1, 0x29(%rbx)
movzbl %al, %eax
cmovel %ecx, %eax
movzbl %al, %eax
leaq 0x17988(%rip), %rcx     # 0x2ada0
movl (%rcx,%rax,4), %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x17a77(%rip), %rdi     # 0x2aea0
leaq 0x17aac(%rip), %rsi     # 0x2aedc
leaq 0x17aad(%rip), %rcx     # 0x2aee4
pushq $0x3a
popq %rdx
callq 0xb170
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/ppu.cpp
// Function: Rnes::Ppu::getColor(unsigned int, unsigned int, bool)
uint32_t Ppu::getColor(uint32_t palette, uint32_t color, bool sprite) {
  uint8_t memColor;
  assert(color >= 0 && color <= 3);
  if (color == 0) {
    memColor = load(backColorAddr);
  } else {
    uint16_t paletteOffset = sprite ? 0x10 : 0;
    memColor = load(backColorAddr + paletteOffset + 4 * palette + color);
  }
  if (isMonochromeMode()) {
    memColor &= 0x30;
  } else {
    memColor &= 0x3f;
  }
  assert(memColor < sizeof(nesPaletteLut) / sizeof(nesPaletteLut[0]));
  return nesPaletteLut[memColor];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
cmpl $0x4, %edx
jae 0x1349e
movq %rdi, %rbx
movzbl %cl, %eax
shll $0x4, %eax
leal (%rax,%rsi,4), %eax
movl $0x3f00, %ecx           # imm = 0x3F00
addl %edx, %eax
addl %ecx, %eax
testl %edx, %edx
cmovel %ecx, %eax
movzwl %ax, %esi
callq 0x13440
testb $0x1, 0x29(%rbx)
pushq $0x3f
popq %rcx
pushq $0x30
popq %rdx
cmovel %ecx, %edx
andb %al, %dl
movzbl %dl, %eax
leaq 0x1790c(%rip), %rcx     # 0x2ada0
movl (%rcx,%rax,4), %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x17a60(%rip), %rdi     # 0x2af05
leaq 0x17a30(%rip), %rsi     # 0x2aedc
leaq 0x17a6b(%rip), %rcx     # 0x2af1e
pushq $0x45
popq %rdx
callq 0xb170
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/ppu.cpp
// Function: Rnes::Ppu::vramYInc()
void Ppu::vramYInc() {
  if ((vramCurrentAddr & 0x7000) != 0x7000) {
    vramCurrentAddr += 0x1000;
  } else {
    vramCurrentAddr &= ~0x7000;
    int y = (vramCurrentAddr & 0x03e0) >> 5;
    if (y == 29) {
      y = 0;
      vramCurrentAddr ^= 0x0800;
    } else if (y == 31) {
      y = 0;
    } else {
      y += 1;
    }
    vramCurrentAddr = (vramCurrentAddr & ~0x03e0) | (y << 5);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movzwl 0x138(%rdi), %ecx
movl %ecx, %eax
notl %eax
testw $0x7000, %ax            # imm = 0x7000
jne 0x13519
movl %ecx, %eax
andl $0x8fff, %eax           # imm = 0x8FFF
shrl $0x5, %ecx
andl $0x1f, %ecx
cmpl $0x1f, %ecx
je 0x13515
cmpl $0x1d, %ecx
jne 0x13521
xorl $0x800, %eax            # imm = 0x800
xorl %ecx, %ecx
jmp 0x1352a
addl $0x1000, %ecx           # imm = 0x1000
jmp 0x13534
movzwl %cx, %ecx
shll $0x5, %ecx
addl $0x20, %ecx
andl $0xfffffc1f, %eax       # imm = 0xFFFFFC1F
movzwl %cx, %ecx
orl %eax, %ecx
movw %cx, 0x138(%rdi)
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/ppu.cpp
// Function: Rnes::Ppu::loadPatternTile(unsigned short)
uint16_t Ppu::loadPatternTile(uint16_t addr) {
  uint16_t ret = 0;
  uint16_t a = load(addr);
  uint16_t b = load(addr + 8);
  for (uint32_t i = 0; i < 8; i++) {
    ret |= ((1u << i) & a) << i;
    ret |= ((1u << i) & b) << (i + 1);
  }
  return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
callq 0x13440
movl %eax, %r15d
addl $0x8, %ebx
movzwl %bx, %esi
movq %r14, %rdi
callq 0x13440
movzbl %r15b, %edx
movzbl %al, %esi
xorl %eax, %eax
pushq $0x1
popq %rdi
xorl %ecx, %ecx
cmpl $0x8, %ecx
je 0x135e5
movl %edi, %r8d
shll %cl, %r8d
movl %r8d, %r9d
andl %edx, %r9d
shll %cl, %r9d
andl %esi, %r8d
incl %ecx
shll %cl, %r8d
orl %r9d, %r8d
orl %r8d, %eax
jmp 0x135c1
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/ppu.cpp
// Function: Rnes::Ppu::save(Rnes::PpuState&)
void Ppu::save(PpuState &pb) {
  pb.set_cycle(cycle);
  pb.set_frame(frame);

  for (int i = 0; i < REG_COUNT; i++) {
    pb.add_regs(regs[i]);
  }

  for (int i = 0; i < spriteRamSize; i++) {
    PpuState_SpriteState *sprite = pb.add_spriteram();
    sprite->set_ycoordminus1(spriteRam[i].yCoordMinus1);
    sprite->set_tileindex(spriteRam[i].tileIndex);
    sprite->set_attr(spriteRam[i].attr);
    sprite->set_xcoord(spriteRam[i].xCoord);
  }

  pb.set_vramtoggle(vramToggle);
  pb.set_vramfinexscroll(vramFineXScroll);
  pb.set_vramcurrentaddr(vramCurrentAddr);
  pb.set_vramtempaddr(vramTempAddr);
  pb.set_vrammachineaddr(vramMachineAddr);
  pb.set_vramreadlatch(vramReadLatch);
  pb.set_scrollingmachinestate(scrollingMachineState);
  pb.set_xscrollorigin(xScrollOrigin);
  pb.set_yscrollorigin(yScrollOrigin);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movq 0x18(%rdi), %rax
movq %rax, 0x40(%rsi)
movq 0x20(%rdi), %rax
orl $0x3, 0x10(%rsi)
movq %rax, 0x48(%rsi)
xorl %r15d, %r15d
cmpq $0x8, %r15
je 0x13631
movzbl 0x28(%r14,%r15), %esi
movq %rbx, %rdi
callq 0x1419a
incq %r15
jmp 0x13618
leaq 0x28(%rbx), %r15
xorl %r12d, %r12d
cmpq $0x40, %r12
je 0x13673
movq %r15, %rdi
callq 0x141ba
movzbl 0x30(%r14,%r12,4), %ecx
movl %ecx, 0x18(%rax)
movzbl 0x31(%r14,%r12,4), %ecx
movl %ecx, 0x1c(%rax)
movzbl 0x32(%r14,%r12,4), %ecx
movl %ecx, 0x20(%rax)
movzbl 0x33(%r14,%r12,4), %ecx
orl $0xf, 0x10(%rax)
movl %ecx, 0x24(%rax)
incq %r12
jmp 0x13638
movl 0x130(%r14), %eax
movl 0x10(%rbx), %ecx
movl %ecx, %edx
orl $0x4, %edx
movl %edx, 0x10(%rbx)
movl %eax, 0x50(%rbx)
movl 0x134(%r14), %eax
movl %eax, 0x54(%rbx)
movzwl 0x138(%r14), %eax
movl %eax, 0x58(%rbx)
movzwl 0x13a(%r14), %eax
movl %eax, 0x5c(%rbx)
movzwl 0x13c(%r14), %eax
movl %eax, 0x60(%rbx)
movzbl 0x13e(%r14), %eax
movl %ecx, %edx
orl $0xfc, %edx
movl %edx, 0x10(%rbx)
movl %eax, 0x64(%rbx)
movl 0x140(%r14), %eax
movl %eax, 0x68(%rbx)
movzbl 0x144(%r14), %eax
movl %eax, 0x6c(%rbx)
movzbl 0x145(%r14), %eax
orl $0x7fc, %ecx            # imm = 0x7FC
movl %ecx, 0x10(%rbx)
movl %eax, 0x70(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/ppu.cpp
// Function: Rnes::Ppu::restore(Rnes::PpuState const&)
void Ppu::restore(const PpuState &pb) {
  cycle = pb.cycle();
  frame = pb.frame();

  for (int i = 0; i < pb.regs_size(); i++) {
    regs[i] = pb.regs(i);
  }

  for (int i = 0; i < pb.spriteram_size(); i++) {
    const PpuState_SpriteState &sprite = pb.spriteram(i);
    spriteRam[i].yCoordMinus1 = sprite.ycoordminus1();
    spriteRam[i].tileIndex = sprite.tileindex();
    spriteRam[i].attr = sprite.attr();
    spriteRam[i].xCoord = sprite.xcoord();
  }

  vramToggle = pb.vramtoggle();
  vramFineXScroll = pb.vramfinexscroll();
  vramCurrentAddr = pb.vramcurrentaddr();
  vramTempAddr = pb.vramtempaddr();
  vramMachineAddr = pb.vrammachineaddr();
  vramReadLatch = pb.vramreadlatch();
  scrollingMachineState = pb.scrollingmachinestate();
  xScrollOrigin = pb.xscrollorigin();
  yScrollOrigin = pb.yscrollorigin();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movq 0x40(%rsi), %rax
movq %rax, 0x18(%rdi)
movq 0x48(%rsi), %rax
movq %rax, 0x20(%rdi)
xorl %r15d, %r15d
movslq 0x18(%r14), %rax
cmpq %rax, %r15
jge 0x1373e
movq %r14, %rdi
movl %r15d, %esi
callq 0x14230
movb %al, 0x28(%rbx,%r15)
incq %r15
jmp 0x13720
leaq 0x28(%r14), %r15
xorl %r12d, %r12d
movslq 0x30(%r14), %rax
cmpq %rax, %r12
jge 0x1377e
movq %r15, %rdi
movl %r12d, %esi
callq 0x14242
movb 0x18(%rax), %cl
movb %cl, 0x30(%rbx,%r12,4)
movb 0x1c(%rax), %cl
movb %cl, 0x31(%rbx,%r12,4)
movb 0x20(%rax), %cl
movb %cl, 0x32(%rbx,%r12,4)
movb 0x24(%rax), %al
movb %al, 0x33(%rbx,%r12,4)
incq %r12
jmp 0x13745
movl 0x50(%r14), %eax
movl %eax, 0x130(%rbx)
movl 0x54(%r14), %eax
movl %eax, 0x134(%rbx)
movzwl 0x58(%r14), %eax
movw %ax, 0x138(%rbx)
movzwl 0x5c(%r14), %eax
movw %ax, 0x13a(%rbx)
movzwl 0x60(%r14), %eax
movw %ax, 0x13c(%rbx)
movb 0x64(%r14), %al
movb %al, 0x13e(%rbx)
movl 0x68(%r14), %eax
movl %eax, 0x140(%rbx)
movb 0x6c(%r14), %al
movb %al, 0x144(%rbx)
movb 0x70(%r14), %al
movb %al, 0x145(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/mindbeast[P]rnes/ppu.cpp
// Function: Rnes::Ppu::tick()
void Ppu::tick() {
  uint32_t scanline = getScanline();
  uint32_t lineClock = getScanlineOffset();
  bool isVblank = scanline >= 240 and scanline <= 260;

  // Update vram registers
  if (!isVblank and renderBackgroundEnabled()) {
    if (lineClock == 255 and scanline < 240) {
      render(scanline);
      nes->notifyScanlineComplete();
    }
    if (lineClock == 256) {
      vramYInc();
    }
    if (lineClock == 257) {
      vramXReset();
    }
    if (scanline == 261 and lineClock >= 280 and lineClock <= 304) {
      vramYReset();
    }
  }

  // set and unset vblank register
  if (scanline == vblankScanline and lineClock == 0) {
    setVblankFlag();
    if (nmiOnVblank()) {
      nmiRequested = true;
    }
  } else if (scanline == vblankScanelineEnd and lineClock == 0) {
    clearVblankFlag();
    clearSprite0Hit();
    clearLostSprites();
  } else if (scanline == vblankScanelineEnd and lineClock == (ticksPerScanline - 1)) {
    sdl->renderSync();
    /*
    float currentTime = timerGetMs();
    float diffTime = currentTime - lastFrameTimeMs;
    if (diffTime < frameTimeMs) {
        float waitTime = frameTimeMs - diffTime;
        sleepMs(waitTime);
    }
    lastFrameTimeMs = timerGetMs();
    */
    frame += 1;
  }
  cycle += 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x18(%rdi), %rax
movl $0x155, %ecx            # imm = 0x155
xorl %edx, %edx
divq %rcx
movq %rdx, %r14
movl $0x106, %ecx            # imm = 0x106
xorl %edx, %edx
divq %rcx
movq %rdx, %r15
leal -0xf0(%rdx), %eax
cmpw $0x15, %ax
jb 0x1398b
testb $0x8, 0x29(%rbx)
je 0x1398b
cmpq $0xff, %r14
setne %al
cmpq $0xf0, %r15
setae %cl
orb %al, %cl
jne 0x1390b
movq %rbx, %rdi
movl %r15d, %esi
callq 0x13c78
movq 0x8(%rbx), %rdi
callq 0x1b0c8
jmp 0x13949
cmpw $0x101, %r14w           # imm = 0x101
je 0x13928
movzwl %r14w, %eax
cmpl $0x100, %eax            # imm = 0x100
jne 0x13949
movq %rbx, %rdi
callq 0x134e4
jmp 0x13949
movl $0xfffffbe0, %eax       # imm = 0xFFFFFBE0
andl 0x138(%rbx), %eax
movzwl 0x13a(%rbx), %ecx
andl $0x41f, %ecx            # imm = 0x41F
orl %eax, %ecx
movw %cx, 0x138(%rbx)
cmpq $0x105, %r15            # imm = 0x105
setne %al
leal -0x118(%r14), %ecx
cmpw $0x19, %cx
setae %cl
orb %al, %cl
jne 0x1398b
movzwl 0x138(%rbx), %eax
andl $0x41f, %eax            # imm = 0x41F
movzwl 0x13a(%rbx), %ecx
andl $0xfffffbe0, %ecx       # imm = 0xFFFFFBE0
orl %eax, %ecx
movw %cx, 0x138(%rbx)
movb $0x1, %al
jmp 0x139c1
movq %r15, %rax
xorq $0xf1, %rax
orq %r14, %rax
jne 0x139a8
orb $-0x80, 0x2a(%rbx)
cmpb $0x0, 0x28(%rbx)
jns 0x139de
movb $0x1, (%rbx)
jmp 0x139de
movl $0x105, %ecx            # imm = 0x105
cmpq %rcx, %r15
sete %al
xorq %rcx, %r15
orq %r14, %r15
jne 0x139c1
andb $0x1f, 0x2a(%rbx)
jmp 0x139de
cmpq $0x154, %r14            # imm = 0x154
setne %cl
xorb $0x1, %al
orb %cl, %al
jne 0x139de
movq 0x10(%rbx), %rdi
callq 0x1c146
incq 0x20(%rbx)
incq 0x18(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop