// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/jfbuild/src/rg_etc1.cpp
// Function: rg_etc1::pack_etc1_block(void*, unsigned int const*, rg_etc1::etc1_pack_params&)
unsigned int pack_etc1_block(void* pETC1_block, const unsigned int* pSrc_pixels_rgba, etc1_pack_params& pack_params)
   {
      const color_quad_u8* pSrc_pixels = reinterpret_cast<const color_quad_u8*>(pSrc_pixels_rgba);
      etc1_block& dst_block = *static_cast<etc1_block*>(pETC1_block);

#ifdef RG_ETC1_BUILD_DEBUG
      // Ensure all alpha values are 0xFF.
      for (uint i = 0; i < 16; i++)
      {
         RG_ETC1_ASSERT(pSrc_pixels[i].a == 255);
      }
#endif

      color_quad_u8 src_pixel0(pSrc_pixels[0]);

      // Check for solid block.
      const uint32 first_pixel_u32 = pSrc_pixels->m_u32;
      int r;
      for (r = 15; r >= 1; --r)
         if (pSrc_pixels[r].m_u32 != first_pixel_u32)
            break;
      if (!r)
         return static_cast<unsigned int>(16 * pack_etc1_block_solid_color(dst_block, &pSrc_pixels[0].r, pack_params));
      
      color_quad_u8 dithered_pixels[16];
      if (pack_params.m_dithering)
      {
         dither_block_555(dithered_pixels, pSrc_pixels);
         pSrc_pixels = dithered_pixels;
      }

      etc1_optimizer optimizer;

      uint64 best_error = cUINT64_MAX;
      uint best_flip = false, best_use_color4 = false;
      
      uint8 best_selectors[2][8];
      etc1_optimizer::results best_results[2];
      for (uint i = 0; i < 2; i++)
      {
         best_results[i].m_n = 8;
         best_results[i].m_pSelectors = best_selectors[i];
      }
      
      uint8 selectors[3][8];
      etc1_optimizer::results results[3];
      
      for (uint i = 0; i < 3; i++)
      {
         results[i].m_n = 8;
         results[i].m_pSelectors = selectors[i];
      }
            
      color_quad_u8 subblock_pixels[8];

      etc1_optimizer::params params(pack_params);
      params.m_num_src_pixels = 8;
      params.m_pSrc_pixels = subblock_pixels;

      for (uint flip = 0; flip < 2; flip++)
      {
         for (uint use_color4 = 0; use_color4 < 2; use_color4++)
         {
            uint64 trial_error = 0;

            uint subblock;
            for (subblock = 0; subblock < 2; subblock++)
            {
               if (flip)
                  memcpy(subblock_pixels, pSrc_pixels + subblock * 8, sizeof(color_quad_u8) * 8);
               else
               {
                  const color_quad_u8* pSrc_col = pSrc_pixels + subblock * 2;
                  subblock_pixels[0] = pSrc_col[0]; subblock_pixels[1] = pSrc_col[4]; subblock_pixels[2] = pSrc_col[8]; subblock_pixels[3] = pSrc_col[12];
                  subblock_pixels[4] = pSrc_col[1]; subblock_pixels[5] = pSrc_col[5]; subblock_pixels[6] = pSrc_col[9]; subblock_pixels[7] = pSrc_col[13];
               }

               results[2].m_error = cUINT64_MAX;
               if ((params.m_quality >= cMediumQuality) && ((subblock) || (use_color4)))
               {
                  const uint32 subblock_pixel0_u32 = subblock_pixels[0].m_u32;
                  for (r = 7; r >= 1; --r)
                     if (subblock_pixels[r].m_u32 != subblock_pixel0_u32)
                        break;
                  if (!r)
                  {
                     pack_etc1_block_solid_color_constrained(results[2], 8, &subblock_pixels[0].r, pack_params, !use_color4, (subblock && !use_color4) ? &results[0].m_block_color_unscaled : NULL);
                  }
               }

               params.m_use_color4 = (use_color4 != 0);
               params.m_constrain_against_base_color5 = false;

               if ((!use_color4) && (subblock))
               {
                  params.m_constrain_against_base_color5 = true;
                  params.m_base_color5 = results[0].m_block_color_unscaled;
               }
                              
               if (params.m_quality == cHighQuality)
               {
                  static const int s_scan_delta_0_to_4[] = { -4, -3, -2, -1, 0, 1, 2, 3, 4 };
                  params.m_scan_delta_size = RG_ETC1_ARRAY_SIZE(s_scan_delta_0_to_4);
                  params.m_pScan_deltas = s_scan_delta_0_to_4;
               }
               else if (params.m_quality == cMediumQuality)
               {
                  static const int s_scan_delta_0_to_1[] = { -1, 0, 1 };
                  params.m_scan_delta_size = RG_ETC1_ARRAY_SIZE(s_scan_delta_0_to_1);
                  params.m_pScan_deltas = s_scan_delta_0_to_1;
               }
               else
               {
                  static const int s_scan_delta_0[] = { 0 };
                  params.m_scan_delta_size = RG_ETC1_ARRAY_SIZE(s_scan_delta_0);
                  params.m_pScan_deltas = s_scan_delta_0;
               }
               
               optimizer.init(params, results[subblock]);
               if (!optimizer.compute())
                  break;
                              
               if (params.m_quality >= cMediumQuality)
               {
                  // TODO: Fix fairly arbitrary/unrefined thresholds that control how far away to scan for potentially better solutions.
                  const uint refinement_error_thresh0 = 3000;
                  const uint refinement_error_thresh1 = 6000;
                  if (results[subblock].m_error > refinement_error_thresh0)
                  {
                     if (params.m_quality == cMediumQuality)
                     {
                        static const int s_scan_delta_2_to_3[] = { -3, -2, 2, 3 };
                        params.m_scan_delta_size = RG_ETC1_ARRAY_SIZE(s_scan_delta_2_to_3);
                        params.m_pScan_deltas = s_scan_delta_2_to_3;
                     }
                     else
                     {
                        static const int s_scan_delta_5_to_5[] = { -5, 5 };
                        static const int s_scan_delta_5_to_8[] = { -8, -7, -6, -5, 5, 6, 7, 8 };
                        if (results[subblock].m_error > refinement_error_thresh1)
                        {
                           params.m_scan_delta_size = RG_ETC1_ARRAY_SIZE(s_scan_delta_5_to_8);
                           params.m_pScan_deltas = s_scan_delta_5_to_8;
                        }
                        else
                        {
                           params.m_scan_delta_size = RG_ETC1_ARRAY_SIZE(s_scan_delta_5_to_5);
                           params.m_pScan_deltas = s_scan_delta_5_to_5;
                        }
                     }

                     if (!optimizer.compute())
                        break;
                  }

                  if (results[2].m_error < results[subblock].m_error)
                     results[subblock] = results[2];
               }
                            
               trial_error += results[subblock].m_error;
               if (trial_error >= best_error)
                  break;
            }

            if (subblock < 2)
               continue;

            best_error = trial_error;
            best_results[0] = results[0];
            best_results[1] = results[1];
            best_flip = flip;
            best_use_color4 = use_color4;
            
         } // use_color4

      } // flip

      int dr = best_results[1].m_block_color_unscaled.r - best_results[0].m_block_color_unscaled.r;
      int dg = best_results[1].m_block_color_unscaled.g - best_results[0].m_block_color_unscaled.g;
      int db = best_results[1].m_block_color_unscaled.b - best_results[0].m_block_color_unscaled.b;
      RG_ETC1_ASSERT(best_use_color4 || (rg_etc1::minimum(dr, dg, db) >= cETC1ColorDeltaMin) && (rg_etc1::maximum(dr, dg, db) <= cETC1ColorDeltaMax));
           
      if (best_use_color4)
      {
         dst_block.m_bytes[0] = static_cast<uint8>(best_results[1].m_block_color_unscaled.r | (best_results[0].m_block_color_unscaled.r << 4));
         dst_block.m_bytes[1] = static_cast<uint8>(best_results[1].m_block_color_unscaled.g | (best_results[0].m_block_color_unscaled.g << 4));
         dst_block.m_bytes[2] = static_cast<uint8>(best_results[1].m_block_color_unscaled.b | (best_results[0].m_block_color_unscaled.b << 4));
      }
      else
      {
         if (dr < 0) dr += 8; dst_block.m_bytes[0] = static_cast<uint8>((best_results[0].m_block_color_unscaled.r << 3) | dr);
         if (dg < 0) dg += 8; dst_block.m_bytes[1] = static_cast<uint8>((best_results[0].m_block_color_unscaled.g << 3) | dg);
         if (db < 0) db += 8; dst_block.m_bytes[2] = static_cast<uint8>((best_results[0].m_block_color_unscaled.b << 3) | db);
      }
      
      dst_block.m_bytes[3] = static_cast<uint8>( (best_results[1].m_block_inten_table << 2) | (best_results[0].m_block_inten_table << 5) | ((~best_use_color4 & 1) << 1) | best_flip );
      
      uint selector0 = 0, selector1 = 0;
      if (best_flip)
      {
         // flipped:
         // { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 },               
         // { 0, 1 }, { 1, 1 }, { 2, 1 }, { 3, 1 } 
         //
         // { 0, 2 }, { 1, 2 }, { 2, 2 }, { 3, 2 },
         // { 0, 3 }, { 1, 3 }, { 2, 3 }, { 3, 3 }
         const uint8* pSelectors0 = best_results[0].m_pSelectors;
         const uint8* pSelectors1 = best_results[1].m_pSelectors;
         for (int x = 3; x >= 0; --x)
         {
            uint b;
            b = g_selector_index_to_etc1[pSelectors1[4 + x]];
            selector0 = (selector0 << 1) | (b & 1); selector1 = (selector1 << 1) | (b >> 1);

            b = g_selector_index_to_etc1[pSelectors1[x]];
            selector0 = (selector0 << 1) | (b & 1); selector1 = (selector1 << 1) | (b >> 1);

            b = g_selector_index_to_etc1[pSelectors0[4 + x]];
            selector0 = (selector0 << 1) | (b & 1); selector1 = (selector1 << 1) | (b >> 1);

            b = g_selector_index_to_etc1[pSelectors0[x]];
            selector0 = (selector0 << 1) | (b & 1); selector1 = (selector1 << 1) | (b >> 1);
         }
      }
      else
      {
         // non-flipped:
         // { 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 },
         // { 1, 0 }, { 1, 1 }, { 1, 2 }, { 1, 3 }
         //
         // { 2, 0 }, { 2, 1 }, { 2, 2 }, { 2, 3 },
         // { 3, 0 }, { 3, 1 }, { 3, 2 }, { 3, 3 }
         for (int subblock = 1; subblock >= 0; --subblock)
         {
            const uint8* pSelectors = best_results[subblock].m_pSelectors + 4;
            for (uint i = 0; i < 2; i++)
            {
               uint b;
               b = g_selector_index_to_etc1[pSelectors[3]];
               selector0 = (selector0 << 1) | (b & 1); selector1 = (selector1 << 1) | (b >> 1);

               b = g_selector_index_to_etc1[pSelectors[2]];
               selector0 = (selector0 << 1) | (b & 1); selector1 = (selector1 << 1) | (b >> 1);

               b = g_selector_index_to_etc1[pSelectors[1]];
               selector0 = (selector0 << 1) | (b & 1); selector1 = (selector1 << 1) | (b >> 1);

               b = g_selector_index_to_etc1[pSelectors[0]];
               selector0 = (selector0 << 1) | (b & 1);selector1 = (selector1 << 1) | (b >> 1);

               pSelectors -= 4;
            }
         }
      }
                  
      dst_block.m_bytes[4] = static_cast<uint8>(selector1 >> 8); dst_block.m_bytes[5] = static_cast<uint8>(selector1 & 0xFF);
      dst_block.m_bytes[6] = static_cast<uint8>(selector0 >> 8); dst_block.m_bytes[7] = static_cast<uint8>(selector0 & 0xFF);

      return static_cast<unsigned int>(best_error);
   }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
movq %rsi, %r12
movq %rdi, 0x20(%rsp)
movl (%rsi), %eax
movl %eax, %esi
shrl $0x8, %esi
movl $0x10, %ecx
leaq 0x168(%rsp), %rbx
decl %ecx
cmpl %eax, (%r12,%rcx,4)
jne 0x6b786
cmpl $0x1, %ecx
ja 0x6b5e4
movq %r12, 0xd0(%rsp)
cmpw $0x0, 0x659da9(%rip)    # 0x6c53ae
je 0x6c6ff
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
leaq 0x11078(%rip), %r10     # 0x7c690
movl $0xff, %edi
xorl %r8d, %r8d
movl $0x0, 0x60(%rsp)
xorl %r14d, %r14d
xorl %ecx, %ecx
xorl %eax, %eax
movl %esi, %edx
leaq 0x1(%r8), %rsi
movq %rsi, 0xd8(%rsp)
movl 0x4(%r10,%r8,4), %esi
movzbl %dl, %r13d
movq 0xd0(%rsp), %rdx
movb (%rdx,%rsi), %sil
movq %r8, %rbp
movzbl (%rdx,%r8), %ebx
movl %esi, 0xf0(%rsp)
movzbl %sil, %r10d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, 0x28(%rsp)
movq %rdx, 0x58(%rsp)
leal (%rdx,%rbx), %r8d
cmpl %edi, %r8d
cmovgel %edi, %r8d
testl %r8d, %r8d
movl $0x0, %edx
cmovlel %edx, %r8d
leaq 0x117ce(%rip), %r11     # 0x7ce60
testl %r8d, %r8d
je 0x6b6bf
cmpl $0xff, %r8d
jne 0x6b6a9
leaq 0x117fb(%rip), %r11     # 0x7cea2
jmp 0x6b6bf
leal -0x1(%r8), %edx
movslq %edx, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq 0x11835(%rip), %rsi     # 0x7cef0
leaq (%rsi,%rdx,8), %r11
subl %ebx, %r8d
imull %r8d, %r8d
movzwl (%r11), %esi
addq $0x2, %r11
movzwl %si, %esi
movzbl %sil, %edx
shll $0x9, %edx
leaq 0x659ad1(%rip), %rbx    # 0x6c51b0
addq %rbx, %rdx
movzwl (%rdx,%r13,2), %ebx
movzwl (%rdx,%r10,2), %edx
movl %ebx, %r15d
shrl $0x8, %r15d
imull %r15d, %r15d
addl %r8d, %r15d
movl %edx, %r12d
shrl $0x8, %r12d
imull %r12d, %r12d
addl %r15d, %r12d
cmpl %r9d, %r12d
jae 0x6b728
andl %edi, %ebx
andl %edi, %edx
testl %r12d, %r12d
je 0x6b92e
movl %edx, %eax
movl %ebx, %ecx
movl %esi, %r14d
movl %ebp, 0x60(%rsp)
movl %r12d, %r9d
movzwl (%r11), %esi
addq $0x2, %r11
cmpw $-0x1, %si
jne 0x6b6ce
movq 0x58(%rsp), %rdx
incl %edx
cmpl $0x2, %edx
movq 0x28(%rsp), %rbx
jne 0x6b66f
movq 0xd8(%rsp), %r8
cmpq $0x3, %r8
leaq 0x10f32(%rip), %r10     # 0x7c690
movl 0xf0(%rsp), %esi
jne 0x6b62f
shll $0x4, %r9d
movq %r9, 0x50(%rsp)
movl %eax, %edx
movl %ecx, %ebx
movl %r14d, %esi
movl 0x60(%rsp), %eax
movl %eax, %ebp
jmp 0x6b93e
cmpb $0x1, 0x4(%rdx)
jne 0x6b9c4
leaq 0x270(%rsp), %rax
pcmpeqd %xmm0, %xmm0
leaq 0x220(%rsp), %rcx
movdqa %xmm0, (%rcx)
movdqa %xmm0, 0x10(%rcx)
movdqa %xmm0, 0x20(%rcx)
movdqa %xmm0, 0x30(%rcx)
leaq 0x260(%rsp), %r8
xorl %esi, %esi
pxor %xmm0, %xmm0
leaq 0x6619ec(%rip), %rdi    # 0x6cd1b8
movdqa %xmm0, 0x270(%rsp)
movdqa %xmm0, 0x260(%rsp)
xorl %r9d, %r9d
movq %r8, %r10
movq %rax, %r8
movq %r10, %rax
movzbl (%r12,%r9), %r10d
movl (%r8), %r11d
movl 0x4(%r8), %ebx
leal (%rbx,%rbx,2), %ebx
leal (%r11,%r11,4), %r11d
addl %ebx, %r11d
sarl $0x4, %r11d
movslq %r11d, %r11
addq %r10, %r11
movzbl (%rdi,%r11), %r11d
movb %r11b, (%rcx,%r9)
subl %r11d, %r10d
movl %r10d, (%rax)
leal (,%r10,8), %r11d
subl %r10d, %r11d
movl 0x4(%r8), %r10d
movl 0x8(%r8), %ebx
leal (%rbx,%rbx,2), %ebx
leal (%r10,%r10,4), %r10d
addl %ebx, %r10d
addl %r11d, %r10d
addl (%r8), %r10d
movzbl 0x4(%r12,%r9), %r11d
sarl $0x4, %r10d
movslq %r10d, %r10
addq %r11, %r10
movzbl (%rdi,%r10), %r10d
movb %r10b, 0x4(%rcx,%r9)
subl %r10d, %r11d
movl %r11d, 0x4(%rax)
movzbl 0x8(%r12,%r9), %r10d
leal (,%r11,8), %ebx
subl %r11d, %ebx
movl 0x8(%r8), %r11d
movl 0xc(%r8), %r14d
leal (%r14,%r14,2), %ebp
leal (%r11,%r11,4), %r11d
addl %ebp, %r11d
addl %ebx, %r11d
addl 0x4(%r8), %r11d
sarl $0x4, %r11d
movslq %r11d, %r11
addq %r10, %r11
movzbl (%rdi,%r11), %r11d
movb %r11b, 0x8(%rcx,%r9)
subl %r11d, %r10d
movl %r10d, 0x8(%rax)
movzbl 0xc(%r12,%r9), %r11d
leal (,%r10,8), %ebx
subl %r10d, %ebx
movl 0xc(%r8), %r10d
leal (%r10,%r10,4), %r10d
addl %ebx, %r10d
addl 0x8(%r8), %r10d
sarl $0x4, %r10d
movslq %r10d, %r10
addq %r11, %r10
movzbl (%rdi,%r10), %r10d
movb %r10b, 0xc(%rcx,%r9)
subl %r10d, %r11d
movl %r11d, 0xc(%rax)
addq $0x10, %r9
movq %r8, %r10
cmpl $0x40, %r9d
jne 0x6b7e4
incq %rsi
incq %rcx
incq %r12
cmpq $0x3, %rsi
jne 0x6b7cc
movl 0x8c(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0xb4(%rsp), %eax
movq %rax, 0x48(%rsp)
leaq 0x220(%rsp), %r12
leaq 0x168(%rsp), %rbx
jmp 0x6b9c9
movq $0x0, 0x50(%rsp)
leaq 0x10d52(%rip), %r10     # 0x7c690
movl %esi, %eax
andl $0x1, %eax
leal (%rsi,%rsi), %ecx
andl $0x1c, %ecx
leal (%rcx,%rcx,8), %ecx
leal (%rcx,%rax,2), %ecx
movq 0x20(%rsp), %r8
movb %cl, 0x3(%r8)
movl %esi, %ecx
shrl $0x4, %ecx
andl $0x3, %ecx
leaq 0x10d3d(%rip), %rdi     # 0x7c6a4
movzbl (%rcx,%rdi), %ecx
movl %ecx, %edi
shll $0x1e, %edi
sarl $0x1f, %edi
movw %di, 0x4(%r8)
andl $0x1, %ecx
negl %ecx
movw %cx, 0x6(%r8)
shrl $0x8, %esi
testl %eax, %eax
jne 0x6c34d
movl %esi, %eax
shll $0x4, %eax
orl %esi, %eax
movl %ebp, %ecx
movq 0x20(%rsp), %rsi
movb %al, (%rsi,%rcx)
movl %ebx, %eax
shll $0x4, %eax
orl %ebx, %eax
movl (%r10,%rcx,4), %ecx
movq 0x20(%rsp), %rsi
movb %al, (%rsi,%rcx)
movq 0x20(%rsp), %rcx
movl %edx, %eax
shll $0x4, %eax
orl %edx, %eax
movl %eax, %edx
jmp 0x6c367
movq %rax, 0x48(%rsp)
xorl %ecx, %ecx
leaq 0x260(%rsp), %r13
movb %cl, 0xa8(%r13)
movq %rcx, 0xa0(%r13)
movq $-0x1, %rax
movq %rax, 0xb8(%r13)
movb %cl, 0xc0(%r13)
movq %rcx, 0xc8(%r13)
movb %cl, 0xd0(%r13)
movq $-0x1, 0x50(%rsp)
movq %rax, 0xe0(%r13)
movb %cl, 0xe8(%r13)
pxor %xmm0, %xmm0
movdqa %xmm0, (%r13)
movdqa %xmm0, 0x80(%r13)
movl $0x8, %esi
movl %esi, 0x90(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x98(%rsp)
movl %esi, 0xb8(%rsp)
leaq 0xe8(%rsp), %rax
movq %rax, 0xc0(%rsp)
leaq 0x148(%rsp), %rdi
movl %esi, 0x8(%rdi)
leaq 0x200(%rsp), %rax
movq %rax, 0x10(%rdi)
movl %esi, 0x30(%rdi)
leaq 0x208(%rsp), %rax
movq %rax, 0x38(%rdi)
movl %esi, 0x58(%rdi)
leaq 0x210(%rsp), %rax
movq %rax, 0x60(%rdi)
movq (%rdx), %rax
leaq 0x1c8(%rsp), %rbp
movq %rax, (%rbp)
movb %cl, 0x18(%rbp)
leaq 0x12c11(%rip), %rax     # 0x7e6c0
movq %rax, 0x20(%rbp)
movq $0x1, 0x28(%rbp)
movb %cl, 0x30(%rbp)
movl %esi, 0x8(%rbp)
leaq 0x100(%rsp), %rax
movq %rax, 0x10(%rbp)
movq 0xa8(%rsp), %rax
movq %rax, 0x38(%rsp)
movb 0xa0(%rsp), %dil
movl 0x8c(%rsp), %esi
movb 0xc8(%rsp), %dl
movl 0xb4(%rsp), %eax
movb $0x1, %cl
movl %ecx, 0x34(%rsp)
movq 0x80(%rsp), %rcx
movl $0x0, 0x68(%rsp)
movq $0x0, 0x120(%rsp)
movl $0x0, 0x6c(%rsp)
movq %r12, 0xd0(%rsp)
movb %dil, 0xc(%rsp)
movl %esi, 0x10(%rsp)
movb %dl, 0xd(%rsp)
movl %eax, 0x14(%rsp)
movq %rcx, 0x40(%rsp)
movb $0x1, %r15b
movl $0x0, 0x1c(%rsp)
movb $0x1, %al
movl %eax, 0x70(%rsp)
xorl %esi, %esi
leaq 0x140(%rsp), %r8
xorl %eax, %eax
xorl %ecx, %ecx
movq %rcx, 0x1c0(%rsp)
testb $0x1, 0x34(%rsp)
je 0x6bbce
movl (%r12,%rax,8), %ecx
movl %ecx, 0x100(%rsp)
movl 0x10(%r12,%rax,8), %ecx
movl %ecx, 0x104(%rsp)
movl 0x20(%r12,%rax,8), %ecx
movl %ecx, 0x108(%rsp)
movl 0x30(%r12,%rax,8), %ecx
movl %ecx, 0x10c(%rsp)
movl 0x4(%r12,%rax,8), %ecx
movl %ecx, 0x110(%rsp)
movl 0x14(%r12,%rax,8), %ecx
movl %ecx, 0x114(%rsp)
movl 0x24(%r12,%rax,8), %ecx
movl %ecx, 0x118(%rsp)
movl 0x34(%r12,%rax,8), %ecx
movl %ecx, 0x11c(%rsp)
jmp 0x6bbf2
movq %rax, %rcx
shlq $0x5, %rcx
movdqu (%r12,%rcx), %xmm0
movups 0x10(%r12,%rcx), %xmm1
movaps %xmm1, 0x110(%rsp)
movdqa %xmm0, 0x100(%rsp)
movq $-0x1, 0x190(%rsp)
cmpl $0x0, 0x1c8(%rsp)
setle %cl
orl 0x1c(%rsp), %eax
sete %al
orb %cl, %al
jne 0x6bff5
movl 0x100(%rsp), %eax
movl %eax, %edx
shrl $0x8, %edx
movl $0x8, %ecx
decl %ecx
cmpl %eax, 0x100(%rsp,%rcx,4)
jne 0x6bff5
cmpl $0x1, %ecx
ja 0x6bc29
movl %r15d, %r9d
andb %sil, %r9b
testb $0x1, %r9b
movl $0x0, %r10d
leaq 0x148(%rsp), %rax
cmovneq %rax, %r10
cmpw $0x0, 0x65974d(%rip)    # 0x6c53ae
je 0x6c5ef
movq %rsi, 0x130(%rsp)
movq %r8, 0x138(%rsp)
xorl %r8d, %r8d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x28(%rsp)
movl $0x1, %eax
movq %rax, 0x58(%rsp)
movl $0x0, 0x74(%rsp)
movl $0x0, 0x78(%rsp)
movl $0x0, 0x7c(%rsp)
movl $0x0, 0xd8(%rsp)
movl $0xff, %r14d
movl 0x58(%rsp), %ebp
leaq 0x1(%r8), %rcx
movq %rcx, 0x1b8(%rsp)
leaq 0x109c2(%rip), %rcx     # 0x7c690
movl 0x4(%rcx,%r8,4), %ecx
movzbl %dl, %eax
movq %rcx, 0x58(%rsp)
movb 0x100(%rsp,%rcx), %cl
movzbl 0x100(%rsp,%r8), %r11d
movl %ecx, 0xfc(%rsp)
movzbl %cl, %ecx
movq %rcx, 0x60(%rsp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %r11, 0xf0(%rsp)
leal (%rsi,%r11), %edi
cmpl %r14d, %edi
cmovgel %r14d, %edi
testl %edi, %edi
movl $0x0, %ecx
cmovlel %ecx, %edi
leaq 0x1113d(%rip), %rbx     # 0x7ce60
testl %edi, %edi
je 0x6bd4d
cmpl $0xff, %edi
jne 0x6bd38
leaq 0x1116c(%rip), %rbx     # 0x7cea2
jmp 0x6bd4d
leal -0x1(%rdi), %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq 0x111a7(%rip), %rdx     # 0x7cef0
leaq (%rdx,%rcx,8), %rbx
subl %r11d, %edi
imull %edi, %edi
movzwl (%rbx), %ecx
addq $0x2, %rbx
movl %ecx, %r11d
andb $0x1, %r11b
movl %r15d, %r12d
andb $0x1, %r12b
cmpb %r11b, %r12b
jne 0x6be99
movzwl %cx, %ecx
testb $0x1, %cl
sete %r11b
movl %r9d, %r12d
notb %r12b
orb %r11b, %r12b
testb $0x1, %r12b
jne 0x6be20
movl %ecx, %r11d
shrl $0x8, %r11d
movzbl (%r10,%r8), %r12d
subl %r12d, %r11d
addl $0x4, %r11d
cmpl $0x8, %r11d
jae 0x6be99
movl %ecx, %r11d
andl %r14d, %r11d
shll $0x9, %r11d
leaq 0x6593f4(%rip), %rdx    # 0x6c51b0
addq %rdx, %r11
movzwl (%r11,%rax,2), %r12d
movl %r12d, %r13d
andl %r14d, %r13d
movl $0xff, %edx
movzbl (%r10,%rbp), %r14d
subl %r14d, %r13d
addl $0x4, %r13d
cmpl $0x7, %r13d
ja 0x6be08
movq 0x60(%rsp), %r14
movzwl (%r11,%r14,2), %r13d
movl %r13d, %r11d
andl %edx, %r11d
movq 0x58(%rsp), %rdx
movzbl (%r10,%rdx), %r14d
subl %r14d, %r11d
addl $0x4, %r11d
cmpl $0x8, %r11d
jb 0x6be41
movzwl (%rbx), %ecx
cmpw $-0x1, %cx
movl $0xff, %r14d
jne 0x6bd56
jmp 0x6bea6
movzbl %cl, %r11d
shll $0x9, %r11d
leaq 0x659381(%rip), %rdx    # 0x6c51b0
addq %rdx, %r11
movzwl (%r11,%rax,2), %r12d
movq 0x60(%rsp), %rdx
movzwl (%r11,%rdx,2), %r13d
movzwl %r12w, %r12d
movl %r12d, %r14d
shrl $0x8, %r14d
imull %r14d, %r14d
movzwl %r13w, %r11d
movl %r11d, %r13d
shrl $0x8, %r13d
imull %r13d, %r13d
addl %edi, %r13d
addl %r14d, %r13d
cmpl 0x28(%rsp), %r13d
movl $0xff, %r14d
jae 0x6be99
testl %r13d, %r13d
je 0x6bf24
movl %r11d, 0xd8(%rsp)
movl %r12d, 0x7c(%rsp)
movl %ecx, 0x78(%rsp)
movl %r8d, 0x74(%rsp)
movl %r13d, %ecx
movq %rcx, 0x28(%rsp)
movzwl (%rbx), %ecx
cmpw $-0x1, %cx
jne 0x6bd56
incl %esi
cmpl $0x2, %esi
movq 0xf0(%rsp), %r11
jne 0x6bd07
movq 0x1b8(%rsp), %r8
cmpq $0x3, %r8
movl 0xfc(%rsp), %edx
jne 0x6bcb7
cmpl $-0x1, 0x28(%rsp)
movq 0xd0(%rsp), %r12
leaq 0x168(%rsp), %rbx
leaq 0x260(%rsp), %r13
leaq 0x1c8(%rsp), %rbp
movq 0x138(%rsp), %r8
movq 0x130(%rsp), %rsi
movl 0xd8(%rsp), %r11d
movl 0x7c(%rsp), %r9d
movl 0x78(%rsp), %ecx
movl 0x74(%rsp), %r14d
jne 0x6bf63
jmp 0x6bff5
movq $0x0, 0x28(%rsp)
movl %r8d, %r14d
movl %r12d, %r9d
movq 0xd0(%rsp), %r12
leaq 0x168(%rsp), %rbx
leaq 0x260(%rsp), %r13
leaq 0x1c8(%rsp), %rbp
movq 0x138(%rsp), %r8
movq 0x130(%rsp), %rsi
movq %rbx, %r10
movl $0x8, 0x1a0(%rsp)
movl %ecx, %eax
notb %al
andb $0x1, %al
movb %al, 0x1b0(%rsp)
movl %ecx, %eax
shrl %eax
andl $0x7, %eax
movl %eax, 0x19c(%rsp)
movq 0x1a8(%rsp), %rax
movl %ecx, %ebx
shrb $0x4, %cl
andb $0x3, %cl
movzbl %cl, %ecx
movabsq $0x101010101010101, %rdx # imm = 0x101010101010101
imulq %rdx, %rcx
movq %rcx, (%rax)
cmpl $0x4, %r14d
jae 0x6c654
movq 0x28(%rsp), %rdi
shll $0x3, %edi
movl %r14d, %eax
movb %bh, 0x198(%rsp,%rax)
leaq 0x106bd(%rip), %rdx     # 0x7c690
movl (%rdx,%rax,4), %ecx
movl 0x4(%rdx,%rax,4), %eax
movb %r9b, 0x198(%rsp,%rcx)
movb %r11b, 0x198(%rsp,%rax)
movq %rdi, 0x190(%rsp)
movq %r10, %rbx
movl 0x1c(%rsp), %eax
movb %al, 0x1e0(%rsp)
movb $0x0, 0x1f8(%rsp)
andb %r15b, %sil
testb $0x1, %sil
je 0x6c027
movb $0x1, 0x1f8(%rsp)
movl 0x148(%rsp), %eax
movl %eax, 0x1f4(%rsp)
movl 0x1c8(%rsp), %eax
cmpl $0x2, %eax
je 0x6c046
cmpl $0x1, %eax
jne 0x6c054
movl $0x3, %eax
leaq 0x10dc0(%rip), %rcx     # 0x7ce04
jmp 0x6c060
movl $0x9, %eax
leaq 0x10d8e(%rip), %rcx     # 0x7cde0
jmp 0x6c060
movl $0x1, %eax
leaq 0x10db0(%rip), %rcx     # 0x7ce10
movl %eax, 0x1f0(%rsp)
movq %rcx, 0x1e8(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq %r8, %rdx
movq %r8, %r14
callq 0x6b136
movq %r13, %rdi
callq 0x6a334
testb %al, %al
je 0x6c255
movl 0x1c8(%rsp), %ecx
movq (%r14), %rax
testl %ecx, %ecx
jle 0x6c15d
cmpq $0xbb9, %rax            # imm = 0xBB9
jb 0x6c107
cmpq $0x1771, %rax           # imm = 0x1771
movl $0x2, %eax
movl $0x8, %edx
cmovael %edx, %eax
leaq 0x10d6c(%rip), %rdx     # 0x7ce30
leaq 0x10d75(%rip), %rsi     # 0x7ce40
cmovaeq %rsi, %rdx
cmpl $0x1, %ecx
movl $0x4, %ecx
cmovel %ecx, %eax
leaq 0x10d3f(%rip), %rcx     # 0x7ce20
cmoveq %rcx, %rdx
movl %eax, 0x1f0(%rsp)
movq %rdx, 0x1e8(%rsp)
movq %r13, %rdi
callq 0x6a334
testb %al, %al
je 0x6c255
movq (%r14), %rax
movq 0x190(%rsp), %rcx
cmpq %rax, %rcx
jae 0x6c15d
movl 0x198(%rsp), %eax
movl %eax, 0x8(%r14)
movb 0x1b0(%rsp), %al
movb %al, 0x20(%r14)
movl 0x19c(%rsp), %eax
movl %eax, 0xc(%r14)
movq %rcx, (%r14)
movl 0x10(%r14), %edx
cmpl 0x1a0(%rsp), %edx
jne 0x6c58a
movq 0x18(%r14), %rdi
movq 0x1a8(%rsp), %rsi
callq 0x60c0
movq (%r14), %rax
movq 0x1c0(%rsp), %rcx
addq %rax, %rcx
cmpq 0x50(%rsp), %rcx
jae 0x6c255
movl $0x1, %eax
movb $0x1, %sil
movq %rbx, %r8
testb $0x1, 0x70(%rsp)
movl $0x0, 0x70(%rsp)
jne 0x6bb5e
movl 0x148(%rsp), %eax
movl %eax, 0x88(%rsp)
cmpl $0x8, 0x150(%rsp)
jne 0x6c58a
movq %rcx, %r14
movb 0x160(%rsp), %al
movb %al, 0xf(%rsp)
movl 0x14c(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x140(%rsp), %rax
movq %rax, 0x128(%rsp)
movq 0x158(%rsp), %rax
movq 0x168(%rsp), %rcx
movq (%rax), %rax
movq %rax, 0xe0(%rsp)
movl 0x170(%rsp), %eax
movl %eax, 0xb0(%rsp)
cmpl $0x8, 0x178(%rsp)
jne 0x6c6b9
movq %rcx, 0x38(%rsp)
movl 0x174(%rsp), %eax
movq %rax, 0x48(%rsp)
movb 0x188(%rsp), %al
movb %al, 0xe(%rsp)
movq 0x180(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xe8(%rsp)
movl 0x1c(%rsp), %eax
movq %rax, 0x120(%rsp)
movl 0x6c(%rsp), %eax
movl %eax, 0x68(%rsp)
movq %r14, 0x50(%rsp)
movl $0x1, 0x1c(%rsp)
testb $0x1, %r15b
movl $0x0, %r15d
jne 0x6bb4a
movl $0x1, 0x6c(%rsp)
movq 0x128(%rsp), %rcx
movq 0x48(%rsp), %rax
movb 0xe(%rsp), %dl
movl 0x18(%rsp), %esi
movb 0xf(%rsp), %dil
testb $0x1, 0x34(%rsp)
movl $0x0, 0x34(%rsp)
jne 0x6bb29
movq 0x38(%rsp), %rax
movq %rax, 0xa8(%rsp)
movb 0xf(%rsp), %al
movb %al, 0xa0(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x8c(%rsp)
movb 0xe(%rsp), %al
movb %al, 0xc8(%rsp)
movq 0x48(%rsp), %rax
movl %eax, 0xb4(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x80(%rsp)
movzbl 0xb0(%rsp), %r8d
movzbl 0x88(%rsp), %edi
movzbl 0xb1(%rsp), %esi
movzbl 0x89(%rsp), %edx
movzbl 0xb2(%rsp), %ecx
movzbl 0x8a(%rsp), %eax
movq 0x120(%rsp), %r10
testl %r10d, %r10d
je 0x6c375
shlb $0x4, %dil
orb %r8b, %dil
movq 0x20(%rsp), %r8
movb %dil, (%r8)
shlb $0x4, %dl
orb %sil, %dl
movb %dl, 0x1(%r8)
shlb $0x4, %al
orb %cl, %al
jmp 0x6c3e9
movq %r8, %rcx
shll $0x3, %esi
movl %ebp, %eax
movb %sil, (%r8,%rax)
shlb $0x3, %bl
movl (%r10,%rax,4), %eax
movb %bl, (%r8,%rax)
shlb $0x3, %dl
incl %ebp
movl (%r10,%rbp,4), %eax
movb %dl, (%rcx,%rax)
jmp 0x6c573
subl %edi, %r8d
subl %edx, %esi
subl %eax, %ecx
cmpl %esi, %r8d
movl %esi, %r9d
cmovll %r8d, %r9d
cmpl %ecx, %r9d
cmovgel %ecx, %r9d
cmpl $-0x4, %r9d
jl 0x6c71e
cmpl %esi, %r8d
movl %esi, %r9d
cmovgl %r8d, %r9d
cmpl %ecx, %r9d
cmovlel %ecx, %r9d
cmpl $0x4, %r9d
jge 0x6c71e
movl %r8d, %r9d
shrl $0x1f, %r9d
leal (%r8,%r9,8), %r8d
shll $0x3, %edi
orl %r8d, %edi
movq 0x20(%rsp), %r8
movb %dil, (%r8)
movl %esi, %edi
shrl $0x1f, %edi
leal (%rsi,%rdi,8), %esi
shll $0x3, %edx
orl %esi, %edx
movb %dl, 0x1(%r8)
movl %ecx, %edx
shrl $0x1f, %edx
leal (%rcx,%rdx,8), %ecx
shll $0x3, %eax
orl %ecx, %eax
movb %al, 0x2(%r8)
movl 0x18(%rsp), %ecx
shll $0x5, %ecx
addl %r10d, %r10d
andl $0x2, %r10d
movq 0x48(%rsp), %rax
leal (%r10,%rax,4), %eax
orl %ecx, %eax
xorl $0x2, %eax
movl 0x68(%rsp), %ecx
orl %ecx, %eax
movb %al, 0x3(%r8)
testl %ecx, %ecx
je 0x6c4b6
xorl %edx, %edx
leaq 0x10280(%rip), %rsi     # 0x7c6a4
xorl %eax, %eax
xorl %ecx, %ecx
movzbl 0xef(%rsp,%rdx), %edi
movzbl (%rdi,%rsi), %r9d
movzbl 0xeb(%rsp,%rdx), %edi
movzbl (%rdi,%rsi), %edi
addl %r9d, %r9d
movl %r9d, %r8d
andl $0x2, %r8d
leal (%r8,%rcx,4), %ecx
movl %edi, %r10d
andl $0x1, %r10d
orl %ecx, %r10d
movzbl 0xe7(%rsp,%rdx), %ecx
movzbl (%rcx,%rsi), %r8d
shll $0x3, %eax
andl $-0x4, %r9d
andl $-0x2, %edi
orl %eax, %edi
orl %r9d, %edi
movzbl 0xe3(%rsp,%rdx), %eax
movzbl (%rax,%rsi), %eax
shll $0x2, %r10d
movl %r8d, %ecx
andl $0x1, %ecx
leal (%r10,%rcx,2), %r9d
movl %eax, %ecx
andl $0x1, %ecx
orl %r9d, %ecx
addl %edi, %edi
andl $-0x2, %r8d
shrl %eax
orl %r8d, %eax
orl %edi, %eax
decq %rdx
cmpq $-0x4, %rdx
jne 0x6c428
jmp 0x6c562
xorl %eax, %eax
movl $0x1, %edx
leaq 0x101e0(%rip), %rsi     # 0x7c6a4
xorl %ecx, %ecx
leaq (%rdx,%rdx,4), %rdi
movq 0x98(%rsp,%rdi,8), %rdi
addq $0x7, %rdi
movb $0x1, %r8b
movzbl (%rdi), %r9d
movzbl (%r9,%rsi), %r11d
movzbl -0x1(%rdi), %r9d
movzbl (%r9,%rsi), %r9d
addl %r11d, %r11d
movl %r11d, %r10d
andl $0x2, %r10d
leal (%r10,%rcx,4), %ecx
movl %r9d, %ebx
andl $0x1, %ebx
orl %ecx, %ebx
movzbl -0x2(%rdi), %ecx
movzbl (%rcx,%rsi), %r10d
shll $0x3, %eax
andl $-0x4, %r11d
andl $-0x2, %r9d
orl %eax, %r9d
orl %r11d, %r9d
movzbl -0x3(%rdi), %eax
movzbl (%rax,%rsi), %eax
shll $0x2, %ebx
movl %r10d, %ecx
andl $0x1, %ecx
leal (%rbx,%rcx,2), %r11d
movl %eax, %ecx
andl $0x1, %ecx
orl %r11d, %ecx
addl %r9d, %r9d
andl $-0x2, %r10d
shrl %eax
orl %r10d, %eax
orl %r9d, %eax
addq $-0x4, %rdi
testb $0x1, %r8b
movl $0x0, %r8d
jne 0x6c4d9
subq $0x1, %rdx
jae 0x6c4c6
movq 0x20(%rsp), %rdx
movb %ah, 0x4(%rdx)
movb %al, 0x5(%rdx)
movb %ch, 0x6(%rdx)
movb %cl, 0x7(%rdx)
movq 0x50(%rsp), %rax
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb 0xc(%rsp), %al
movb %al, 0xa0(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x8c(%rsp)
movb 0xd(%rsp), %al
movb %al, 0xc8(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0xb4(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0x1066d(%rip), %rdi     # 0x7cc44
leaq 0x10101(%rip), %rsi     # 0x7c6df
leaq 0x1066e(%rip), %rcx     # 0x7cc53
movl $0x599, %edx            # imm = 0x599
callq 0x61b0
movb 0xc(%rsp), %al
movb %al, 0xa0(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x8c(%rsp)
movb 0xd(%rsp), %al
movb %al, 0xc8(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0xb4(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0x104b2(%rip), %rdi     # 0x7caee
leaq 0x1009c(%rip), %rsi     # 0x7c6df
leaq 0x1051f(%rip), %rcx     # 0x7cb69
movl $0x7fb, %edx            # imm = 0x7FB
callq 0x61b0
movb 0xc(%rsp), %al
movb %al, 0xa0(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x8c(%rsp)
movb 0xd(%rsp), %al
movb %al, 0xc8(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0xb4(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0x1055f(%rip), %rdi     # 0x7cc00
leaq 0x10037(%rip), %rsi     # 0x7c6df
leaq 0x1055f(%rip), %rcx     # 0x7cc0e
movl $0xd0, %edx
callq 0x61b0
movb 0xc(%rsp), %al
movb %al, 0xa0(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x8c(%rsp)
movb 0xd(%rsp), %al
movb %al, 0xc8(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0xb4(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x80(%rsp)
movq %rcx, 0xa8(%rsp)
jmp 0x6c5d0
leaq 0x103e8(%rip), %rdi     # 0x7caee
leaq 0xffd2(%rip), %rsi      # 0x7c6df
leaq 0x103f8(%rip), %rcx     # 0x7cb0c
movl $0x7a2, %edx            # imm = 0x7A2
callq 0x61b0
leaq 0x1023a(%rip), %rdi     # 0x7c95f
leaq 0xffb3(%rip), %rsi      # 0x7c6df
leaq 0x102ac(%rip), %rcx     # 0x7c9df
movl $0x947, %edx            # imm = 0x947
callq 0x61b0