// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/libraries/libwebp/src/utils/palette.c
// Function: GetColorPalette
int GetColorPalette(const WebPPicture* const pic, uint32_t* const palette) {
  int i;
  int x, y;
  int num_colors = 0;
  uint8_t in_use[COLOR_HASH_SIZE] = {0};
  uint32_t colors[COLOR_HASH_SIZE] = {0};
  const uint32_t* argb = pic->argb;
  const int width = pic->width;
  const int height = pic->height;
  uint32_t last_pix = ~argb[0];  // so we're sure that last_pix != argb[0]
  assert(pic != NULL);
  assert(pic->use_argb);

  for (y = 0; y < height; ++y) {
    for (x = 0; x < width; ++x) {
      int key;
      if (argb[x] == last_pix) {
        continue;
      }
      last_pix = argb[x];
      key = VP8LHashPix(last_pix, COLOR_HASH_RIGHT_SHIFT);
      while (1) {
        if (!in_use[key]) {
          colors[key] = last_pix;
          in_use[key] = 1;
          ++num_colors;
          if (num_colors > MAX_PALETTE_SIZE) {
            return MAX_PALETTE_SIZE + 1;  // Exact count not needed.
          }
          break;
        } else if (colors[key] == last_pix) {
          break;  // The color is already there.
        } else {
          // Some other color sits here, so do linear conflict resolution.
          ++key;
          key &= (COLOR_HASH_SIZE - 1);  // Key mask.
        }
      }
    }
    argb += pic->argb_stride;
  }

  if (palette != NULL) {  // Fill the colors into palette.
    num_colors = 0;
    for (i = 0; i < COLOR_HASH_SIZE; ++i) {
      if (in_use[i]) {
        palette[num_colors] = colors[i];
        ++num_colors;
      }
    }
    qsort(palette, num_colors, sizeof(*palette), PaletteCompareColorsForQsort);
  }
  return num_colors;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x1400, %rsp           # imm = 0x1400
movq %rsi, %rbx
movq %rdi, %r15
movq %rsp, %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x55f20
leaq 0x400(%rsp), %rdi
movl $0x1000, %edx           # imm = 0x1000
xorl %esi, %esi
callq 0x55f20
testq %r15, %r15
je 0xf18dc
cmpl $0x0, (%r15)
je 0xf18fb
movl 0xc(%r15), %eax
testl %eax, %eax
jle 0xf1886
movl 0x8(%r15), %ecx
movq 0x48(%r15), %rdx
movl (%rdx), %r8d
notl %r8d
xorl %r14d, %r14d
xorl %esi, %esi
testl %ecx, %ecx
jle 0xf186a
xorl %edi, %edi
movl (%rdx,%rdi,4), %r9d
movl $0x7, %r10d
cmpl %r8d, %r9d
je 0xf1857
imull $0x1e35a7bd, %r9d, %r8d # imm = 0x1E35A7BD
shrl $0x16, %r8d
cmpb $0x0, (%rsp,%r8)
je 0xf182d
cmpl %r9d, 0x400(%rsp,%r8,4)
je 0xf1851
incl %r8d
andl $0x3ff, %r8d            # imm = 0x3FF
jmp 0xf1810
movl %r9d, 0x400(%rsp,%r8,4)
movb $0x1, (%rsp,%r8)
xorl %r10d, %r10d
cmpl $0x100, %r14d           # imm = 0x100
leal 0x1(%r14), %r8d
setge %r10b
movl %r8d, %r14d
jmp 0xf1854
xorl %r10d, %r10d
movl %r9d, %r8d
cmpl $0x7, %r10d
je 0xf1862
testl %r10d, %r10d
jne 0xf187e
incq %rdi
cmpq %rcx, %rdi
jne 0xf17f6
movslq 0x50(%r15), %rdi
leaq (%rdx,%rdi,4), %rdx
incl %esi
cmpl %eax, %esi
jne 0xf17f0
jmp 0xf1889
movl $0x101, %r14d           # imm = 0x101
jmp 0xf18cc
xorl %r14d, %r14d
testq %rbx, %rbx
je 0xf18cc
xorl %eax, %eax
xorl %r14d, %r14d
cmpb $0x0, (%rsp,%rax)
je 0xf18aa
movl 0x400(%rsp,%rax,4), %ecx
movslq %r14d, %r14
movl %ecx, (%rbx,%r14,4)
incl %r14d
incq %rax
cmpq $0x400, %rax            # imm = 0x400
jne 0xf1893
movslq %r14d, %rsi
leaq -0x168(%rip), %rcx      # 0xf1757
movl $0x4, %edx
movq %rbx, %rdi
callq 0x57590
movl %r14d, %eax
addq $0x1400, %rsp           # imm = 0x1400
popq %rbx
popq %r14
popq %r15
retq
leaq 0x3d312(%rip), %rdi     # 0x12ebf5
leaq 0x3d317(%rip), %rsi     # 0x12ec01
leaq 0x3d324(%rip), %rcx     # 0x12ec15
movl $0x69, %edx
callq 0x55710
leaq 0x3d352(%rip), %rdi     # 0x12ec54
leaq 0x3d2f8(%rip), %rsi     # 0x12ec01
leaq 0x3d305(%rip), %rcx     # 0x12ec15
movl $0x6a, %edx
callq 0x55710