// File: /workspace/github_c_makefile_star2_O2/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 $0x318, %rsp            # imm = 0x318
movq %rsi, %r14
movq %rdi, 0x28(%rsp)
movl (%rsi), %eax
pushq $0xf
popq %rsi
movl %esi, %ecx
subl $0x1, %ecx
jb 0x6041c
movl %esi, %edi
movl %ecx, %esi
cmpl %eax, (%r14,%rdi,4)
je 0x602b2
cmpb $0x1, 0x4(%rdx)
jne 0x6061d
leaq 0x1c0(%rsp), %r10
pcmpeqd %xmm0, %xmm0
leaq 0x2d0(%rsp), %rax
movdqa %xmm0, (%rax)
movdqa %xmm0, 0x10(%rax)
movdqa %xmm0, 0x20(%rax)
movdqa %xmm0, 0x30(%rax)
leaq 0x1b0(%rsp), %rsi
xorl %ecx, %ecx
pxor %xmm0, %xmm0
leaq 0x665ead(%rip), %rdi    # 0x6c61b8
cmpq $0x3, %rcx
je 0x60615
movdqa %xmm0, 0x1c0(%rsp)
movdqa %xmm0, 0x1b0(%rsp)
xorl %r9d, %r9d
movq %r10, %r8
cmpl $0x40, %r9d
je 0x6040b
imull $0x3, 0x4(%r8), %r10d
imull $0x5, (%r8), %r11d
movzbl (%r14,%r9), %ebx
addl %r10d, %r11d
sarl $0x4, %r11d
movslq %r11d, %r10
addq %rbx, %r10
movzbl (%rdi,%r10), %r10d
movb %r10b, (%rax,%r9)
subl %r10d, %ebx
movl %ebx, (%rsi)
movzbl 0x4(%r14,%r9), %r10d
imull $0x3, 0x8(%r8), %r11d
imull $0x7, %ebx, %ebx
imull $0x5, 0x4(%r8), %ebp
addl %r11d, %ebp
addl %ebx, %ebp
addl (%r8), %ebp
sarl $0x4, %ebp
movslq %ebp, %r11
addq %r10, %r11
movzbl (%rdi,%r11), %r11d
movb %r11b, 0x4(%rax,%r9)
subl %r11d, %r10d
movl %r10d, 0x4(%rsi)
movzbl 0x8(%r14,%r9), %r11d
imull $0x7, %r10d, %r10d
imull $0x3, 0xc(%r8), %ebx
imull $0x5, 0x8(%r8), %ebp
addl %ebx, %ebp
addl %r10d, %ebp
addl 0x4(%r8), %ebp
sarl $0x4, %ebp
movslq %ebp, %r10
addq %r11, %r10
movzbl (%rdi,%r10), %r10d
movb %r10b, 0x8(%rax,%r9)
subl %r10d, %r11d
movl %r11d, 0x8(%rsi)
movzbl 0xc(%r14,%r9), %r10d
imull $0x7, %r11d, %r11d
imull $0x5, 0xc(%r8), %ebx
addl %r11d, %ebx
addl 0x8(%r8), %ebx
sarl $0x4, %ebx
movslq %ebx, %r11
addq %r10, %r11
movzbl (%rdi,%r11), %r11d
movb %r11b, 0xc(%rax,%r9)
subl %r11d, %r10d
movl %r10d, 0xc(%rsi)
addq $0x10, %r9
movq %rsi, %r10
movq %r8, %rsi
jmp 0x6032a
incq %rcx
incq %r14
incq %rax
movq %r8, %r10
jmp 0x6030b
cmpw $0x0, 0x65df8a(%rip)    # 0x6be3ae
je 0x60f84
pushq $-0x1
popq %rax
leaq 0x10fac(%rip), %r10     # 0x713e0
movl $0xff, %edi
xorl %esi, %esi
movl $0x0, 0x38(%rsp)
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r15d, %r15d
movl %eax, %r9d
movq %r14, 0x30(%rsp)
cmpq $0x3, %rsi
je 0x60f4d
movl (%r10,%rsi,4), %eax
movl 0x4(%r10,%rsi,4), %edx
movzbl (%r14,%rax), %r12d
leaq 0x1(%rsi), %rax
movq %rax, 0x60(%rsp)
movzbl (%r14,%rdx), %r11d
movq %rsi, %r13
movzbl (%r14,%rsi), %esi
pushq $-0x1
popq %rax
movq %rsi, 0x8(%rsp)
cmpl $0x2, %eax
je 0x60557
movq %rax, 0x68(%rsp)
addl %esi, %eax
cmpl %edi, %eax
cmovgel %edi, %eax
testl %eax, %eax
movl $0x0, %edx
cmovlel %edx, %eax
leaq 0x11811(%rip), %r10     # 0x71cc0
testl %eax, %eax
je 0x604d7
cmpl $0xff, %eax
jne 0x604c3
leaq 0x11841(%rip), %r10     # 0x71d02
jmp 0x604d7
leal -0x1(%rax), %edx
movslq %edx, %rdx
imulq $0x18, %rdx, %r10
leaq 0x1187c(%rip), %rdx     # 0x71d50
addq %rdx, %r10
subl %esi, %eax
imull %eax, %eax
movzwl (%r10), %ebx
addq $0x2, %r10
movzwl %bx, %r14d
movzbl %r14b, %edx
shll $0x9, %edx
leaq 0x65dcba(%rip), %rsi    # 0x6be1b0
addq %rsi, %rdx
movzwl (%rdx,%r12,2), %esi
movzwl (%rdx,%r11,2), %edx
movl %esi, %ebp
shrl $0x8, %ebp
imull %ebp, %ebp
addl %eax, %ebp
movl %edx, %ebx
shrl $0x8, %ebx
imull %ebx, %ebx
addl %ebp, %ebx
cmpl %r9d, %ebx
jae 0x60533
andl %edi, %esi
andl %edi, %edx
testl %ebx, %ebx
je 0x60568
movl %edx, 0x38(%rsp)
movl %esi, %ecx
movl %r14d, %r8d
movl %r13d, %r15d
movl %ebx, %r9d
movzwl (%r10), %ebx
addq $0x2, %r10
cmpw $-0x1, %bx
jne 0x604e4
movq 0x68(%rsp), %rax
incl %eax
movq 0x30(%rsp), %r14
movq 0x8(%rsp), %rsi
jmp 0x60489
movq 0x60(%rsp), %rsi
leaq 0x10e7d(%rip), %r10     # 0x713e0
jmp 0x60453
xorl %ebx, %ebx
leaq 0x10e6f(%rip), %r10     # 0x713e0
movl %r14d, %eax
andl $0x1, %eax
movl %r14d, %ecx
shrl %ecx
andl $0x7, %ecx
imull $0x24, %ecx, %ecx
leal (%rcx,%rax,2), %ecx
movq 0x28(%rsp), %r8
movb %cl, 0x3(%r8)
movl %r14d, %ecx
shrl $0x4, %ecx
andl $0x3, %ecx
leaq 0x10e56(%rip), %rdi     # 0x713f4
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, %r14d
testl %eax, %eax
jne 0x605eb
movl %r14d, %eax
shll $0x4, %eax
orl %r14d, %eax
movl %r13d, %ecx
movb %al, (%r8,%rcx)
movl %esi, %eax
shll $0x4, %eax
orl %esi, %eax
movl (%r10,%rcx,4), %ecx
movb %al, (%r8,%rcx)
movl %edx, %eax
shll $0x4, %eax
orl %edx, %eax
movl %eax, %edx
jmp 0x60605
shll $0x3, %r14d
movl %r13d, %eax
movb %r14b, (%r8,%rax)
shlb $0x3, %sil
movl (%r10,%rax,4), %eax
movb %sil, (%r8,%rax)
shlb $0x3, %dl
incl %r13d
movl (%r10,%r13,4), %eax
movb %dl, (%r8,%rax)
jmp 0x60e81
leaq 0x2d0(%rsp), %r14
xorl %eax, %eax
andq $0x0, 0x250(%rsp)
movb %al, 0x258(%rsp)
orq $-0x1, 0x268(%rsp)
movb %al, 0x270(%rsp)
andq $0x0, 0x278(%rsp)
movb %al, 0x280(%rsp)
orq $-0x1, 0x290(%rsp)
movb %al, 0x298(%rsp)
pxor %xmm0, %xmm0
movdqa %xmm0, 0x1b0(%rsp)
movdqa %xmm0, 0x230(%rsp)
pushq $0x8
popq %rcx
leaq 0xf8(%rsp), %rsi
movl %ecx, -0x18(%rsi)
leaq 0x1a0(%rsp), %rax
movq %rax, -0x10(%rsi)
movl %ecx, 0x10(%rsi)
leaq 0x1a8(%rsp), %rax
movq %rax, 0x18(%rsi)
pushq $0x3
popq %rax
leaq 0x2b0(%rsp), %rcx
cmpq $0x12, %rax
je 0x606cc
movl $0x8, 0x118(%rsp,%rax,8)
movq %rcx, 0x120(%rsp,%rax,8)
addq $0x5, %rax
addq $0x8, %rcx
jmp 0x606a9
movq (%rdx), %rax
leaq 0x98(%rsp), %rcx
movq %rax, (%rcx)
xorl %edx, %edx
movb %dl, 0x18(%rcx)
leaq 0x12e3a(%rip), %rax     # 0x73520
movq %rax, 0x20(%rcx)
movq $0x1, 0x28(%rcx)
movb %dl, 0x30(%rcx)
movl $0x8, 0x8(%rcx)
leaq 0x40(%rsp), %rax
movq %rax, 0x10(%rcx)
pushq $-0x1
popq %rbx
xorl %eax, %eax
movq $0x0, 0x70(%rsp)
movl $0x0, 0x18(%rsp)
movq %r14, 0x30(%rsp)
cmpl $0x2, %eax
je 0x60cba
xorl %r15d, %r15d
movl %eax, 0x4(%rsp)
cmpl $0x2, %r15d
je 0x60cb3
xorl %edi, %edi
xorl %ecx, %ecx
movq %rbx, 0x78(%rsp)
cmpq $0x2, %rdi
je 0x60c6e
testl %eax, %eax
movq %rcx, 0x90(%rsp)
je 0x60779
movq %rdi, %rax
shlq $0x5, %rax
movdqu (%r14,%rax), %xmm0
movups 0x10(%r14,%rax), %xmm1
movaps %xmm1, 0x50(%rsp)
movdqa %xmm0, 0x40(%rsp)
jmp 0x607c0
movl (%r14,%rdi,8), %eax
movl %eax, 0x40(%rsp)
movl 0x10(%r14,%rdi,8), %eax
movl %eax, 0x44(%rsp)
movl 0x20(%r14,%rdi,8), %eax
movl %eax, 0x48(%rsp)
movl 0x30(%r14,%rdi,8), %eax
movl %eax, 0x4c(%rsp)
movl 0x4(%r14,%rdi,8), %eax
movl %eax, 0x50(%rsp)
movl 0x14(%r14,%rdi,8), %eax
movl %eax, 0x54(%rsp)
movl 0x24(%r14,%rdi,8), %eax
movl %eax, 0x58(%rsp)
movl 0x34(%r14,%rdi,8), %eax
movl %eax, 0x5c(%rsp)
orq $-0x1, 0x170(%rsp)
cmpl $0x0, 0x98(%rsp)
setle %al
movl %r15d, %ecx
orl %edi, %ecx
sete %cl
orb %al, %cl
movq %rdi, 0x10(%rsp)
jne 0x60ad7
movl 0x40(%rsp), %eax
pushq $0x7
popq %rdx
movl %edx, %ecx
subl $0x1, %ecx
jb 0x60806
movl %edx, %esi
movl %ecx, %edx
cmpl %eax, 0x40(%rsp,%rsi,4)
je 0x607f2
jmp 0x60ad7
testl %r15d, %r15d
sete %al
testq %rdi, %rdi
setne %r14b
andb %al, %r14b
movl $0x0, %ecx
leaq 0x128(%rsp), %rax
cmovneq %rax, %rcx
cmpw $0x0, 0x65db7f(%rip)    # 0x6be3ae
je 0x60f65
xorl %edx, %edx
xorl %ebp, %ebp
xorl %r13d, %r13d
movl $0x0, 0x1c(%rsp)
xorl %esi, %esi
pushq $-0x1
popq %rax
movq %rax, 0x8(%rsp)
cmpq $0x3, %rdx
je 0x60c47
movl %r13d, 0x20(%rsp)
movq %rsi, 0x80(%rsp)
movl %ebp, 0x24(%rsp)
leaq 0x10b70(%rip), %rax     # 0x713e0
movl (%rax,%rdx,4), %esi
movl 0x4(%rax,%rdx,4), %eax
movzbl 0x40(%rsp,%rsi), %r8d
leaq 0x1(%rdx), %rdi
movq %rdi, 0x88(%rsp)
movq %rax, 0x38(%rsp)
movzbl 0x40(%rsp,%rax), %r10d
movzbl 0x40(%rsp,%rdx), %r9d
pushq $-0x1
popq %rax
movq %r9, 0x60(%rsp)
cmpl $0x2, %eax
je 0x609fd
movq %rax, 0x68(%rsp)
leal (%rax,%r9), %r13d
movl $0xff, %eax
cmpl %eax, %r13d
movl $0xff, %edi
cmovgel %eax, %r13d
testl %r13d, %r13d
movl $0x0, %eax
cmovlel %eax, %r13d
leaq 0x113e8(%rip), %rbp     # 0x71cc0
testl %r13d, %r13d
je 0x60903
cmpl $0xff, %r13d
jne 0x608ef
leaq 0x11415(%rip), %rbp     # 0x71d02
jmp 0x60903
leal -0x1(%r13), %eax
cltq
imulq $0x18, %rax, %rbp
leaq 0x11450(%rip), %rax     # 0x71d50
addq %rax, %rbp
subl %r9d, %r13d
imull %r13d, %r13d
movzwl (%rbp), %ebx
addq $0x2, %rbp
testl %r15d, %r15d
sete %al
movl %ebx, %r11d
andb $0x1, %r11b
cmpb %r11b, %al
jne 0x60998
movzwl %bx, %ebx
movl %r14d, %eax
andb %bl, %al
cmpb $0x1, %al
jne 0x60949
movl %ebx, %r11d
shrl $0x8, %r11d
movzbl (%rcx,%rdx), %r12d
subl %r12d, %r11d
addl $0x4, %r11d
cmpl $0x8, %r11d
jae 0x60998
movzbl %bl, %r12d
shll $0x9, %r12d
leaq 0x65d858(%rip), %r9     # 0x6be1b0
addq %r9, %r12
movzwl (%r12,%r8,2), %r11d
movzwl (%r12,%r10,2), %r12d
testb %al, %al
je 0x609a8
movl %r11d, %eax
andl %edi, %eax
movzbl (%rcx,%rsi), %r9d
subl %r9d, %eax
addl $0x4, %eax
cmpl $0x7, %eax
ja 0x60998
movl %r12d, %eax
andl %edi, %eax
movq 0x38(%rsp), %r9
movzbl (%rcx,%r9), %r9d
subl %r9d, %eax
addl $0x4, %eax
cmpl $0x8, %eax
jb 0x609a8
movzwl (%rbp), %ebx
cmpw $-0x1, %bx
jne 0x6090e
jmp 0x609ec
movl %r11d, %r9d
shrl $0x8, %r9d
imull %r9d, %r9d
addl %r13d, %r9d
movl %r12d, %eax
shrl $0x8, %eax
imull %eax, %eax
addl %r9d, %eax
cmpl 0x8(%rsp), %eax
jae 0x60998
testl %eax, %eax
je 0x60a20
movl %r12d, 0x24(%rsp)
movl %r11d, 0x20(%rsp)
movl %ebx, 0x1c(%rsp)
movl %edx, %r9d
movq %r9, 0x80(%rsp)
movq %rax, 0x8(%rsp)
jmp 0x60998
movq 0x68(%rsp), %rax
incl %eax
movq 0x60(%rsp), %r9
jmp 0x608a2
movq 0x88(%rsp), %rdx
movq 0x10(%rsp), %rdi
movl 0x24(%rsp), %ebp
movq 0x80(%rsp), %rsi
movl 0x20(%rsp), %r13d
jmp 0x6084e
xorl %ecx, %ecx
movl %edx, %esi
movl %ebx, %eax
movl %r11d, %r13d
movl %r12d, %ebp
shll $0x3, %ecx
movq %rcx, 0x8(%rsp)
movl $0x8, 0x180(%rsp)
movl %eax, %ebx
notb %al
andb $0x1, %al
movb %al, 0x190(%rsp)
movl %ebx, %eax
shrl %eax
andl $0x7, %eax
movl %eax, 0x17c(%rsp)
movq 0x188(%rsp), %rax
shrb $0x4, %bl
andb $0x3, %bl
movzbl %bl, %ecx
movabsq $0x101010101010101, %rdx # imm = 0x101010101010101
imulq %rdx, %rcx
movq %rcx, (%rax)
leaq 0x178(%rsp), %r12
movq %r12, %rdi
movq %rsi, %r14
callq 0x61650
movb %bh, (%rax)
movl %r14d, %eax
leaq 0x10945(%rip), %rbx     # 0x713e0
movl (%rbx,%rax,4), %esi
movq %r12, %rdi
callq 0x61650
movb %r13b, (%rax)
incl %r14d
movl (%rbx,%r14,4), %esi
movq %r12, %rdi
callq 0x61650
movq 0x10(%rsp), %rdi
movb %bpl, (%rax)
movq 0x8(%rsp), %rax
movq %rax, 0x170(%rsp)
movq 0x78(%rsp), %rbx
movq 0x30(%rsp), %r14
testl %r15d, %r15d
setne %al
movb %r15b, 0xb0(%rsp)
movb $0x0, 0xc8(%rsp)
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x60b0d
movb $0x1, 0xc8(%rsp)
movl 0x128(%rsp), %eax
movl %eax, 0xc4(%rsp)
movl 0x98(%rsp), %edx
pushq $0x9
popq %rax
leaq 0x11122(%rip), %rcx     # 0x71c40
cmpl $0x2, %edx
je 0x60b3e
cmpl $0x1, %edx
jne 0x60b34
pushq $0x3
popq %rax
leaq 0x11132(%rip), %rcx     # 0x71c64
jmp 0x60b3e
pushq $0x1
popq %rax
leaq 0x11132(%rip), %rcx     # 0x71c70
movl %eax, 0xc0(%rsp)
movq %rcx, 0xb8(%rsp)
imulq $0x28, %rdi, %rax
leaq (%rsp,%rax), %rbp
addq $0x120, %rbp            # imm = 0x120
leaq 0x1b0(%rsp), %r12
movq %r12, %rdi
leaq 0x98(%rsp), %rsi
movq %rbp, %rdx
callq 0x5fe7c
movq %r12, %rdi
callq 0x5f2a4
testb %al, %al
je 0x60c68
movl 0x98(%rsp), %ecx
movq (%rbp), %rax
testl %ecx, %ecx
jle 0x60c25
cmpq $0xbb9, %rax            # imm = 0xBB9
jb 0x60bfb
cmpq $0x1771, %rax           # imm = 0x1771
pushq $0x2
popq %rax
pushq $0x8
popq %rdx
cmovael %edx, %eax
leaq 0x110d8(%rip), %rdx     # 0x71c90
leaq 0x110e1(%rip), %rsi     # 0x71ca0
cmovaeq %rsi, %rdx
cmpl $0x1, %ecx
pushq $0x4
popq %rcx
cmovel %ecx, %eax
leaq 0x110ad(%rip), %rcx     # 0x71c80
cmoveq %rcx, %rdx
movl %eax, 0xc0(%rsp)
movq %rdx, 0xb8(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x5f2a4
testb %al, %al
je 0x60c68
movq (%rbp), %rax
movq 0x10(%rsp), %rdi
cmpq %rax, 0x170(%rsp)
jae 0x60c2a
movq %rbp, %rdi
leaq 0x170(%rsp), %rsi
callq 0x615fa
movq 0x10(%rsp), %rdi
movq (%rbp), %rax
jmp 0x60c2a
movq 0x10(%rsp), %rdi
movq 0x90(%rsp), %rcx
addq %rax, %rcx
incq %rdi
cmpq %rbx, %rcx
movl 0x4(%rsp), %eax
jb 0x60743
jmp 0x60cab
movq 0x8(%rsp), %rcx
cmpl $-0x1, %ecx
movq 0x78(%rsp), %rbx
movq 0x30(%rsp), %r14
movl 0x1c(%rsp), %eax
jne 0x60a2c
jmp 0x60ad7
movl 0x4(%rsp), %eax
jmp 0x60cab
leaq 0xd0(%rsp), %rdi
leaq 0x120(%rsp), %rsi
movq %rcx, %rbx
callq 0x615fa
leaq 0xf8(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x615fa
movl %r15d, %eax
movq %rax, 0x70(%rsp)
movl 0x4(%rsp), %eax
movl %eax, 0x18(%rsp)
incl %r15d
jmp 0x60730
incl %eax
jmp 0x60720
movzbl 0x100(%rsp), %r8d
movzbl 0xd8(%rsp), %edi
movzbl 0x101(%rsp), %esi
movzbl 0xd9(%rsp), %edx
movzbl 0x102(%rsp), %ecx
movzbl 0xda(%rsp), %eax
movq 0x70(%rsp), %r10
testl %r10d, %r10d
je 0x60d18
shlb $0x4, %dil
orb %r8b, %dil
movq 0x28(%rsp), %r8
movb %dil, (%r8)
shlb $0x4, %dl
orb %sil, %dl
movq %r8, %rsi
movb %dl, 0x1(%r8)
shlb $0x4, %al
orb %cl, %al
jmp 0x60d8f
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 0x60fa3
cmpl %esi, %r8d
movl %esi, %r9d
cmovgl %r8d, %r9d
cmpl %ecx, %r9d
cmovlel %ecx, %r9d
cmpl $0x4, %r9d
jge 0x60fa3
movl %r8d, %r9d
shrl $0x1f, %r9d
leal (%r8,%r9,8), %r8d
shll $0x3, %edi
orl %r8d, %edi
movq 0x28(%rsp), %r8
movb %dil, (%r8)
movl %esi, %edi
shrl $0x1f, %edi
leal (%rsi,%rdi,8), %esi
shll $0x3, %edx
orl %esi, %edx
movq %r8, %rsi
movb %dl, 0x1(%r8)
movl %ecx, %edx
shrl $0x1f, %edx
leal (%rcx,%rdx,8), %ecx
shll $0x3, %eax
orl %ecx, %eax
movb %al, 0x2(%rsi)
movl 0xdc(%rsp), %eax
movl 0x104(%rsp), %ecx
shll $0x5, %eax
addl %r10d, %r10d
andl $0x2, %r10d
leal (%r10,%rcx,4), %ecx
orl %eax, %ecx
xorl $0x2, %ecx
movl 0x18(%rsp), %eax
orl %eax, %ecx
movb %cl, 0x3(%rsi)
testl %eax, %eax
je 0x60e95
movq %rbx, %r15
movq 0xe8(%rsp), %rdx
movq 0x110(%rsp), %rsi
xorl %ecx, %ecx
pushq $0x7
popq %rdi
leaq 0x10611(%rip), %r8      # 0x713f4
xorl %eax, %eax
leaq -0x4(%rdi), %r9
testl %r9d, %r9d
js 0x60e6d
movzbl (%rsi,%rdi), %r10d
movzbl (%r10,%r8), %r11d
movl %r9d, %ebx
movzbl (%rsi,%rbx), %r9d
movzbl (%r9,%r8), %r9d
addl %r11d, %r11d
movl %r11d, %r10d
andl $0x2, %r10d
leal (%r10,%rcx,4), %ecx
movl %r9d, %r14d
andl $0x1, %r14d
orl %ecx, %r14d
movzbl (%rdx,%rdi), %ecx
movzbl (%rcx,%r8), %r10d
shll $0x3, %eax
andl $-0x4, %r11d
orl %eax, %r11d
andl $-0x2, %r9d
orl %r11d, %r9d
movzbl (%rdx,%rbx), %eax
movzbl (%rax,%r8), %eax
shll $0x2, %r14d
movl %r10d, %ecx
andl $0x1, %ecx
leal (%r14,%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
jmp 0x60de5
movq %r15, %rbx
movq 0x28(%rsp), %rdx
movb %ah, 0x4(%rdx)
movb %al, 0x5(%rdx)
movb %ch, 0x6(%rdx)
movb %cl, 0x7(%rdx)
movl %ebx, %eax
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rdx
xorl %ecx, %ecx
pushq $0x7
popq %rsi
leaq 0x10550(%rip), %rdi     # 0x713f4
xorl %eax, %eax
testl %edx, %edx
js 0x60e70
movq %rbx, %r15
movl %edx, %r8d
imulq $0x28, %r8, %r8
movq 0xe8(%rsp,%r8), %r8
movq %rsi, %r9
cmpl $-0x1, %r9d
je 0x60f43
movzbl (%r8,%r9), %r10d
movzbl (%r10,%rdi), %ebx
movzbl -0x1(%r8,%r9), %r10d
movzbl (%r10,%rdi), %r10d
addl %ebx, %ebx
movl %ebx, %r11d
andl $0x2, %r11d
leal (%r11,%rcx,4), %ecx
movl %r10d, %r14d
andl $0x1, %r14d
orl %ecx, %r14d
movzbl -0x2(%r8,%r9), %ecx
movzbl (%rcx,%rdi), %r11d
shll $0x3, %eax
andl $-0x4, %ebx
andl $-0x2, %r10d
orl %eax, %r10d
orl %ebx, %r10d
movzbl -0x3(%r8,%r9), %eax
movzbl (%rax,%rdi), %eax
shll $0x2, %r14d
movl %r11d, %ecx
andl $0x1, %ecx
leal (%r14,%rcx,2), %ebx
movl %eax, %ecx
andl $0x1, %ecx
orl %ebx, %ecx
addl %r10d, %r10d
andl $-0x2, %r11d
shrl %eax
orl %r11d, %eax
orl %r10d, %eax
addq $-0x4, %r9
jmp 0x60ebf
decl %edx
movq %r15, %rbx
jmp 0x60ea6
shll $0x4, %r9d
movq %r9, %rbx
movl 0x38(%rsp), %edx
movl %ecx, %esi
movl %r8d, %r14d
movl %r15d, %r13d
jmp 0x60571
leaq 0x109e6(%rip), %rdi     # 0x71952
leaq 0x104bc(%rip), %rsi     # 0x7142f
leaq 0x10a53(%rip), %rcx     # 0x719cd
movl $0x7fb, %edx            # imm = 0x7FB
callq 0x61b0
leaq 0x109c7(%rip), %rdi     # 0x71952
leaq 0x1049d(%rip), %rsi     # 0x7142f
leaq 0x109d7(%rip), %rcx     # 0x71970
movl $0x7a2, %edx            # imm = 0x7A2
callq 0x61b0
leaq 0x10705(%rip), %rdi     # 0x716af
leaq 0x1047e(%rip), %rsi     # 0x7142f
leaq 0x10777(%rip), %rcx     # 0x7172f
movl $0x947, %edx            # imm = 0x947
callq 0x61b0