// File: /workspace/github_c_makefile_star2_O1/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 $0x378, %rsp            # imm = 0x378
movq %rdi, 0x20(%rsp)
movl (%rsi), %eax
movl $0x10, %ecx
leal -0x1(%rcx), %edi
cmpl %eax, (%rsi,%rdi,4)
jne 0x6981a
decl %ecx
cmpl $0x1, %ecx
ja 0x69809
xorl %edi, %edi
testl %edi, %edi
je 0x6a36d
cmpb $0x1, 0x4(%rdx)
jne 0x699a7
leaq 0x210(%rsp), %rax
pcmpeqd %xmm0, %xmm0
leaq 0x330(%rsp), %rcx
movdqa %xmm0, (%rcx)
movdqa %xmm0, 0x10(%rcx)
movdqa %xmm0, 0x20(%rcx)
movdqa %xmm0, 0x30(%rcx)
leaq 0x200(%rsp), %r8
xorl %r15d, %r15d
pxor %xmm0, %xmm0
leaq 0x66295f(%rip), %rdi    # 0x6cc1c8
movdqa %xmm0, 0x210(%rsp)
movdqa %xmm0, 0x200(%rsp)
xorl %r9d, %r9d
movq %r8, %r10
movq %rax, %r8
movq %r10, %rax
movzbl (%rsi,%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(%rsi,%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(%rsi,%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(%rsi,%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 0x69881
incq %r15
incq %rcx
incq %rsi
cmpq $0x3, %r15
jne 0x69869
leaq 0x330(%rsp), %rsi
xorl %eax, %eax
movb %al, 0x2a8(%rsp)
movq %rax, 0x2a0(%rsp)
movq $-0x1, %rcx
movq %rcx, 0x2b8(%rsp)
movb %al, 0x2c0(%rsp)
movq %rax, 0x2c8(%rsp)
movb %al, 0x2d0(%rsp)
movq %rcx, 0x2e0(%rsp)
movb %al, 0x2e8(%rsp)
pxor %xmm0, %xmm0
movdqa %xmm0, 0x200(%rsp)
movdqa %xmm0, 0x280(%rsp)
movl $0x3, %eax
leaq 0x300(%rsp), %rcx
movl $0x8, 0x38(%rsp,%rax,8)
movq %rcx, 0x40(%rsp,%rax,8)
addq $0x5, %rax
addq $0x8, %rcx
cmpq $0x8, %rax
je 0x69a0f
movq %rsi, 0xb0(%rsp)
movl $0x3, %eax
leaq 0x310(%rsp), %rcx
movl $0x8, 0x118(%rsp,%rax,8)
movq %rcx, 0x120(%rsp,%rax,8)
addq $0x5, %rax
addq $0x8, %rcx
cmpq $0x12, %rax
jne 0x69a3f
movq (%rdx), %rax
leaq 0x1c8(%rsp), %rcx
movq %rax, (%rcx)
xorl %edx, %edx
movb %dl, 0x18(%rcx)
leaq 0x13796(%rip), %rax     # 0x7d210
movq %rax, 0x20(%rcx)
movq $0x1, 0x28(%rcx)
movb %dl, 0x30(%rcx)
movl $0x8, 0x8(%rcx)
leaq 0xe0(%rsp), %rax
movq %rax, 0x10(%rcx)
movl 0x50(%rsp), %eax
movl %eax, 0x110(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x1a0(%rsp)
movl 0x78(%rsp), %eax
movl %eax, 0x10c(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x198(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x90(%rsp)
movl 0x48(%rsp), %eax
movl %eax, 0x18(%rsp)
movb 0x60(%rsp), %al
movb %al, 0xe(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x70(%rsp), %eax
movl %eax, 0x14(%rsp)
movb 0x88(%rsp), %al
movb %al, 0xd(%rsp)
movl 0x74(%rsp), %eax
movl %eax, 0x10(%rsp)
movq $-0x1, 0xb8(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x28(%rsp)
movl $0x0, 0x3c(%rsp)
movq $0x0, 0x118(%rsp)
movq $0x0, 0xc0(%rsp)
xorl %ebp, %ebp
movb $0x1, %cl
xorl %esi, %esi
movq $0x0, 0x100(%rsp)
movb %cl, 0xf(%rsp)
cmpl $0x0, 0xc0(%rsp)
je 0x69b91
movq %rsi, %rax
shlq $0x5, %rax
movq 0xb0(%rsp), %rcx
movdqu (%rcx,%rax), %xmm0
movups 0x10(%rcx,%rax), %xmm1
movaps %xmm1, 0xf0(%rsp)
movdqa %xmm0, 0xe0(%rsp)
jmp 0x69bf0
movq 0xb0(%rsp), %rcx
movl (%rcx,%rsi,8), %eax
movl %eax, 0xe0(%rsp)
movl 0x10(%rcx,%rsi,8), %eax
movl %eax, 0xe4(%rsp)
movl 0x20(%rcx,%rsi,8), %eax
movl %eax, 0xe8(%rsp)
movl 0x30(%rcx,%rsi,8), %eax
movl %eax, 0xec(%rsp)
movl 0x4(%rcx,%rsi,8), %eax
movl %eax, 0xf0(%rsp)
movl 0x14(%rcx,%rsi,8), %eax
movl %eax, 0xf4(%rsp)
movl 0x24(%rcx,%rsi,8), %eax
movl %eax, 0xf8(%rsp)
movl 0x34(%rcx,%rsi,8), %eax
movl %eax, 0xfc(%rsp)
movq $-0x1, 0x170(%rsp)
cmpl $0x0, 0x1c8(%rsp)
setle %al
movl %ebp, %ecx
orl %esi, %ecx
sete %cl
orb %al, %cl
jne 0x6a009
movl $0x8, %eax
movl 0xe0(%rsp), %ecx
leal -0x1(%rax), %edx
cmpl %ecx, 0xe0(%rsp,%rdx,4)
jne 0x69c37
decl %eax
cmpl $0x1, %eax
ja 0x69c22
xorl %edx, %edx
testl %edx, %edx
jne 0x6a009
testl %ebp, %ebp
sete %al
movq %rsi, 0x1a8(%rsp)
testq %rsi, %rsi
setne %r13b
andb %al, %r13b
movl $0x0, %ecx
leaq 0x128(%rsp), %rax
cmovneq %rax, %rcx
movq %rcx, 0x30(%rsp)
cmpw $0x0, 0x65a74a(%rip)    # 0x6c43be
je 0x6a897
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
movl $0x0, 0xc8(%rsp)
movl $0x0, 0xac(%rsp)
xorl %edx, %edx
movl $0x0, 0xa8(%rsp)
cmpq $0x3, %r9
je 0x69f5b
movl %edx, 0xd0(%rsp)
leaq 0x13563(%rip), %rax     # 0x7d220
movl (%rax,%r9,4), %edx
movl 0x4(%rax,%r9,4), %esi
movq %rdx, 0x98(%rsp)
movzbl 0xe0(%rsp,%rdx), %r12d
leaq 0x1(%r9), %rax
movq %rax, 0x1b0(%rsp)
movq %rsi, 0xd8(%rsp)
movzbl 0xe0(%rsp,%rsi), %r10d
movzbl 0xe0(%rsp,%r9), %edx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %esi, %esi
movq %rdx, 0x1b8(%rsp)
movl %esi, 0x114(%rsp)
leal (%rdi,%rdx), %r8d
movl $0xff, %eax
cmpl %eax, %r8d
cmovgel %eax, %r8d
testl %r8d, %r8d
movl $0x0, %eax
cmovlel %eax, %r8d
leaq 0x11c7a(%rip), %rsi     # 0x7b9b0
testl %r8d, %r8d
je 0x69d63
cmpl $0xff, %r8d
jne 0x69d4d
leaq 0x11ca7(%rip), %rsi     # 0x7b9f2
jmp 0x69d63
leal -0x1(%r8), %esi
movslq %esi, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq 0x11ce1(%rip), %rax     # 0x7ba40
leaq (%rax,%rsi,8), %rsi
movq %rdi, 0x1c0(%rsp)
subl %edx, %r8d
imull %r8d, %r8d
addq $0x2, %rsi
movq %r8, 0xa0(%rsp)
testl %ebp, %ebp
sete %dil
movzwl -0x2(%rsi), %ebx
movl %ebx, %r11d
andb $0x1, %r11b
cmpb %r11b, %dil
je 0x69da8
xorl %r15d, %r15d
cmpw $-0x1, (%rsi)
sete %r15b
xorl $0x9, %r15d
jmp 0x69ef4
movl %r13d, %edi
andb %bl, %dil
cmpb $0x1, %dil
jne 0x69dee
movl %ebx, %r11d
shrl $0x8, %r11d
movq 0x30(%rsp), %rax
movzbl (%rax,%r9), %r14d
subl %r14d, %r11d
addl $0x4, %r11d
xorl %r15d, %r15d
cmpl $0x8, %r11d
jb 0x69de4
xorl %r15d, %r15d
cmpw $-0x1, (%rsi)
sete %r15b
xorl $0x9, %r15d
cmpl $0x7, %r11d
ja 0x69ef4
movzbl %bl, %r11d
shll $0x9, %r11d
leaq 0x65a3c3(%rip), %rax    # 0x6c41c0
addq %rax, %r11
movzwl (%r11,%r12,2), %r14d
movzwl (%r11,%r10,2), %r11d
testb %dil, %dil
je 0x69ea4
movq %r9, %r8
movl %r13d, %r9d
movq %rbp, %r13
movq %r10, %rbp
movq %r12, %r10
movq %rcx, %r12
movl %r14d, %edi
movl $0xff, %eax
andl %eax, %edi
movq 0x98(%rsp), %rcx
movq 0x30(%rsp), %rdx
movzbl (%rdx,%rcx), %r15d
subl %r15d, %edi
movl %r11d, %r15d
andl %eax, %r15d
movq 0xd8(%rsp), %rax
movzbl (%rdx,%rax), %ecx
addl $0x4, %edi
cmpl $0x8, %edi
setb %al
subl %ecx, %r15d
addl $0x4, %r15d
cmpl $0x8, %r15d
setb %dil
xorl %r15d, %r15d
andb %al, %dil
jne 0x69e85
xorl %r15d, %r15d
cmpw $-0x1, (%rsi)
sete %r15b
xorl $0x9, %r15d
testb %dil, %dil
movq %r12, %rcx
movq %r10, %r12
movq %rbp, %r10
movq %r13, %rbp
movl %r9d, %r13d
movq %r8, %r9
movq 0xa0(%rsp), %r8
je 0x69ef4
movl %r14d, %eax
shrl $0x8, %eax
imull %eax, %eax
addl %r8d, %eax
movl %r11d, %edi
shrl $0x8, %edi
imull %edi, %edi
addl %eax, %edi
xorl %r15d, %r15d
cmpl %ecx, %edi
jae 0x69ef4
testl %edi, %edi
movl $0x0, %r15d
movl $0xa, %eax
cmovel %eax, %r15d
movl %r11d, 0xc8(%rsp)
movl %r14d, 0xac(%rsp)
movl %ebx, 0xd0(%rsp)
movl %r9d, 0xa8(%rsp)
movl %edi, %ecx
testl %r15d, %r15d
je 0x69eff
cmpl $0x9, %r15d
jne 0x69f0f
cmpw $-0x1, (%rsi)
leaq 0x2(%rsi), %rsi
jne 0x69d7e
jmp 0x69f15
cmpl $0x8, %r15d
jne 0x69f3b
movq 0x1c0(%rsp), %rax
testl %eax, %eax
leal 0x1(%rax), %eax
setg %sil
movl %eax, %edi
cmpl $0x2, %eax
movq 0x1b8(%rsp), %rdx
jne 0x69d0c
jmp 0x69f42
movl 0x114(%rsp), %esi
movq 0x1b0(%rsp), %r9
testb $0x1, %sil
movl 0xd0(%rsp), %edx
jne 0x69ca5
cmpl $-0x1, %ecx
movq 0x1a8(%rsp), %rsi
je 0x6a009
movq %rcx, %rdi
movl $0x8, 0x180(%rsp)
movl %edx, %eax
notb %al
andb $0x1, %al
movb %al, 0x190(%rsp)
movl %edx, %eax
shrl %eax
andl $0x7, %eax
movl %eax, 0x17c(%rsp)
movq 0x188(%rsp), %rax
movl %edx, %ecx
shrb $0x4, %cl
andb $0x3, %cl
movzbl %cl, %ecx
movl %edx, %ebx
movabsq $0x101010101010101, %rdx # imm = 0x101010101010101
imulq %rdx, %rcx
movq %rcx, (%rax)
movl 0xa8(%rsp), %eax
cmpl $0x4, %eax
jae 0x6a900
shll $0x3, %edi
movl %eax, %eax
movb %bh, 0x178(%rsp,%rax)
leaq 0x13242(%rip), %rdx     # 0x7d220
movl (%rdx,%rax,4), %ecx
movl 0x4(%rdx,%rax,4), %eax
movl 0xac(%rsp), %edx
movb %dl, 0x178(%rsp,%rcx)
movl 0xc8(%rsp), %ecx
movb %cl, 0x178(%rsp,%rax)
movq %rdi, 0x170(%rsp)
testl %ebp, %ebp
setne %al
movb %bpl, 0x1e0(%rsp)
movb $0x0, 0x1f8(%rsp)
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0x6a03e
movb $0x1, 0x1f8(%rsp)
movl 0x128(%rsp), %eax
movl %eax, 0x1f4(%rsp)
movl 0x1c8(%rsp), %eax
cmpl $0x2, %eax
je 0x6a05d
cmpl $0x1, %eax
jne 0x6a06b
movl $0x3, %eax
leaq 0x118f9(%rip), %rcx     # 0x7b954
jmp 0x6a077
movl $0x9, %eax
leaq 0x118c7(%rip), %rcx     # 0x7b930
jmp 0x6a077
movl $0x1, %eax
leaq 0x118e9(%rip), %rcx     # 0x7b960
movl %eax, 0x1f0(%rsp)
movq %rcx, 0x1e8(%rsp)
movq %rsi, %r14
leaq (%rsi,%rsi,4), %rax
leaq (%rsp,%rax,8), %r13
addq $0x120, %r13            # imm = 0x120
leaq 0x200(%rsp), %rbx
movq %rbx, %rdi
leaq 0x1c8(%rsp), %rsi
movq %r13, %rdx
callq 0x693be
movq %rbx, %rdi
callq 0x68620
testb %al, %al
je 0x6a1c4
movl 0x1c8(%rsp), %eax
testl %eax, %eax
jle 0x6a194
movq (%r13), %rcx
cmpq $0xbb9, %rcx            # imm = 0xBB9
jb 0x6a13f
cmpq $0x1771, %rcx           # imm = 0x1771
movl $0x2, %ecx
movl $0x8, %edx
cmovael %edx, %ecx
leaq 0x11886(%rip), %rdx     # 0x7b980
leaq 0x1188f(%rip), %rsi     # 0x7b990
cmovaeq %rsi, %rdx
cmpl $0x1, %eax
movl $0x4, %eax
cmovel %eax, %ecx
leaq 0x11859(%rip), %rax     # 0x7b970
cmoveq %rax, %rdx
movl %ecx, 0x1f0(%rsp)
movq %rdx, 0x1e8(%rsp)
leaq 0x200(%rsp), %rdi
callq 0x68620
testb %al, %al
je 0x6a1c4
movq 0x170(%rsp), %rax
cmpq (%r13), %rax
jae 0x6a194
movl 0x178(%rsp), %ecx
movl %ecx, 0x8(%r13)
movb 0x190(%rsp), %cl
movb %cl, 0x20(%r13)
movl 0x17c(%rsp), %ecx
movl %ecx, 0xc(%r13)
movq %rax, (%r13)
movl 0x180(%rsp), %edx
cmpl %edx, 0x10(%r13)
jne 0x6a82e
movq 0x18(%r13), %rdi
movq 0x188(%rsp), %rsi
callq 0x60c0
movq 0x100(%rsp), %rcx
addq (%r13), %rcx
movq %rcx, 0x100(%rsp)
cmpq 0xb8(%rsp), %rcx
jae 0x6a1c4
leaq 0x1(%r14), %rsi
testq %r14, %r14
sete %cl
je 0x69b57
jmp 0x6a1c8
movb 0xf(%rsp), %cl
testb $0x1, %cl
jne 0x6a2a8
movl 0x128(%rsp), %eax
movl %eax, 0x18(%rsp)
movb 0x140(%rsp), %al
movb %al, 0xe(%rsp)
movl 0x12c(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x120(%rsp), %rax
movl 0x130(%rsp), %edx
cmpl %edx, 0x110(%rsp)
jne 0x6a969
movq %rax, 0x90(%rsp)
movq 0x138(%rsp), %rsi
movq 0x1a0(%rsp), %rdi
callq 0x60c0
movl 0x150(%rsp), %eax
movl %eax, 0x14(%rsp)
movb 0x168(%rsp), %al
movb %al, 0xd(%rsp)
movl 0x154(%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0x148(%rsp), %rax
movq %rax, 0x28(%rsp)
movl 0x158(%rsp), %edx
cmpl %edx, 0x10c(%rsp)
jne 0x6a82e
movq 0x160(%rsp), %rsi
movq 0x198(%rsp), %rdi
callq 0x60c0
movl %ebp, %eax
movq %rax, 0x118(%rsp)
movq 0xc0(%rsp), %rax
movl %eax, 0x3c(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0xb8(%rsp)
leal 0x1(%rbp), %eax
testl %ebp, %ebp
movl %eax, %ebp
je 0x69b47
movb 0xd(%rsp), %al
movb %al, 0x88(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x74(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x68(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x48(%rsp)
movb 0xe(%rsp), %al
movb %al, 0x60(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x70(%rsp)
movq 0xc0(%rsp), %rcx
leal 0x1(%rcx), %eax
testl %ecx, %ecx
movq %rax, 0xc0(%rsp)
je 0x69b45
movq 0x90(%rsp), %rax
movq %rax, 0x40(%rsp)
movzbl 0x70(%rsp), %r8d
movzbl 0x48(%rsp), %edi
movzbl 0x71(%rsp), %esi
movzbl 0x49(%rsp), %edx
movzbl 0x72(%rsp), %ecx
movzbl 0x4a(%rsp), %eax
movq 0x118(%rsp), %r10
testl %r10d, %r10d
je 0x6a5d6
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 0x6a64a
cmpw $0x0, 0x65a049(%rip)    # 0x6c43be
je 0x6a9ca
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
leaq 0x12e98(%rip), %rdi     # 0x7d220
movl $0xff, %r9d
xorl %r15d, %r15d
movl $0x0, 0x30(%rsp)
movl $0x0, 0x98(%rsp)
xorl %r11d, %r11d
movq $0x0, 0xa0(%rsp)
movq %rsi, 0xb0(%rsp)
cmpq $0x3, %r15
je 0x6a53b
movl (%rdi,%r15,4), %eax
movl 0x4(%rdi,%r15,4), %ecx
movzbl (%rsi,%rax), %r13d
leaq 0x1(%r15), %rax
movq %rax, 0xc8(%rsp)
movzbl (%rsi,%rcx), %ebp
movzbl (%rsi,%r15), %edx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x0, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
leal (%rdi,%rdx), %ebx
cmpl %r9d, %ebx
cmovgel %r9d, %ebx
testl %ebx, %ebx
movl $0x0, %eax
cmovlel %eax, %ebx
leaq 0x11595(%rip), %r10     # 0x7b9b0
testl %ebx, %ebx
je 0x6a444
cmpl $0xff, %ebx
jne 0x6a430
leaq 0x115c4(%rip), %r10     # 0x7b9f2
jmp 0x6a444
leal -0x1(%rbx), %eax
cltq
leaq (%rax,%rax,2), %rax
leaq 0x11600(%rip), %rcx     # 0x7ba40
leaq (%rcx,%rax,8), %r10
subl %edx, %ebx
imull %ebx, %ebx
addq $0x2, %r10
movzwl -0x2(%r10), %r8d
movzbl %r8b, %eax
shll $0x9, %eax
leaq 0x659d60(%rip), %rcx    # 0x6c41c0
addq %rcx, %rax
movzwl (%rax,%r13,2), %esi
movzwl (%rax,%rbp,2), %ecx
movl %esi, %eax
shrl $0x8, %eax
imull %eax, %eax
addl %ebx, %eax
movl %ecx, %edx
shrl $0x8, %edx
imull %edx, %edx
addl %eax, %edx
xorl %r12d, %r12d
movb $0x1, %al
cmpl %r14d, %edx
jae 0x6a4d9
andl %r9d, %esi
andl %r9d, %ecx
testl %edx, %edx
je 0x6a4b5
xorl %r12d, %r12d
movl %ecx, 0x30(%rsp)
movl %esi, 0x98(%rsp)
movl %r8d, %r11d
movl %r15d, %ecx
movq %rcx, 0xa0(%rsp)
movl %edx, %r14d
jmp 0x6a4d9
xorl %eax, %eax
movl $0xa, %r12d
movl %ecx, 0x30(%rsp)
movl %esi, 0x98(%rsp)
movl %r8d, %r11d
movl %r15d, %ecx
movq %rcx, 0xa0(%rsp)
xorl %r14d, %r14d
testb %al, %al
je 0x6a4ef
cmpw $-0x1, (%r10)
leaq 0x2(%r10), %r10
jne 0x6a44d
xorl %r12d, %r12d
testl %r12d, %r12d
movq 0xd0(%rsp), %rdx
jne 0x6a516
testl %edi, %edi
leal 0x1(%rdi), %eax
setg %cl
movl %ecx, 0xd8(%rsp)
movl %eax, %edi
cmpl $0x2, %eax
jne 0x6a400
movq 0xc8(%rsp), %r15
testb $0x1, 0xd8(%rsp)
movq 0xb0(%rsp), %rsi
leaq 0x12ceb(%rip), %rdi     # 0x7d220
jne 0x6a3bb
movl %r11d, %eax
andl $0x1, %eax
leal (%r11,%r11), %ecx
andl $0x1c, %ecx
leal (%rcx,%rcx,8), %ecx
leal (%rcx,%rax,2), %ecx
movq 0x20(%rsp), %rsi
movb %cl, 0x3(%rsi)
movl %r11d, %ecx
shrl $0x4, %ecx
andl $0x3, %ecx
leaq 0x10c0e(%rip), %rdx     # 0x7b174
movzbl (%rcx,%rdx), %ecx
movl %ecx, %edx
shll $0x1e, %edx
sarl $0x1f, %edx
movw %dx, 0x4(%rsi)
andl $0x1, %ecx
negl %ecx
movw %cx, 0x6(%rsi)
shrl $0x8, %r11d
testl %eax, %eax
jne 0x6a7e1
movl %r11d, %eax
shll $0x4, %eax
orl %r11d, %eax
movq 0xa0(%rsp), %rsi
movl %esi, %ecx
movq 0x20(%rsp), %rdx
movb %al, (%rdx,%rcx)
movl 0x98(%rsp), %edx
movl %edx, %eax
shll $0x4, %eax
orl %edx, %eax
movl (%rdi,%rcx,4), %ecx
movq 0x20(%rsp), %rdx
movb %al, (%rdx,%rcx)
movq 0x20(%rsp), %rcx
movl 0x30(%rsp), %edx
movl %edx, %eax
shll $0x4, %eax
orl %edx, %eax
movl %eax, %edx
jmp 0x6a80d
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 0x6a9ab
cmpl %esi, %r8d
movl %esi, %r9d
cmovgl %r8d, %r9d
cmpl %ecx, %r9d
cmovlel %ecx, %r9d
cmpl $0x4, %r9d
jge 0x6a9ab
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
movl 0x3c(%rsp), %edx
movb %al, 0x2(%r8)
movl 0x4c(%rsp), %eax
movl 0x74(%rsp), %ecx
shll $0x5, %eax
addl %r10d, %r10d
andl $0x2, %r10d
leal (%r10,%rcx,4), %ecx
orl %eax, %ecx
xorl $0x2, %ecx
orl %edx, %ecx
movb %cl, 0x3(%r8)
testl %edx, %edx
je 0x6a721
movq 0x58(%rsp), %rdx
movq 0x80(%rsp), %rsi
xorl %eax, %eax
movl $0x7, %edi
leaq 0x10ade(%rip), %r8      # 0x7b174
xorl %ecx, %ecx
movq 0xb8(%rsp), %r14
movzbl (%rsi,%rdi), %r9d
movzbl (%r9,%r8), %r11d
movzbl -0x4(%rsi,%rdi), %r9d
movzbl (%r9,%r8), %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 (%rdx,%rdi), %ecx
movzbl (%rcx,%r8), %r10d
shll $0x3, %eax
andl $-0x4, %r11d
andl $-0x2, %r9d
orl %eax, %r9d
orl %r11d, %r9d
movzbl -0x4(%rdx,%rdi), %eax
movzbl (%rax,%r8), %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
decq %rdi
cmpq $0x3, %rdi
jne 0x6a6a0
jmp 0x6a7ce
xorl %eax, %eax
movl $0x1, %edx
leaq 0x10a45(%rip), %rsi     # 0x7b174
xorl %ecx, %ecx
movq 0xb8(%rsp), %r14
leaq (%rdx,%rdx,4), %rdi
movq 0x58(%rsp,%rdi,8), %rdi
addq $0x7, %rdi
movl $0x1, %r8d
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
decl %r8d
je 0x6a74c
subq $0x1, %rdx
jae 0x6a739
movq 0x20(%rsp), %rdx
movb %ah, 0x4(%rdx)
movb %al, 0x5(%rdx)
movb %ch, 0x6(%rdx)
movb %cl, 0x7(%rdx)
jmp 0x6a819
movq %rsi, %rcx
shll $0x3, %r11d
movq 0xa0(%rsp), %rsi
movl %esi, %eax
movb %r11b, (%rcx,%rax)
movl 0x98(%rsp), %edx
shlb $0x3, %dl
movl (%rdi,%rax,4), %eax
movb %dl, (%rcx,%rax)
movl 0x30(%rsp), %edx
shlb $0x3, %dl
incl %esi
movl (%rdi,%rsi,4), %eax
movb %dl, (%rcx,%rax)
shll $0x4, %r14d
movl %r14d, %eax
addq $0x378, %rsp            # imm = 0x378
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb 0xd(%rsp), %al
movb %al, 0x88(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x74(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x68(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x48(%rsp)
movb 0xe(%rsp), %al
movb %al, 0x60(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x70(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x10f1d(%rip), %rdi     # 0x7b79c
leaq 0x10929(%rip), %rsi     # 0x7b1af
leaq 0x10f1e(%rip), %rcx     # 0x7b7ab
movl $0x599, %edx            # imm = 0x599
callq 0x61b0
movb 0xd(%rsp), %al
movb %al, 0x88(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x74(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x68(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x48(%rsp)
movb 0xe(%rsp), %al
movb %al, 0x60(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x70(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x10d5e(%rip), %rdi     # 0x7b646
leaq 0x108c0(%rip), %rsi     # 0x7b1af
leaq 0x10dcb(%rip), %rcx     # 0x7b6c1
movl $0x7fb, %edx            # imm = 0x7FB
callq 0x61b0
movb 0xd(%rsp), %al
movb %al, 0x88(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x74(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x68(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x48(%rsp)
movb 0xe(%rsp), %al
movb %al, 0x60(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x70(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x10e07(%rip), %rdi     # 0x7b758
leaq 0x10857(%rip), %rsi     # 0x7b1af
leaq 0x10e07(%rip), %rcx     # 0x7b766
movl $0xd0, %edx
callq 0x61b0
movb 0xd(%rsp), %cl
movb %cl, 0x88(%rsp)
movl 0x10(%rsp), %ecx
movl %ecx, 0x74(%rsp)
movq 0x28(%rsp), %rcx
movq %rcx, 0x68(%rsp)
movl 0x18(%rsp), %ecx
movl %ecx, 0x48(%rsp)
movb 0xe(%rsp), %cl
movb %cl, 0x60(%rsp)
movl 0x1c(%rsp), %ecx
movl %ecx, 0x4c(%rsp)
movl 0x14(%rsp), %ecx
movl %ecx, 0x70(%rsp)
jmp 0x6a873
leaq 0x10a7d(%rip), %rdi     # 0x7b42f
leaq 0x107f6(%rip), %rsi     # 0x7b1af
leaq 0x10aef(%rip), %rcx     # 0x7b4af
movl $0x947, %edx            # imm = 0x947
callq 0x61b0
leaq 0x10c75(%rip), %rdi     # 0x7b646
leaq 0x107d7(%rip), %rsi     # 0x7b1af
leaq 0x10c85(%rip), %rcx     # 0x7b664
movl $0x7a2, %edx            # imm = 0x7A2
callq 0x61b0