// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/libraries/libwebp/src/utils/rescaler_utils.c
// Function: WebPRescalerInit
int WebPRescalerInit(WebPRescaler* const rescaler,
                     int src_width, int src_height,
                     uint8_t* const dst,
                     int dst_width, int dst_height, int dst_stride,
                     int num_channels, rescaler_t* const work) {
  const int x_add = src_width, x_sub = dst_width;
  const int y_add = src_height, y_sub = dst_height;
  const uint64_t total_size = 2ull * dst_width * num_channels * sizeof(*work);
  if (!CheckSizeOverflow(total_size)) return 0;

  rescaler->x_expand = (src_width < dst_width);
  rescaler->y_expand = (src_height < dst_height);
  rescaler->src_width = src_width;
  rescaler->src_height = src_height;
  rescaler->dst_width = dst_width;
  rescaler->dst_height = dst_height;
  rescaler->src_y = 0;
  rescaler->dst_y = 0;
  rescaler->dst = dst;
  rescaler->dst_stride = dst_stride;
  rescaler->num_channels = num_channels;

  // for 'x_expand', we use bilinear interpolation
  rescaler->x_add = rescaler->x_expand ? (x_sub - 1) : x_add;
  rescaler->x_sub = rescaler->x_expand ? (x_add - 1) : x_sub;
  if (!rescaler->x_expand) {  // fx_scale is not used otherwise
    rescaler->fx_scale = WEBP_RESCALER_FRAC(1, rescaler->x_sub);
  }
  // vertical scaling parameters
  rescaler->y_add = rescaler->y_expand ? y_add - 1 : y_add;
  rescaler->y_sub = rescaler->y_expand ? y_sub - 1 : y_sub;
  rescaler->y_accum = rescaler->y_expand ? rescaler->y_sub : rescaler->y_add;
  if (!rescaler->y_expand) {
    // This is WEBP_RESCALER_FRAC(dst_height, x_add * y_add) without the cast.
    // Its value is <= WEBP_RESCALER_ONE, because dst_height <= rescaler->y_add
    // and rescaler->x_add >= 1;
    const uint64_t num = (uint64_t)dst_height * WEBP_RESCALER_ONE;
    const uint64_t den = (uint64_t)rescaler->x_add * rescaler->y_add;
    const uint64_t ratio = num / den;
    if (ratio != (uint32_t)ratio) {
      // When ratio == WEBP_RESCALER_ONE, we can't represent the ratio with the
      // current fixed-point precision. This happens when src_height ==
      // rescaler->y_add (which == src_height), and rescaler->x_add == 1.
      // => We special-case fxy_scale = 0, in WebPRescalerExportRow().
      rescaler->fxy_scale = 0;
    } else {
      rescaler->fxy_scale = (uint32_t)ratio;
    }
    rescaler->fy_scale = WEBP_RESCALER_FRAC(1, rescaler->y_sub);
  } else {
    rescaler->fy_scale = WEBP_RESCALER_FRAC(1, rescaler->x_add);
    // rescaler->fxy_scale is unused here.
  }
  rescaler->irow = work;
  rescaler->frow = work + num_channels * dst_width;
  memset(work, 0, (size_t)total_size);

  WebPRescalerDspInit();
  return 1;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %edx, %r10d
movl 0x28(%rsp), %r11d
movl 0x20(%rsp), %edx
xorl %ebp, %ebp
cmpl %r9d, %r10d
setl %bpl
leal -0x1(%r8), %ebx
leal -0x1(%rsi), %eax
xorl %r14d, %r14d
cmpl %r8d, %esi
setl %r14b
movl %r14d, (%rdi)
movl %ebp, 0x4(%rdi)
movl %esi, 0x2c(%rdi)
movl %r10d, 0x30(%rdi)
movl %r8d, 0x34(%rdi)
movl %r9d, 0x38(%rdi)
movq $0x0, 0x3c(%rdi)
movq %rcx, 0x48(%rdi)
movl %edx, 0x50(%rdi)
movl %r11d, 0x8(%rdi)
cmovgel %esi, %ebx
movl %ebx, 0x24(%rdi)
cmovgel %r8d, %eax
movl %eax, 0x28(%rdi)
jl 0xcf716
movslq %eax, %rcx
movabsq $0x100000000, %rax      # imm = 0x100000000
xorl %edx, %edx
divq %rcx
movl %eax, 0xc(%rdi)
movq 0x30(%rsp), %rcx
xorl %edx, %edx
cmpl %r9d, %r10d
setl %dl
movl %r10d, %eax
subl %edx, %eax
movl %r9d, %esi
subl %edx, %esi
movl %eax, 0x1c(%rdi)
movl %esi, 0x20(%rdi)
cmpl %r9d, %r10d
cmovll %esi, %r10d
movl %r10d, 0x18(%rdi)
jge 0xcf744
movl %ebx, %esi
jmp 0xcf76f
movabsq $0x100000000, %r10      # imm = 0x100000000
shlq $0x20, %r9
movslq %ebx, %rdx
movslq %eax, %rbx
imulq %rdx, %rbx
movq %r9, %rax
xorl %edx, %edx
divq %rbx
cmpq %r10, %rax
cmovbq %rax, %r10
movl %r10d, 0x14(%rdi)
movslq %esi, %rsi
movabsq $0x100000000, %rax      # imm = 0x100000000
xorl %edx, %edx
divq %rsi
movl %eax, 0x10(%rdi)
movslq %r8d, %rax
movslq %r11d, %rdx
imulq %rax, %rdx
shlq $0x3, %rdx
movq %rcx, 0x58(%rdi)
imull %r8d, %r11d
movslq %r11d, %rax
leaq (%rcx,%rax,4), %rax
movq %rax, 0x60(%rdi)
movq %rcx, %rdi
xorl %esi, %esi
callq 0x55f20
callq 0xdcccd
movl $0x1, %eax
popq %rbx
popq %r14
popq %rbp
retq