// File: /workspace/github_c_makefile_star2_O3/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
xorl %r14d, %r14d
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x55f20
leaq 0x400(%rsp), %rdi
movl $0x1000, %edx           # imm = 0x1000
xorl %esi, %esi
callq 0x55f20
cmpl $0x0, (%r15)
je 0xf0bc3
movl 0xc(%r15), %eax
testl %eax, %eax
jle 0xf0b68
movq 0x48(%r15), %rcx
movl 0x8(%r15), %edx
movl (%rcx), %r9d
notl %r9d
xorl %r14d, %r14d
xorl %esi, %esi
testl %edx, %edx
jle 0xf0b54
xorl %r8d, %r8d
movl (%rcx,%r8,4), %edi
cmpl %r9d, %edi
jne 0xf0b06
movl %r9d, %edi
jmp 0xf0b47
imull $0x1e35a7bd, %edi, %r9d # imm = 0x1E35A7BD
shrl $0x16, %r9d
cmpb $0x0, (%rsp,%r9)
je 0xf0b2e
cmpl %edi, 0x400(%rsp,%r9,4)
je 0xf0b47
incl %r9d
andl $0x3ff, %r9d            # imm = 0x3FF
jmp 0xf0b11
movl %edi, 0x400(%rsp,%r9,4)
movb $0x1, (%rsp,%r9)
cmpl $0xff, %r14d
jg 0xf0bad
incl %r14d
incq %r8
movl %edi, %r9d
cmpq %rdx, %r8
jne 0xf0af8
jmp 0xf0b57
movl %r9d, %edi
movslq 0x50(%r15), %r8
leaq (%rcx,%r8,4), %rcx
incl %esi
movl %edi, %r9d
cmpl %eax, %esi
jne 0xf0af1
testq %rbx, %rbx
je 0xf0bb3
xorl %eax, %eax
xorl %r14d, %r14d
cmpb $0x0, (%rsp,%rax)
je 0xf0b89
movl 0x400(%rsp,%rax,4), %ecx
movslq %r14d, %r14
movl %ecx, (%rbx,%r14,4)
incl %r14d
incq %rax
cmpq $0x400, %rax            # imm = 0x400
jne 0xf0b72
movslq %r14d, %rsi
leaq -0x140(%rip), %rcx      # 0xf0a5e
movl $0x4, %edx
movq %rbx, %rdi
callq 0x57590
jmp 0xf0bb3
movl $0x101, %r14d           # imm = 0x101
movl %r14d, %eax
addq $0x1400, %rsp           # imm = 0x1400
popq %rbx
popq %r14
popq %r15
retq
leaq 0x3d2b2(%rip), %rdi     # 0x12de7c
leaq 0x3d258(%rip), %rsi     # 0x12de29
leaq 0x3d265(%rip), %rcx     # 0x12de3d
movl $0x6a, %edx
callq 0x55710