// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x38(%rbp)
movslq -0x24(%rbp), %rax
shlq %rax
movslq 0x18(%rbp), %rcx
imulq %rcx, %rax
shlq $0x2, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x13d690
cmpl $0x0, %eax
jne 0x13d421
movl $0x0, -0x4(%rbp)
jmp 0x13d679
movl -0x14(%rbp), %eax
cmpl -0x24(%rbp), %eax
setl %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movl -0x18(%rbp), %eax
cmpl -0x28(%rbp), %eax
setl %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x34(%rax)
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x3c(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movl 0x10(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x50(%rax)
movl 0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x13d4bc
movl -0x30(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x13d4c2
movl -0x2c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x13d4e0
movl -0x2c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x13d4e6
movl -0x30(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x13d519
movq -0x10(%rbp), %rax
movslq 0x28(%rax), %rcx
movabsq $0x100000000, %rax      # imm = 0x100000000
xorl %edx, %edx
divq %rcx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x13d52e
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x13d534
movl -0x34(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x13d553
movl -0x38(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x13d559
movl -0x38(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x13d579
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x6c(%rbp)
jmp 0x13d583
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x13d616
movslq -0x28(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movslq 0x24(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x1c(%rcx), %rcx
imulq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x50(%rbp)
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x58(%rbp), %rcx
movl %ecx, %ecx
cmpq %rcx, %rax
je 0x13d5e7
movq -0x10(%rbp), %rax
movl $0x0, 0x14(%rax)
jmp 0x13d5f4
movq -0x58(%rbp), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rax
movslq 0x20(%rax), %rcx
movabsq $0x100000000, %rax      # imm = 0x100000000
xorl %edx, %edx
divq %rcx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0x13d636
movq -0x10(%rbp), %rax
movslq 0x24(%rax), %rcx
movabsq $0x100000000, %rax      # imm = 0x100000000
xorl %edx, %edx
divq %rcx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq 0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
movq 0x20(%rbp), %rcx
movl 0x18(%rbp), %eax
imull -0x24(%rbp), %eax
cltq
shlq $0x2, %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movq 0x20(%rbp), %rdi
movq -0x40(%rbp), %rdx
xorl %esi, %esi
callq 0x5a200
callq 0x151340
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)