// File: /workspace/github_cpp_makefile_star2_O2/JMMackenzie[P]binary_to_jass/bin_to_jass_disk.cpp
// Function: score_index(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, double, char)
void score_index(std::string ds2i_prefix,
                 std::string lex_file,
                 const double quant_level,
                 char compression){

	 // Tell JASS that we're using QMX-D1: we need to compute our own deltas
    ANT_compress *compression_scheme;
    if (compression == 'q')
        compression_scheme = new ANT_compress_qmx();
    else if (compression == 'G')
        compression_scheme = new JASS::compress_integer_elias_gamma_simd();
    else if (compression == 'g')
        compression_scheme = new JASS::compress_integer_elias_gamma_simd_vb();
    else
         compression_scheme = nullptr;
    ANT_compress &compressor = *compression_scheme;


    uint32_t sse_alignment = 16;
    std::vector<std::string> m_terms;

    // 1. Read lexicon file and start building posting metadata
    std::ifstream lex_data(lex_file);
    std::string term;
	 uint32_t term_id = 0;
	 while (lex_data >> term) {
	     m_terms.emplace_back(term);
	     ++term_id;
	 }

    std::cerr << "Read " << m_terms.size() << " terms.\n";

    std::string docs_file = ds2i_prefix + ".docs";
    std::string freqs_file = ds2i_prefix + ".freqs";
    std::string sizes_file = ds2i_prefix + ".sizes";

    auto df = fopen(docs_file.c_str(), "rb");
    auto ff = fopen(freqs_file.c_str(), "rb");
    auto sf = fopen(sizes_file.c_str(), "rb");

    std::vector<uint32_t> doc_list;
    std::vector<uint32_t> freq_list;
    std::vector<uint32_t> size_list;

    double global_maximum = 0.0;

    // Get no. docs    
    read_uint32_list(doc_list,df);
    uint32_t no_docs = doc_list[0];

    // Read sizes
    read_uint32_list(size_list,sf);
  
    // validate sizes
    if (size_list.size() != no_docs) {
      std::cerr << "Something went wrong: Sizes not matched with no. docs." 
                << std::endl;
      exit(EXIT_FAILURE);
    }

    std::cerr << "Processing " << no_docs << " documents." << std::endl;

    // Compute mean document length
    float average_len = std::accumulate(size_list.begin(), size_list.end(), 0.0)/no_docs; 

    bm25_t ranker(float(no_docs), average_len);

    term_id = 0;
    while (!feof(df)) {
      read_uint32_list(doc_list,df);
      read_uint32_list(freq_list,ff);
      size_t doc_n = doc_list.size();
      size_t freq_n = freq_list.size();
      if (doc_n != freq_n) {
        std::cerr << "Files are not aligned.\n";
        exit(EXIT_FAILURE);
      }
      // Exhausted our lists
      if (doc_n == 0) {
        break;
      }

      // Query term weight (compute once)
      float w_qt = ranker.query_term_weight(doc_n);

      // Resize our PL

      // Score the PL and dump it
      for (size_t i = 0; i < doc_list.size(); ++i) {
        uint32_t doc_id = doc_list[i];
        uint32_t freq = freq_list[i];
        double impact = w_qt * ranker.doc_term_weight(float(freq), float(size_list[doc_id]));
        global_maximum = std::max(global_maximum, impact);
      }
      ++term_id;
    }

    // Re-read files
    rewind(df);
    rewind(ff);
 
    // Make sure we forward to the right segment
    read_uint32_list(doc_list,df);

    // prepare output
    std::ofstream vocab_terms("CIvocab_terms.bin");
    std::ofstream vocab("CIvocab.bin", std::ofstream::binary);
    std::ofstream postings("CIpostings.bin", std::ofstream::binary);
    size_t terms_offset = 0;
    size_t pl_offset = 0;

    // Tell JASS that we're using QMX-D1: we need to compute our own deltas
    postings.write((char *)&compression, sizeof(uint8_t));
    pl_offset = postings.tellp();


    // Reiterate, quantize, build, and write JASS data
    term_id = 0;
    while (!feof(df)) {
      read_uint32_list(doc_list,df);
      read_uint32_list(freq_list,ff);
      size_t doc_n = doc_list.size();
      size_t freq_n = freq_list.size();
      if (doc_n != freq_n) {
        std::cerr << "Files are not aligned.\n";
        exit(EXIT_FAILURE);
      }
      // Exhausted our lists
      if (doc_n == 0) {
        break;
      }

      float w_qt = ranker.query_term_weight(doc_n);

      // prepare segments vector
      uint32_t max_quant = uint32_t(quant_level);
      std::vector<std::vector<uint32_t>> pl_segments(max_quant);
      std::vector<compressed_segment_t> jass_pl;


      // Score the PL and add it to our structure
      for (size_t i = 0; i < doc_list.size(); ++i) {
        uint32_t doc_id = doc_list[i];
        uint32_t freq = freq_list[i];
        double impact = w_qt * ranker.doc_term_weight(float(freq), float(size_list[doc_id]));
        uint32_t quant_score = std::ceil(quant_level * impact / global_maximum);
        pl_segments[quant_score-1].push_back(doc_id + 1); 
      }

      std::string current_term = m_terms[term_id];

      // Write the offset in the vocab file
      vocab.write((char *)&terms_offset, sizeof(size_t));
      vocab.write((char *)&pl_offset, sizeof(size_t));

      // Write term to the terms file
      vocab_terms << current_term << '\0';
    
      // Update offsets
      terms_offset = vocab_terms.tellp();

      // Deal with postings
     

      // Count non-zero segments and compress them
      uint64_t valid_segments = 0;
      for (size_t j = 0; j < pl_segments.size(); ++j) {
        if (pl_segments[j].size() == 0)
          continue;
      
        // Give the buffer double + some incase of overflow
        std::vector<uint32_t> compressed_segment (2 * pl_segments[j].size() + 1024);
        uint64_t used = compressed_segment.size() * sizeof(compressed_segment[0]);

        // Delta encode the document identifiers
        fastDelta(pl_segments[j].data(), pl_segments[j].size()); 
        compressor.encodeArray(pl_segments[j].data(), pl_segments[j].size(), compressed_segment.data(), &used);

        uint64_t used_padded = ((used + sse_alignment - 1) / sse_alignment) * sse_alignment;  // SSE alignment
        // Resize to padded size
        size_t elements = used_padded/sizeof(uint32_t);
        compressed_segment.resize(elements);
        uint16_t impact = j + 1;
        uint32_t frequency = pl_segments[j].size();
        
        jass_pl.emplace_back(impact, frequency, used, used_padded, std::move(compressed_segment));
           
      } 
      // Tell vocab how many segments are here
      valid_segments = jass_pl.size();
      vocab.write((char *)&valid_segments, sizeof(uint64_t));
 
      // We can now write our PL's to file
      // 1. Write the k pointers to headers via arithmetic
      uint32_t header_size = sizeof(uint16_t) + sizeof(uint64_t) + sizeof(uint64_t) + sizeof(uint32_t);
      // Address of the first header is the (number of headers * size of the pointer) + current postings offset.
      uint64_t header_pointer = valid_segments * sizeof(uint64_t) + pl_offset;
      for (size_t i = 0; i < valid_segments; ++i) {
        postings.write((char *)&header_pointer, sizeof(uint64_t));
        header_pointer += header_size;
      }


      uint64_t posting_offset = header_size * (valid_segments + 1) + valid_segments * sizeof(uint64_t) + pl_offset;
      // Ensure SSE alignment is OK
      size_t sse_offset = ((posting_offset + sse_alignment - 1)/sse_alignment) * sse_alignment;
      size_t sse_padding = sse_offset - posting_offset;
      posting_offset = sse_offset;

      // 2. Let's write the header quads now
      for (size_t i = 0; i < jass_pl.size(); ++i) {
        uint16_t impact = jass_pl[i].impact;
        uint32_t frequency = jass_pl[i].frequency;
        uint64_t length = jass_pl[i].length;
        uint64_t length_with_padding = jass_pl[i].length_with_padding;
        uint64_t end = posting_offset + length;
      
        // Write the data
        postings.write((char *)&impact, sizeof(uint16_t));
        postings.write((char *)&posting_offset, sizeof(uint64_t));
        postings.write((char *)&end, sizeof(uint64_t));
        postings.write((char *)&frequency, sizeof(uint32_t));

        // Update offsets for next round
        posting_offset += length_with_padding;

      }

      // Don't forget the zero block
      uint8_t zero_block[] = {0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0};
      postings.write((char *)&zero_block, header_size);

      // More SSE checks
      if (sse_padding != 0) {
        if (sse_padding > sizeof(zero_block)) {
          std::cerr << "Padding is too large (sorry). Fix the code." << std::endl;
          exit(EXIT_FAILURE);
        }
        // Pad some more zeros
        postings.write((char *)zero_block, sse_padding);
      }

      // 4.  Now we write the actual postings lists
      for (size_t i = 0; i < jass_pl.size(); ++i) {
        postings.write((char *)jass_pl[i].compressed_ids.data(), jass_pl[i].length_with_padding);
      }
  
      pl_offset = postings.tellp();

    ++term_id;
    } 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa18, %rsp            # imm = 0xA18
vmovsd %xmm0, 0xe8(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
movb %dl, 0xf(%rsp)
cmpl $0x47, %edx
je 0x2731
cmpl $0x67, %edx
je 0x2728
cmpl $0x71, %edx
jne 0x274e
pushq $0x18
popq %rdi
callq 0x2170
movq %rax, 0x50(%rsp)
movq %rax, %rdi
callq 0x44f8
jmp 0x2757
leaq 0x5a5c9(%rip), %r15     # 0x5ccf8
jmp 0x2738
leaq 0x5a568(%rip), %r15     # 0x5cca0
addq $0x10, %r15
pushq $0x8
popq %rdi
callq 0x2170
movq %rax, 0x50(%rsp)
movq %r15, (%rax)
jmp 0x2757
movq $0x0, 0x50(%rsp)
vxorpd %xmm0, %xmm0, %xmm0
vmovapd %xmm0, 0x130(%rsp)
andq $0x0, 0x140(%rsp)
leaq 0x810(%rsp), %rdi
pushq $0x8
popq %rdx
movq %r14, %rsi
callq 0x2280
pushq $0x18
popq %rbp
leaq 0x200(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x810(%rsp), %r14
leaq 0x1f0(%rsp), %r15
leaq 0x130(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x21e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x27d5
movq %r12, %rdi
movq %r15, %rsi
callq 0x37a6
jmp 0x27af
movq 0x5a80c(%rip), %rdi     # 0x5cfe8
leaq 0x5585a(%rip), %rsi     # 0x5803d
callq 0x2160
movq 0x138(%rsp), %rsi
subq 0x130(%rsp), %rsi
sarq $0x5, %rsi
movq %rax, %rdi
callq 0x2100
leaq 0x55838(%rip), %rsi     # 0x58043
movq %rax, %rdi
callq 0x2160
leaq 0x55832(%rip), %rdx     # 0x5804c
leaq 0x1d0(%rsp), %rdi
movq %rbx, %rsi
callq 0x37d2
leaq 0x55821(%rip), %rdx     # 0x58052
leaq 0x1b0(%rsp), %rdi
movq %rbx, %rsi
callq 0x37d2
leaq 0x55811(%rip), %rdx     # 0x58059
leaq 0x190(%rsp), %rdi
movq %rbx, %rsi
callq 0x37d2
movq 0x1d0(%rsp), %rdi
leaq 0x557f9(%rip), %rbx     # 0x58060
movq %rbx, %rsi
callq 0x21b0
movq %rax, %r12
movq 0x1b0(%rsp), %rdi
movq %rbx, %rsi
callq 0x21b0
movq %rax, %r13
movq 0x190(%rsp), %rdi
movq %rbx, %rsi
callq 0x21b0
movq %rax, %rbx
vxorpd %xmm0, %xmm0, %xmm0
leaq 0x30(%rsp), %rdi
vmovapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
vmovapd %xmm0, 0x60(%rsp)
andq $0x0, 0x70(%rsp)
vmovapd %xmm0, 0xc0(%rsp)
andq $0x0, 0xd0(%rsp)
movq %r12, %rsi
callq 0x24e7
movq 0x30(%rsp), %rax
movl (%rax), %r14d
leaq 0xc0(%rsp), %rdi
movq %rbx, %rsi
callq 0x24e7
movq 0xc8(%rsp), %rbx
subq 0xc0(%rsp), %rbx
sarq $0x2, %rbx
cmpq %r14, %rbx
jne 0x328d
movq 0x5a6dc(%rip), %rdi     # 0x5cfe8
leaq 0x55787(%rip), %rsi     # 0x5809a
callq 0x2160
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2100
leaq 0x5577c(%rip), %rsi     # 0x580a6
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
callq 0x20d0
movq 0xc0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
vxorpd %xmm0, %xmm0, %xmm0
vmovsd %xmm0, 0x90(%rsp)
callq 0x380a
vcvtsi2sd %r14, %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
vcvtsd2ss %xmm0, %xmm0, %xmm0
vcvtsi2ss %r14, %xmm2, %xmm1
leaq 0x98(%rsp), %rbx
vmovss %xmm1, (%rbx)
vmovss %xmm0, 0x4(%rbx)
leaq 0x30(%rsp), %r14
leaq 0x60(%rsp), %r15
movq %r12, %rdi
callq 0x2270
testl %eax, %eax
jne 0x2a94
movq %r14, %rdi
movq %r12, %rsi
callq 0x24e7
movq %r15, %rdi
movq %r13, %rsi
callq 0x24e7
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rdx
movq %rdx, %rax
subq %rcx, %rax
movq 0x68(%rsp), %rsi
subq 0x60(%rsp), %rsi
cmpq %rsi, %rax
jne 0x3240
cmpq %rcx, %rdx
je 0x2a94
sarq $0x2, %rax
js 0x29e8
vcvtsi2ss %rax, %xmm2, %xmm0
jmp 0x29fd
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
vcvtsi2ss %rax, %xmm2, %xmm0
vaddss %xmm0, %xmm0, %xmm0
movq %rbx, %rdi
callq 0x3822
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movq 0x60(%rsp), %rdx
movq 0xc0(%rsp), %rsi
vmovss 0x9c(%rsp), %xmm1
xorl %edi, %edi
cmpq %rdi, %rcx
je 0x2989
movl (%rax,%rdi,4), %r8d
movl (%rdx,%rdi,4), %r9d
vcvtsi2ss %r9, %xmm4, %xmm2
movl (%rsi,%r8,4), %r8d
vcvtsi2ss %r8, %xmm4, %xmm3
vdivss %xmm1, %xmm3, %xmm3
vmulss 0x555ab(%rip), %xmm3, %xmm3 # 0x58004
vaddss 0x555a7(%rip), %xmm3, %xmm3 # 0x58008
vmulss 0x555a3(%rip), %xmm3, %xmm3 # 0x5800c
vaddss %xmm2, %xmm3, %xmm3
vdivss %xmm3, %xmm2, %xmm2
vmulss %xmm2, %xmm0, %xmm2
vcvtss2sd %xmm2, %xmm2, %xmm2
vmovsd 0x90(%rsp), %xmm3
vmaxsd %xmm3, %xmm2, %xmm3
vmovsd %xmm3, 0x90(%rsp)
incq %rdi
jmp 0x2a2e
movq %r12, %rdi
callq 0x2050
movq %r13, %rdi
callq 0x2050
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x24e7
leaq 0x55612(%rip), %rsi     # 0x580ca
leaq 0x610(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x2190
leaq 0x5560d(%rip), %rsi     # 0x580dc
leaq 0x410(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x2190
leaq 0x55602(%rip), %rsi     # 0x580e8
leaq 0x210(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x2190
andq $0x0, 0x108(%rsp)
andq $0x0, 0x28(%rsp)
leaq 0x210(%rsp), %rdi
leaq 0xf(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x2210
movq %r13, 0x158(%rsp)
movq %r12, 0xe0(%rsp)
leaq 0x210(%rsp), %rdi
callq 0x2130
leaq 0x28(%rsp), %rcx
movq %rax, (%rcx)
vcvttsd2si 0xe8(%rsp), %rax
movl %eax, %eax
movq %rax, 0x150(%rsp)
movq $0x0, 0x80(%rsp)
leaq 0xf0(%rsp), %rbx
pushq $0x8
popq %r13
leaq 0x110(%rsp), %r15
leaq 0x210(%rsp), %r14
movq 0xe0(%rsp), %rdi
callq 0x2270
testl %eax, %eax
jne 0x3168
leaq 0x30(%rsp), %rdi
movq 0xe0(%rsp), %rsi
callq 0x24e7
leaq 0x60(%rsp), %rdi
movq 0x158(%rsp), %rsi
callq 0x24e7
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rdx
movq %rdx, %rax
subq %rcx, %rax
movq 0x68(%rsp), %rsi
subq 0x60(%rsp), %rsi
cmpq %rsi, %rax
jne 0x3255
cmpq %rcx, %rdx
je 0x3168
sarq $0x2, %rax
js 0x2bed
vcvtsi2ss %rax, %xmm2, %xmm0
jmp 0x2c02
movq %rax, %rcx
shrq %rcx
andl $0x1, %eax
orq %rcx, %rax
vcvtsi2ss %rax, %xmm2, %xmm0
vaddss %xmm0, %xmm0, %xmm0
leaq 0x98(%rsp), %rdi
callq 0x3822
vmovss %xmm0, 0x88(%rsp)
movq %rbx, %rdi
movq 0x150(%rsp), %rsi
leaq 0x170(%rsp), %rdx
callq 0x3856
vxorps %xmm0, %xmm0, %xmm0
vmovaps %xmm0, 0xa0(%rsp)
andq $0x0, 0xb0(%rsp)
xorl %ebx, %ebx
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rcx, %rbx
jae 0x2d01
movl (%rax,%rbx,4), %eax
movq 0x60(%rsp), %rcx
movl (%rcx,%rbx,4), %ecx
vcvtsi2ss %rcx, %xmm2, %xmm0
movq 0xc0(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
vcvtsi2ss %rcx, %xmm2, %xmm1
vdivss 0x9c(%rsp), %xmm1, %xmm1
vmulss 0x55371(%rip), %xmm1, %xmm1 # 0x58004
vaddss 0x5536d(%rip), %xmm1, %xmm1 # 0x58008
vmulss 0x55369(%rip), %xmm1, %xmm1 # 0x5800c
vaddss %xmm0, %xmm1, %xmm1
vdivss %xmm1, %xmm0, %xmm0
vmulss 0x88(%rsp), %xmm0, %xmm0
vcvtss2sd %xmm0, %xmm0, %xmm0
vmulsd 0xe8(%rsp), %xmm0, %xmm0
vdivsd 0x90(%rsp), %xmm0, %xmm0
vroundsd $0xa, %xmm0, %xmm0, %xmm0
vcvttsd2si %xmm0, %rcx
decl %ecx
imulq $0x18, %rcx, %rdi
addq 0xf0(%rsp), %rdi
incl %eax
movl %eax, 0x170(%rsp)
leaq 0x170(%rsp), %rsi
callq 0x40f6
incq %rbx
jmp 0x2c48
movl 0x80(%rsp), %esi
shlq $0x5, %rsi
addq 0x130(%rsp), %rsi
leaq 0x170(%rsp), %rdi
callq 0x2220
leaq 0x410(%rsp), %rdi
leaq 0x108(%rsp), %rsi
movq %r13, %rdx
callq 0x2210
leaq 0x410(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movq %r13, %rdx
callq 0x2210
leaq 0x610(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x2150
movq %rax, %rdi
xorl %esi, %esi
callq 0x21a0
leaq 0x610(%rsp), %rdi
callq 0x2130
movq %rax, 0x108(%rsp)
andq $0x0, 0x58(%rsp)
xorl %ebx, %ebx
movq 0xf0(%rsp), %rcx
movq 0xf8(%rsp), %rax
subq %rcx, %rax
cqto
idivq %rbp
cmpq %rax, %rbx
jae 0x2f35
imulq $0x18, %rbx, %r12
movq 0x8(%rcx,%r12), %rsi
subq (%rcx,%r12), %rsi
je 0x2f0a
sarq %rsi
addq $0x400, %rsi            # imm = 0x400
movq %r15, %rdi
leaq 0x10(%rsp), %rdx
callq 0x38aa
movq 0x118(%rsp), %rax
subq 0x110(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xf0(%rsp), %rcx
movq (%rcx,%r12), %rax
movq 0x8(%rcx,%r12), %rdx
movq %rdx, %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq $0x4, %rcx
ja 0x2e2b
cmpq %rax, %rdx
je 0x3210
decq %rcx
movq %rcx, %rdx
subq $0x1, %rdx
jb 0x2e6f
movl (%rax,%rdx,4), %esi
subl %esi, (%rax,%rcx,4)
movq %rdx, %rcx
jmp 0x2e1a
movq %rcx, %rdx
andq $-0x4, %rdx
leaq (%rax,%rdx,4), %rsi
vxorps %xmm0, %xmm0, %xmm0
movq %rax, %rdi
cmpq %rsi, %rdi
jae 0x2e66
vpsrldq $0xc, %xmm0, %xmm0      # xmm0 = xmm0[12,13,14,15],zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero,zero
vmovdqa (%rdi), %xmm1
vpslldq $0x4, %xmm1, %xmm2      # xmm2 = zero,zero,zero,zero,xmm1[0,1,2,3,4,5,6,7,8,9,10,11]
vpaddd %xmm2, %xmm0, %xmm0
vpsubd %xmm0, %xmm1, %xmm0
vmovdqa %xmm0, (%rdi)
addq $0x10, %rdi
vmovdqa %xmm1, %xmm0
jmp 0x2e3d
cmpq %rcx, %rdx
jne 0x2f12
movq 0xf0(%rsp), %rax
movq (%rax,%r12), %rsi
movq 0x8(%rax,%r12), %rdx
subq %rsi, %rdx
sarq $0x2, %rdx
movq 0x110(%rsp), %rcx
movq 0x50(%rsp), %rdi
movq (%rdi), %rax
leaq 0x10(%rsp), %r8
callq *0x10(%rax)
movq 0x10(%rsp), %rsi
addq $0xf, %rsi
andq $-0x10, %rsi
movq %rsi, 0x20(%rsp)
shrq $0x2, %rsi
movq %r15, %rdi
callq 0x3774
leal 0x1(%rbx), %eax
movw %ax, 0xc(%rsp)
movq 0xf0(%rsp), %rax
movq 0x8(%rax,%r12), %rcx
subq (%rax,%r12), %rcx
shrq $0x2, %rcx
movl %ecx, 0x1c(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0xc(%rsp), %rsi
leaq 0x1c(%rsp), %rdx
leaq 0x10(%rsp), %rcx
leaq 0x20(%rsp), %r8
movq %r15, %r9
callq 0x38fe
movq %r15, %rdi
callq 0x3b86
incq %rbx
jmp 0x2d8a
vextractps $0x3, %xmm0, %esi
cmpq %rcx, %rdx
jae 0x2e6f
movl (%rax,%rdx,4), %edi
movl %edi, %r8d
subl %esi, %r8d
movl %r8d, (%rax,%rdx,4)
incq %rdx
movl %edi, %esi
jmp 0x2f18
movq 0xa8(%rsp), %rax
subq 0xa0(%rsp), %rax
cqto
pushq $0x30
popq %rcx
idivq %rcx
movq %rax, 0x58(%rsp)
leaq 0x410(%rsp), %rdi
leaq 0x58(%rsp), %rsi
movq %r13, %rdx
callq 0x2210
movq 0x58(%rsp), %rax
leaq (,%rax,8), %rcx
addq 0x28(%rsp), %rcx
movq %rcx, 0x10(%rsp)
xorl %ebx, %ebx
cmpq %rax, %rbx
jae 0x2fa5
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
movq %r13, %rdx
callq 0x2210
addq $0x16, 0x10(%rsp)
incq %rbx
movq 0x58(%rsp), %rax
jmp 0x2f80
movq 0x28(%rsp), %rcx
imulq $0x1e, %rax, %rax
leaq (%rax,%rcx), %rdx
addq $0x16, %rdx
addq %rax, %rcx
addq $0x25, %rcx
andq $-0x10, %rcx
movq %rcx, %rax
movq %rdx, 0x88(%rsp)
subq %rdx, %rax
movq %rax, 0x160(%rsp)
movq %rcx, 0x20(%rsp)
pushq $0x10
popq %rbx
movq %rcx, 0x168(%rsp)
xorl %r12d, %r12d
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rax
subq %rsi, %rax
cqto
pushq $0x30
popq %rdi
idivq %rdi
cmpq %rax, %r12
jae 0x3084
movzwl -0x10(%rsi,%rbx), %eax
movw %ax, 0xc(%rsp)
movl -0xc(%rsi,%rbx), %eax
movl %eax, 0x1c(%rsp)
movq (%rsi,%rbx), %rbp
addq -0x8(%rsi,%rbx), %rcx
movq %rcx, 0x110(%rsp)
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
pushq $0x2
popq %rdx
callq 0x2210
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
movq %r13, %rdx
callq 0x2210
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2210
movq %r14, %rdi
leaq 0x1c(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x2210
addq 0x20(%rsp), %rbp
movq %rbp, 0x20(%rsp)
incq %r12
addq $0x30, %rbx
movq %rbp, %rcx
jmp 0x2fea
vxorps %xmm0, %xmm0, %xmm0
vmovaps %xmm0, 0x110(%rsp)
andq $0x0, 0x11e(%rsp)
movq %r14, %rdi
movq %r15, %rsi
pushq $0x16
popq %rdx
callq 0x2210
pushq $0x18
popq %rbp
movq 0x168(%rsp), %rax
cmpq 0x88(%rsp), %rax
je 0x30da
movq 0x160(%rsp), %rdx
cmpq $0x17, %rdx
jae 0x3270
movq %r14, %rdi
movq %r15, %rsi
callq 0x2210
movq %rbp, %rbx
xorl %r12d, %r12d
movq 0xa0(%rsp), %rcx
movq 0xa8(%rsp), %rax
subq %rcx, %rax
cqto
pushq $0x30
popq %rsi
idivq %rsi
cmpq %rax, %r12
jae 0x311a
movq -0x8(%rcx,%rbx), %rdx
movq (%rcx,%rbx), %rsi
movq %r14, %rdi
callq 0x2210
incq %r12
addq $0x30, %rbx
jmp 0x30e0
movq %r14, %rdi
callq 0x2130
movq %rax, 0x28(%rsp)
movq 0x80(%rsp), %rax
incl %eax
movq %rax, 0x80(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x20c0
leaq 0xa0(%rsp), %rdi
callq 0x3948
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
callq 0x396a
jmp 0x2b7b
leaq 0x210(%rsp), %rdi
callq 0x2240
leaq 0x410(%rsp), %rdi
callq 0x2240
leaq 0x610(%rsp), %rdi
callq 0x2240
leaq 0xc0(%rsp), %rdi
callq 0x3b86
leaq 0x60(%rsp), %rdi
callq 0x3b86
leaq 0x30(%rsp), %rdi
callq 0x3b86
leaq 0x190(%rsp), %rdi
callq 0x20c0
leaq 0x1b0(%rsp), %rdi
callq 0x20c0
leaq 0x1d0(%rsp), %rdi
callq 0x20c0
leaq 0x1f0(%rsp), %rdi
callq 0x20c0
leaq 0x810(%rsp), %rdi
callq 0x2060
leaq 0x130(%rsp), %rdi
callq 0x398c
addq $0xa18, %rsp            # imm = 0xA18
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0x55022(%rip), %rsi     # 0x58244
movq %rax, %rdi
callq 0x2090
movq 0x59dbf(%rip), %rsi     # 0x5cff0
movq 0x59d90(%rip), %rdx     # 0x5cfc8
movq %r14, %rdi
callq 0x22b0
movq 0x59da1(%rip), %rdi     # 0x5cfe8
leaq 0x54e64(%rip), %rsi     # 0x580b2
callq 0x2160
jmp 0x3268
movq 0x59d8c(%rip), %rdi     # 0x5cfe8
leaq 0x54e4f(%rip), %rsi     # 0x580b2
callq 0x2160
pushq $0x1
popq %rdi
callq 0x21c0
movq 0x59d71(%rip), %rdi     # 0x5cfe8
leaq 0x54e79(%rip), %rsi     # 0x580f7
callq 0x2160
movq %rax, %rdi
callq 0x20d0
jmp 0x3268
movq 0x59d54(%rip), %rdi     # 0x5cfe8
leaq 0x54dc8(%rip), %rsi     # 0x58063
callq 0x2160
movq %rax, %rdi
callq 0x20d0
jmp 0x3268
movq %rax, %rbx
pushq $0x18
popq %rsi
movq 0x50(%rsp), %rdi
callq 0x2180
jmp 0x3414
jmp 0x330d
jmp 0x330d
movq %rax, %rbx
jmp 0x338b
movq %rax, %rbx
jmp 0x3398
jmp 0x3312
jmp 0x3312
jmp 0x3312
movq %rax, %rbx
jmp 0x33d3
movq %rax, %rbx
jmp 0x33e0
jmp 0x331c
movq %rax, %rbx
jmp 0x3407
jmp 0x331c
jmp 0x3354
jmp 0x3312
jmp 0x330d
jmp 0x3312
jmp 0x3354
jmp 0x3354
jmp 0x3354
jmp 0x334f
jmp 0x330d
jmp 0x330d
jmp 0x3312
jmp 0x3354
movq %rax, %rbx
jmp 0x337e
movq %rax, %rbx
jmp 0x33a5
jmp 0x3354
movq %rax, %rbx
jmp 0x33ed
jmp 0x3339
movq %rax, %rbx
movq %r14, %rdi
callq 0x2110
jmp 0x333c
jmp 0x3354
jmp 0x3339
jmp 0x3339
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x3b86
jmp 0x3357
jmp 0x3354
jmp 0x3354
movq %rax, %rbx
jmp 0x3364
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
callq 0x20c0
leaq 0xa0(%rsp), %rdi
callq 0x3948
leaq 0xf0(%rsp), %rdi
callq 0x396a
leaq 0x210(%rsp), %rdi
callq 0x2240
leaq 0x410(%rsp), %rdi
callq 0x2240
leaq 0x610(%rsp), %rdi
callq 0x2240
leaq 0xc0(%rsp), %rdi
callq 0x3b86
leaq 0x60(%rsp), %rdi
callq 0x3b86
leaq 0x30(%rsp), %rdi
callq 0x3b86
leaq 0x190(%rsp), %rdi
callq 0x20c0
leaq 0x1b0(%rsp), %rdi
callq 0x20c0
leaq 0x1d0(%rsp), %rdi
callq 0x20c0
leaq 0x1f0(%rsp), %rdi
callq 0x20c0
leaq 0x810(%rsp), %rdi
callq 0x2060
leaq 0x130(%rsp), %rdi
callq 0x398c
movq %rbx, %rdi
callq 0x22c0