// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/libraries/libwebp/src/utils/palette.c
// Function: PaletteSort
int PaletteSort(PaletteSorting method, const struct WebPPicture* const pic,
                const uint32_t* const palette_sorted, uint32_t num_colors,
                uint32_t* const palette) {
  switch (method) {
    case kSortedDefault:
      // Nothing to do, we have already sorted the palette.
      memcpy(palette, palette_sorted, num_colors * sizeof(*palette));
      return 1;
    case kMinimizeDelta:
      PaletteSortMinimizeDeltas(palette_sorted, num_colors, palette);
      return 1;
    case kModifiedZeng:
      return PaletteSortModifiedZeng(pic, palette_sorted, num_colors, palette);
    case kUnusedPalette:
    case kPaletteSortingNum:
      break;
  }

  assert(0);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc48, %rsp            # imm = 0xC48
movq %r8, 0x20(%rsp)
movl %ecx, %r12d
movq %rdx, 0x10(%rsp)
movl %ecx, %eax
movq %rax, 0x8(%rsp)
pushq $0x1
popq %rbx
cmpl $0x2, %edi
je 0xe175a
cmpl $0x1, %edi
je 0xe15d3
testl %edi, %edi
jne 0xe1b35
movq 0x8(%rsp), %rdx
shlq $0x2, %rdx
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x562f0
jmp 0xe1ad9
movslq %r12d, %rdx
shlq $0x2, %rdx
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x562f0
xorl %r14d, %r14d
testl %r12d, %r12d
cmovlel %r14d, %r12d
movq %r12, (%rsp)
movl $0xff, %ebp
movl $0x80, %r15d
pushq $0x40
popq %r12
xorl %r13d, %r13d
xorl %esi, %esi
cmpq %r14, (%rsp)
je 0xe167a
movq 0x10(%rsp), %rax
movl (%rax,%r14,4), %ebx
movl %ebx, %edi
callq 0xe1b92
movl %eax, %ecx
shrl $0x10, %ecx
movl %eax, %edx
shrl $0x8, %edx
andl %ebp, %ecx
cmpl %r15d, %ecx
movb $0x2, %sil
sbbb $0x0, %sil
testl %ecx, %ecx
movzbl %sil, %esi
cmovel %ecx, %esi
andl %ebp, %edx
cmpl $0x7f, %edx
seta %cl
shlb $0x3, %cl
addb $0x8, %cl
testl %edx, %edx
movzbl %cl, %ecx
cmovel %edx, %ecx
andl %ebp, %eax
cmpl %r15d, %eax
movl $0x80, %edx
cmovbl %r12d, %edx
testl %eax, %eax
cmovel %eax, %edx
orl %esi, %edx
orl %ecx, %edx
orb %r13b, %dl
incq %r14
movl %edx, %r13d
movl %ebx, %esi
jmp 0xe160b
leal (,%r13,2), %eax
testb %r13b, %al
je 0xe1752
xorl %esi, %esi
movl $0xff, %r15d
movl $0x81, %r12d
xorl %ebx, %ebx
cmpq (%rsp), %rsi
je 0xe1752
movq %rsi, %r14
movq %rsi, 0x18(%rsp)
movl %esi, %r13d
pushq $-0x1
popq %rbp
cmpq %r14, 0x8(%rsp)
je 0xe1731
movq 0x20(%rsp), %rax
movl (%rax,%r14,4), %edi
movl %ebx, %esi
callq 0xe1b92
movl %eax, %ecx
andl %r15d, %ecx
movl $0x100, %edx            # imm = 0x100
subl %ecx, %edx
cmpl %r12d, %ecx
cmovbl %ecx, %edx
movl %eax, %ecx
shrl $0x8, %ecx
andl %r15d, %ecx
movl $0x100, %esi            # imm = 0x100
subl %ecx, %esi
cmpl %r12d, %ecx
cmovbl %ecx, %esi
addl %edx, %esi
movl %eax, %ecx
shrl $0x10, %ecx
andl %r15d, %ecx
movl $0x100, %edx            # imm = 0x100
subl %ecx, %edx
cmpl %r12d, %ecx
cmovbl %ecx, %edx
addl %esi, %edx
leal (%rdx,%rdx,8), %ecx
movl %eax, %edx
shrl $0x18, %edx
movl $0x100, %esi            # imm = 0x100
subl %edx, %esi
cmpl $0x81000000, %eax       # imm = 0x81000000
cmovbl %edx, %esi
addl %ecx, %esi
cmpl %esi, %ebp
cmoval %r14d, %r13d
cmovael %esi, %ebp
incq %r14
jmp 0xe16b3
movslq %r13d, %rax
movq 0x20(%rsp), %rdx
movl (%rdx,%rax,4), %ebx
movq 0x18(%rsp), %rsi
movl (%rdx,%rsi,4), %ecx
movl %ecx, (%rdx,%rax,4)
movl %ebx, (%rdx,%rsi,4)
incq %rsi
jmp 0xe169b
pushq $0x1
popq %rbx
jmp 0xe1ad9
cmpl $0x2, %r12d
jb 0xe1ad9
movq %rsi, 0x30(%rsp)
movl %r12d, %edi
imull %edi, %edi
pushq $0x4
popq %rsi
callq 0x57690
testq %rax, %rax
je 0xe1ad7
movq %rax, %rbp
movq 0x30(%rsp), %r13
movq 0x48(%r13), %rax
movq %rax, 0x38(%rsp)
movl (%rax), %r14d
leaq 0x440(%rsp), %rdi
xorl %r15d, %r15d
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x56ff0
movslq 0x8(%r13), %rdi
addq %rdi, %rdi
pushq $0x4
popq %rsi
callq 0x57c90
testq %rax, %rax
je 0xe1acf
notl %r14d
movslq 0x8(%r13), %rcx
leaq (%rax,%rcx,4), %rbx
leaq 0x40(%rsp), %rdx
leaq 0x440(%rsp), %rcx
movq %rax, 0x28(%rsp)
movq 0x10(%rsp), %rdi
movq %r12, (%rsp)
movl %r12d, %esi
movq %rcx, %r12
callq 0xe13a0
xorl %eax, %eax
movq 0x28(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq %r13, %rdi
movq 0x38(%rsp), %r8
cmpl 0xc(%rdi), %r15d
jge 0xe18d4
movq %rbx, %r13
xorl %r12d, %r12d
movslq 0x8(%rdi), %rcx
cmpq %rcx, %r12
jge 0xe18b2
movl (%r8,%r12,4), %ebx
cmpl %r14d, %ebx
je 0xe1855
leaq 0x40(%rsp), %rdi
movl %ebx, %esi
movq (%rsp), %rdx
movq %r8, %r14
callq 0xe137c
movq %r14, %r8
movq 0x30(%rsp), %rdi
cltq
movl 0x440(%rsp,%rax,4), %eax
movl %ebx, %r14d
movl %eax, (%r13,%r12,4)
testq %r12, %r12
je 0xe1880
movl -0x4(%r13,%r12,4), %ecx
cmpl %ecx, %eax
je 0xe1880
movl %eax, %edx
movq (%rsp), %rsi
imull %esi, %edx
addl %ecx, %edx
incl (%rbp,%rdx,4)
imull %esi, %ecx
addl %eax, %ecx
incl (%rbp,%rcx,4)
testl %r15d, %r15d
je 0xe18aa
movq 0x18(%rsp), %rcx
movl (%rcx,%r12,4), %ecx
cmpl %ecx, %eax
je 0xe18aa
movl %eax, %edx
movq (%rsp), %rsi
imull %esi, %edx
addl %ecx, %edx
incl (%rbp,%rdx,4)
imull %esi, %ecx
addl %eax, %ecx
incl (%rbp,%rcx,4)
incq %r12
jmp 0xe1818
movslq 0x50(%rdi), %rcx
leaq (%r8,%rcx,4), %r8
incl %r15d
movq 0x18(%rsp), %rbx
movq %r13, 0x18(%rsp)
leaq 0x440(%rsp), %r12
jmp 0xe1808
movq 0x28(%rsp), %rdi
callq 0x58480
xorl %ecx, %ecx
xorl %esi, %esi
xorl %edx, %edx
xorl %edi, %edi
movq (%rsp), %r13
movzbl %sil, %eax
cmpl %r13d, %edi
je 0xe1921
xorl %esi, %esi
movq 0x8(%rsp), %r8
movl %ecx, %r9d
subq $0x1, %r8
jb 0xe1910
movl %r9d, %r10d
addl (%rbp,%r10,4), %esi
incl %r9d
jmp 0xe18fd
cmpl %edx, %esi
cmoval %edi, %eax
cmoval %esi, %edx
incl %edi
addl %r13d, %ecx
movl %eax, %esi
jmp 0xe18ea
movb %al, 0x40(%rsp)
movl %eax, %edx
imull %r13d, %edx
xorl %edi, %edi
xorl %r10d, %r10d
xorl %r8d, %r8d
xorl %r9d, %r9d
movzbl %r10b, %ecx
cmpq %rdi, 0x8(%rsp)
je 0xe1964
leal (%rdx,%rdi), %r10d
movl (%rbp,%r10,4), %r10d
cmpl %r9d, %r10d
cmoval %edi, %ecx
movzbl %r8b, %r8d
cmoval %edi, %r8d
cmoval %r10d, %r9d
incq %rdi
movl %ecx, %r10d
jmp 0xe1936
movb %r10b, 0x41(%rsp)
cmpb %r8b, %sil
je 0xe1b54
movl %r13d, %edx
addl $-0x2, %edx
je 0xe1aed
movb $0x0, 0x440(%rsp)
andl $0x0, 0x444(%rsp)
movzbl %sil, %esi
xorl %edi, %edi
movl %ecx, %r8d
xorl %r9d, %r9d
cmpq %rdi, 0x8(%rsp)
je 0xe19ed
cmpq %rdi, %rsi
je 0xe19e2
cmpq %rdi, %rcx
je 0xe19e2
movl %r9d, %r10d
movb %dil, 0x440(%rsp,%r10,8)
movl %eax, %r11d
movl %r8d, %ebx
movl (%rbp,%rbx,4), %ebx
addl (%rbp,%r11,4), %ebx
movl %ebx, 0x444(%rsp,%r10,8)
cmpl 0x4(%r12), %ebx
jbe 0xe19df
leaq (%rsp,%r10,8), %r12
addq $0x440, %r12            # imm = 0x440
incl %r9d
incq %rdi
addl %r13d, %r8d
addl %r13d, %eax
jmp 0xe199a
movl %edx, %edi
leal -0x3(%r13), %r8d
xorl %ebx, %ebx
pushq $0x1
popq %r9
movl %r9d, %ecx
subq $0x1, %rdi
jb 0xe1acb
movl %r8d, %r8d
movq %r12, %r10
movzbl (%r12), %r12d
leal 0x1(%rcx), %r11d
movl %r12d, %r14d
imull %r13d, %r14d
xorl %r15d, %r15d
movl %ebx, %esi
movl %r9d, %r13d
movl %esi, %eax
xorl %edx, %edx
divl (%rsp)
cmpl %r11d, %edx
je 0xe1a4d
movl %edx, %eax
movzbl 0x40(%rsp,%rax), %eax
addl %r14d, %eax
movl (%rbp,%rax,4), %eax
imull %r13d, %eax
addl %eax, %r15d
addl $-0x2, %r13d
incl %esi
jmp 0xe1a24
testl %ebx, %ebx
movl %ebx, %eax
cmovel 0x8(%rsp), %eax
decl %eax
testl %r15d, %r15d
movl %r11d, %edx
cmovgl %eax, %edx
cmovgl %eax, %ebx
movb %r12b, 0x40(%rsp,%rdx)
movl %edi, %eax
movq 0x440(%rsp,%rax,8), %rax
movq %rax, (%r10)
leaq 0x440(%rsp), %r12
movq %r12, %rax
movq %r8, %rdx
movq (%rsp), %r13
subq $0x1, %rdx
jb 0xe1ab9
movzbl (%rax), %esi
addl %r14d, %esi
movq %r12, %r10
movl 0x4(%rax), %r12d
addl (%rbp,%rsi,4), %r12d
movl %r12d, 0x4(%rax)
movq %rax, %rsi
cmpl 0x4(%r10), %r12d
ja 0xe1ab0
movq %r10, %rsi
addq $0x8, %rax
movq %rsi, %r12
jmp 0xe1a88
testl %r15d, %r15d
cmovlel %r11d, %ecx
decl %r8d
incl %r9d
jmp 0xe19fc
incl %ecx
jmp 0xe1af2
movq %rbp, %rdi
callq 0x58480
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xc48, %rsp            # imm = 0xC48
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
pushq $0x2
popq %rcx
movl %ecx, %eax
xorl %edx, %edx
divl %r13d
cmpl %ebx, %edx
jne 0xe1b73
movq %rbp, %rdi
callq 0x58480
movl %ebx, %ecx
xorl %esi, %esi
pushq $0x1
popq %rbx
cmpq %rsi, 0x8(%rsp)
je 0xe1ad9
leal (%rcx,%rsi), %eax
xorl %edx, %edx
divl %r13d
movzbl 0x40(%rsp,%rdx), %eax
movq 0x10(%rsp), %rdx
movl (%rdx,%rax,4), %eax
movq 0x20(%rsp), %rdx
movl %eax, (%rdx,%rsi,4)
incq %rsi
jmp 0xe1b0c
leaq 0x3a4ee(%rip), %rdi     # 0x11c02a
leaq 0x3c014(%rip), %rsi     # 0x11db57
leaq 0x3c06e(%rip), %rcx     # 0x11dbb8
movl $0x190, %edx            # imm = 0x190
callq 0x56770
leaq 0x3c19d(%rip), %rdi     # 0x11dcf8
leaq 0x3bff5(%rip), %rsi     # 0x11db57
leaq 0x3c19a(%rip), %rcx     # 0x11dd03
movl $0xf0, %edx
callq 0x56770
leaq 0x3c0f5(%rip), %rdi     # 0x11dc6f
leaq 0x3bfd6(%rip), %rsi     # 0x11db57
leaq 0x3c108(%rip), %rcx     # 0x11dc90
movl $0x172, %edx            # imm = 0x172
callq 0x56770