// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/libraries/libwebp/src/utils/palette.c
// Function: CoOccurrenceBuild
static int CoOccurrenceBuild(const WebPPicture* const pic,
                             const uint32_t* const palette, uint32_t num_colors,
                             uint32_t* cooccurrence) {
  uint32_t *lines, *line_top, *line_current, *line_tmp;
  int x, y;
  const uint32_t* src = pic->argb;
  uint32_t prev_pix = ~src[0];
  uint32_t prev_idx = 0u;
  uint32_t idx_map[MAX_PALETTE_SIZE] = {0};
  uint32_t palette_sorted[MAX_PALETTE_SIZE];
  lines = (uint32_t*)WebPSafeMalloc(2 * pic->width, sizeof(*lines));
  if (lines == NULL) {
    return 0;
  }
  line_top = &lines[0];
  line_current = &lines[pic->width];
  PrepareMapToPalette(palette, num_colors, palette_sorted, idx_map);
  for (y = 0; y < pic->height; ++y) {
    for (x = 0; x < pic->width; ++x) {
      const uint32_t pix = src[x];
      if (pix != prev_pix) {
        prev_idx = idx_map[SearchColorNoIdx(palette_sorted, pix, num_colors)];
        prev_pix = pix;
      }
      line_current[x] = prev_idx;
      // 4-connectivity is what works best as mentioned in "On the relation
      // between Memon's and the modified Zeng's palette reordering methods".
      if (x > 0 && prev_idx != line_current[x - 1]) {
        const uint32_t left_idx = line_current[x - 1];
        ++cooccurrence[prev_idx * num_colors + left_idx];
        ++cooccurrence[left_idx * num_colors + prev_idx];
      }
      if (y > 0 && prev_idx != line_top[x]) {
        const uint32_t top_idx = line_top[x];
        ++cooccurrence[prev_idx * num_colors + top_idx];
        ++cooccurrence[top_idx * num_colors + prev_idx];
      }
    }
    line_tmp = line_top;
    line_top = line_current;
    line_current = line_tmp;
    src += pic->argb_stride;
  }
  WebPSafeFree(lines);
  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x870, %rsp            # imm = 0x870
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl (%rax), %eax
xorl $-0x1, %eax
movl %eax, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
leaq -0x460(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x5a200
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
shll %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x5b060
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x1840a9
movl $0x0, -0x4(%rbp)
jmp 0x18428b
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x8(%rcx), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0x860(%rbp), %rdx
leaq -0x460(%rbp), %rcx
callq 0x183390
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x18427b
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x18423c
movq -0x58(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x864(%rbp)
movl -0x864(%rbp), %eax
cmpl -0x5c(%rbp), %eax
je 0x184156
leaq -0x860(%rbp), %rdi
movl -0x864(%rbp), %esi
movl -0x1c(%rbp), %edx
callq 0x183310
cltq
movl -0x460(%rbp,%rax,4), %eax
movl %eax, -0x60(%rbp)
movl -0x864(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x60(%rbp), %edx
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
cmpl $0x0, -0x4c(%rbp)
jle 0x1841cd
movl -0x60(%rbp), %eax
movq -0x40(%rbp), %rcx
movl -0x4c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x1841cd
movq -0x40(%rbp), %rax
movl -0x4c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x868(%rbp)
movq -0x28(%rbp), %rax
movl -0x60(%rbp), %ecx
imull -0x1c(%rbp), %ecx
addl -0x868(%rbp), %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movl -0x868(%rbp), %ecx
imull -0x1c(%rbp), %ecx
addl -0x60(%rbp), %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
cmpl $0x0, -0x50(%rbp)
jle 0x18422c
movl -0x60(%rbp), %eax
movq -0x38(%rbp), %rcx
movslq -0x4c(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
je 0x18422c
movq -0x38(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x86c(%rbp)
movq -0x28(%rbp), %rax
movl -0x60(%rbp), %ecx
imull -0x1c(%rbp), %ecx
addl -0x86c(%rbp), %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movl -0x86c(%rbp), %ecx
imull -0x1c(%rbp), %ecx
addl -0x60(%rbp), %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x18422e
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x184100
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0x50(%rax), %ecx
movq -0x58(%rbp), %rax
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x1840e9
movq -0x30(%rbp), %rdi
callq 0x5b920
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x870, %rsp            # imm = 0x870
popq %rbp
retq
nopw (%rax,%rax)