// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x1450, %rsp           # imm = 0x1450
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x28(%rbp)
leaq -0x430(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x5a200
leaq -0x1430(%rbp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x5a200
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x1438(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x143c(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x1440(%rbp)
movq -0x1438(%rbp), %rax
movl (%rax), %eax
xorl $-0x1, %eax
movl %eax, -0x1444(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x183524
jmp 0x183543
leaq 0x3e2b1(%rip), %rdi     # 0x1c17dc
leaq 0x3e2b6(%rip), %rsi     # 0x1c17e8
movl $0x69, %edx
leaq 0x3e2be(%rip), %rcx     # 0x1c17fc
callq 0x598a0
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x18354e
jmp 0x18356d
leaq 0x3e2e6(%rip), %rdi     # 0x1c183b
leaq 0x3e28c(%rip), %rsi     # 0x1c17e8
movl $0x6a, %edx
leaq 0x3e294(%rip), %rcx     # 0x1c17fc
callq 0x598a0
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x1440(%rbp), %eax
jge 0x1836ae
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x143c(%rbp), %eax
jge 0x183681
movq -0x1438(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x1444(%rbp), %eax
jne 0x1835b4
jmp 0x183673
movq -0x1438(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x1444(%rbp)
movl -0x1444(%rbp), %edi
movl $0x16, %esi
callq 0x183740
movl %eax, -0x1448(%rbp)
movslq -0x1448(%rbp), %rax
cmpb $0x0, -0x430(%rbp,%rax)
jne 0x183632
movl -0x1444(%rbp), %ecx
movslq -0x1448(%rbp), %rax
movl %ecx, -0x1430(%rbp,%rax,4)
movslq -0x1448(%rbp), %rax
movb $0x1, -0x430(%rbp,%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
cmpl $0x100, -0x28(%rbp)     # imm = 0x100
jle 0x183630
movl $0x101, -0x4(%rbp)      # imm = 0x101
jmp 0x183725
jmp 0x183671
movslq -0x1448(%rbp), %rax
movl -0x1430(%rbp,%rax,4), %eax
cmpl -0x1444(%rbp), %eax
jne 0x18364a
jmp 0x183671
movl -0x1448(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1448(%rbp)
movl -0x1448(%rbp), %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, -0x1448(%rbp)
jmp 0x18366c
jmp 0x1835de
jmp 0x183673
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x18358a
movq -0x10(%rbp), %rax
movl 0x50(%rax), %ecx
movq -0x1438(%rbp), %rax
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x1438(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x183574
cmpq $0x0, -0x18(%rbp)
je 0x18371f
movl $0x0, -0x28(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x400, -0x1c(%rbp)     # imm = 0x400
jge 0x183706
movslq -0x1c(%rbp), %rax
cmpb $0x0, -0x430(%rbp,%rax)
je 0x1836f9
movslq -0x1c(%rbp), %rax
movl -0x1430(%rbp,%rax,4), %edx
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1836fb
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1836c3
movq -0x18(%rbp), %rdi
movslq -0x28(%rbp), %rsi
movl $0x4, %edx
leaq -0x2ea(%rip), %rcx      # 0x183430
callq 0x5bcb0
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1450, %rsp           # imm = 0x1450
popq %rbp
retq
nopw %cs:(%rax,%rax)