// File: /workspace/github_c_makefile_star2_O2/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), %eax
xorl %edx, %edx
cmpl %r9d, %r10d
setl %dl
andq $0x0, 0x3c(%rdi)
leal -0x1(%r8), %ebp
xorl %r14d, %r14d
movslq %r8d, %rbx
cmpl %r8d, %esi
setl %r14b
movl %r14d, (%rdi)
leal -0x1(%rsi), %r14d
movl %edx, 0x4(%rdi)
movl %esi, 0x2c(%rdi)
movl %r10d, 0x30(%rdi)
movl %r8d, 0x34(%rdi)
movl %r9d, 0x38(%rdi)
movq %rcx, 0x48(%rdi)
movl %eax, 0x50(%rdi)
movl %r11d, 0x8(%rdi)
cmovgel %esi, %ebp
movl %ebp, 0x24(%rdi)
cmovgel %r8d, %r14d
movl %r14d, 0x28(%rdi)
jl 0xc7944
movabsq $0x100000000, %rax      # imm = 0x100000000
xorl %edx, %edx
divq %rbx
movl %eax, 0xc(%rdi)
movq 0x30(%rsp), %rsi
xorl %edx, %edx
cmpl %r9d, %r10d
setl %dl
movl %r10d, %eax
subl %edx, %eax
movl %r9d, %ecx
subl %edx, %ecx
movl %eax, 0x1c(%rdi)
movl %ecx, 0x20(%rdi)
cmpl %r9d, %r10d
jge 0xc796d
movl %ecx, 0x18(%rdi)
movl %ebp, %ecx
jmp 0xc799b
movabsq $0x100000000, %r8       # imm = 0x100000000
movl %eax, 0x18(%rdi)
shlq $0x20, %r9
movslq %ebp, %rdx
movslq %eax, %r10
imulq %rdx, %r10
movq %r9, %rax
xorl %edx, %edx
divq %r10
cmpq %r8, %rax
cmovbq %rax, %r8
movl %r8d, 0x14(%rdi)
movslq %ecx, %rcx
movabsq $0x100000000, %rax      # imm = 0x100000000
xorl %edx, %edx
divq %rcx
movl %eax, 0x10(%rdi)
movslq %r11d, %rdx
imulq %rbx, %rdx
shlq $0x3, %rdx
movq %rsi, 0x58(%rdi)
imull %r11d, %ebx
movslq %ebx, %rax
leaq (%rsi,%rax,4), %rax
movq %rax, 0x60(%rdi)
movq %rsi, %rdi
xorl %esi, %esi
callq 0x56ff0
callq 0xd354a
pushq $0x1
popq %rax
popq %rbx
popq %r14
popq %rbp
retq