// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/libraries/libwebp/src/dec/frame_dec.c
// Function: AllocateMemory
static int AllocateMemory(VP8Decoder* const dec) {
  const int num_caches = dec->num_caches_;
  const int mb_w = dec->mb_w_;
  // Note: we use 'size_t' when there's no overflow risk, uint64_t otherwise.
  const size_t intra_pred_mode_size = 4 * mb_w * sizeof(uint8_t);
  const size_t top_size = sizeof(VP8TopSamples) * mb_w;
  const size_t mb_info_size = (mb_w + 1) * sizeof(VP8MB);
  const size_t f_info_size =
      (dec->filter_type_ > 0) ?
          mb_w * (dec->mt_method_ > 0 ? 2 : 1) * sizeof(VP8FInfo)
        : 0;
  const size_t yuv_size = YUV_SIZE * sizeof(*dec->yuv_b_);
  const size_t mb_data_size =
      (dec->mt_method_ == 2 ? 2 : 1) * mb_w * sizeof(*dec->mb_data_);
  const size_t cache_height = (16 * num_caches
                            + kFilterExtraRows[dec->filter_type_]) * 3 / 2;
  const size_t cache_size = top_size * cache_height;
  // alpha_size is the only one that scales as width x height.
  const uint64_t alpha_size = (dec->alpha_data_ != NULL) ?
      (uint64_t)dec->pic_hdr_.width_ * dec->pic_hdr_.height_ : 0ULL;
  const uint64_t needed = (uint64_t)intra_pred_mode_size
                        + top_size + mb_info_size + f_info_size
                        + yuv_size + mb_data_size
                        + cache_size + alpha_size + WEBP_ALIGN_CST;
  uint8_t* mem;

  if (!CheckSizeOverflow(needed)) return 0;  // check for overflow
  if (needed > dec->mem_size_) {
    WebPSafeFree(dec->mem_);
    dec->mem_size_ = 0;
    dec->mem_ = WebPSafeMalloc(needed, sizeof(uint8_t));
    if (dec->mem_ == NULL) {
      return VP8SetError(dec, VP8_STATUS_OUT_OF_MEMORY,
                         "no memory during frame initialization.");
    }
    // down-cast is ok, thanks to WebPSafeMalloc() above.
    dec->mem_size_ = (size_t)needed;
  }

  mem = (uint8_t*)dec->mem_;
  dec->intra_t_ = mem;
  mem += intra_pred_mode_size;

  dec->yuv_t_ = (VP8TopSamples*)mem;
  mem += top_size;

  dec->mb_info_ = ((VP8MB*)mem) + 1;
  mem += mb_info_size;

  dec->f_info_ = f_info_size ? (VP8FInfo*)mem : NULL;
  mem += f_info_size;
  dec->thread_ctx_.id_ = 0;
  dec->thread_ctx_.f_info_ = dec->f_info_;
  if (dec->filter_type_ > 0 && dec->mt_method_ > 0) {
    // secondary cache line. The deblocking process need to make use of the
    // filtering strength from previous macroblock row, while the new ones
    // are being decoded in parallel. We'll just swap the pointers.
    dec->thread_ctx_.f_info_ += mb_w;
  }

  mem = (uint8_t*)WEBP_ALIGN(mem);
  assert((yuv_size & WEBP_ALIGN_CST) == 0);
  dec->yuv_b_ = mem;
  mem += yuv_size;

  dec->mb_data_ = (VP8MBData*)mem;
  dec->thread_ctx_.mb_data_ = (VP8MBData*)mem;
  if (dec->mt_method_ == 2) {
    dec->thread_ctx_.mb_data_ += mb_w;
  }
  mem += mb_data_size;

  dec->cache_y_stride_ = 16 * mb_w;
  dec->cache_uv_stride_ = 8 * mb_w;
  {
    const int extra_rows = kFilterExtraRows[dec->filter_type_];
    const int extra_y = extra_rows * dec->cache_y_stride_;
    const int extra_uv = (extra_rows / 2) * dec->cache_uv_stride_;
    dec->cache_y_ = mem + extra_y;
    dec->cache_u_ = dec->cache_y_
                  + 16 * num_caches * dec->cache_y_stride_ + extra_uv;
    dec->cache_v_ = dec->cache_u_
                  + 8 * num_caches * dec->cache_uv_stride_ + extra_uv;
    dec->cache_id_ = 0;
  }
  mem += cache_size;

  // alpha plane
  dec->alpha_plane_ = alpha_size ? mem : NULL;
  mem += alpha_size;
  assert(mem <= (uint8_t*)dec->mem_ + dec->mem_size_);

  // note: left/top-info is initialized once for all.
  memset(dec->mb_info_ - 1, 0, mb_info_size);
  VP8InitScanline(dec);   // initialize left too.

  // initialize top
  memset(dec->intra_t_, B_DC_PRED, intra_pred_mode_size);

  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0xd0(%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x198(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
shll $0x2, %eax
cltq
shlq $0x0, %rax
movq %rax, -0x20(%rbp)
movslq -0x18(%rbp), %rax
shlq $0x5, %rax
movq %rax, -0x28(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
cltq
shlq %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xb68(%rax)
jle 0x13f4a0
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0xc8(%rcx), %esi
movl $0x1, %ecx
movl $0x2, %edx
cmpl $0x0, %esi
cmovgl %edx, %ecx
imull %ecx, %eax
cltq
shlq $0x2, %rax
movq %rax, -0x88(%rbp)
jmp 0x13f4ab
xorl %eax, %eax
movq %rax, -0x88(%rbp)
jmp 0x13f4ab
movq -0x88(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x340, -0x40(%rbp)     # imm = 0x340
movq -0x10(%rbp), %rax
movl 0xc8(%rax), %edx
movl $0x1, %eax
movl $0x2, %ecx
cmpl $0x2, %edx
cmovel %ecx, %eax
imull -0x18(%rbp), %eax
cltq
imulq $0x320, %rax, %rax      # imm = 0x320
movq %rax, -0x48(%rbp)
movl -0x14(%rbp), %eax
shll $0x4, %eax
movq -0x10(%rbp), %rcx
movslq 0xb68(%rcx), %rdx
leaq 0x7d7db(%rip), %rcx     # 0x1bccdc
movzbl (%rcx,%rdx), %ecx
addl %ecx, %eax
imull $0x3, %eax, %eax
movl $0x2, %ecx
cltd
idivl %ecx
cltq
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
imulq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0xb98(%rax)
je 0x13f550
movq -0x10(%rbp), %rax
movzwl 0x4c(%rax), %eax
movq -0x10(%rbp), %rcx
movzwl 0x4e(%rcx), %ecx
imulq %rcx, %rax
movq %rax, -0x90(%rbp)
jmp 0x13f55b
xorl %eax, %eax
movq %rax, -0x90(%rbp)
jmp 0x13f55b
movq -0x90(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rax
addq -0x28(%rbp), %rax
addq -0x30(%rbp), %rax
addq -0x38(%rbp), %rax
addq $0x340, %rax            # imm = 0x340
addq -0x48(%rbp), %rax
addq -0x58(%rbp), %rax
addq -0x60(%rbp), %rax
addq $0x1f, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
callq 0x1401e0
cmpl $0x0, %eax
jne 0x13f5aa
movl $0x0, -0x4(%rbp)
jmp 0x13f96a
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0xb50(%rcx), %rax
jbe 0x13f630
movq -0x10(%rbp), %rax
movq 0xb48(%rax), %rdi
callq 0x5b920
movq -0x10(%rbp), %rax
movq $0x0, 0xb50(%rax)
movq -0x68(%rbp), %rdi
movl $0x1, %esi
callq 0x5b060
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xb48(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0xb48(%rax)
jne 0x13f621
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x7d640(%rip), %rdx     # 0x1bcc54
callq 0x142580
movl %eax, -0x4(%rbp)
jmp 0x13f96a
movq -0x68(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xb50(%rax)
movq -0x10(%rbp), %rax
movq 0xb48(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xaf8(%rax)
movq -0x20(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xb08(%rax)
movq -0x28(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rcx
addq $0x2, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xb10(%rax)
movq -0x30(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x13f6a8
movq -0x70(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x13f6b3
xorl %eax, %eax
movq %rax, -0x98(%rbp)
jmp 0x13f6b3
movq -0x98(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xb18(%rax)
movq -0x38(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0xd8(%rax)
movq -0x10(%rbp), %rax
movq 0xb18(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xe8(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xb68(%rax)
jle 0x13f72e
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc8(%rax)
jle 0x13f72e
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0xe8(%rax), %rcx
movslq %edx, %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
movq %rcx, 0xe8(%rax)
movq -0x70(%rbp), %rax
addq $0x1f, %rax
andq $-0x20, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xb20(%rax)
movq -0x70(%rbp), %rax
addq $0x340, %rax            # imm = 0x340
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xb60(%rax)
movq -0x70(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xf0(%rax)
movq -0x10(%rbp), %rax
cmpl $0x2, 0xc8(%rax)
jne 0x13f7a8
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0xf0(%rax), %rcx
movslq %edx, %rdx
imulq $0x320, %rdx, %rdx      # imm = 0x320
addq %rdx, %rcx
movq %rcx, 0xf0(%rax)
movq -0x48(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x18(%rbp), %ecx
shll $0x4, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xb40(%rax)
movl -0x18(%rbp), %ecx
shll $0x3, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xb44(%rax)
movq -0x10(%rbp), %rax
movslq 0xb68(%rax), %rcx
leaq 0x7d4f6(%rip), %rax     # 0x1bccdc
movzbl (%rax,%rcx), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x10(%rbp), %rcx
imull 0xb40(%rcx), %eax
movl %eax, -0x78(%rbp)
movl -0x74(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movq -0x10(%rbp), %rcx
imull 0xb44(%rcx), %eax
movl %eax, -0x7c(%rbp)
movq -0x70(%rbp), %rcx
movslq -0x78(%rbp), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xb28(%rax)
movq -0x10(%rbp), %rax
movq 0xb28(%rax), %rcx
movl -0x14(%rbp), %eax
shll $0x4, %eax
movq -0x10(%rbp), %rdx
imull 0xb40(%rdx), %eax
cltq
addq %rax, %rcx
movslq -0x7c(%rbp), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xb30(%rax)
movq -0x10(%rbp), %rax
movq 0xb30(%rax), %rcx
movl -0x14(%rbp), %eax
shll $0x3, %eax
movq -0x10(%rbp), %rdx
imull 0xb44(%rdx), %eax
cltq
addq %rax, %rcx
movslq -0x7c(%rbp), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xb38(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0xcc(%rax)
movq -0x58(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x13f8c1
movq -0x70(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x13f8cc
xorl %eax, %eax
movq %rax, -0xa0(%rbp)
jmp 0x13f8cc
movq -0xa0(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xbb8(%rax)
movq -0x60(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0xb48(%rcx), %rcx
movq -0x10(%rbp), %rdx
addq 0xb50(%rdx), %rcx
cmpq %rcx, %rax
ja 0x13f90b
jmp 0x13f92a
leaq 0x7d369(%rip), %rdi     # 0x1bcc7b
leaq 0x7d023(%rip), %rsi     # 0x1bc93c
movl $0x304, %edx            # imm = 0x304
leaq 0x7d382(%rip), %rcx     # 0x1bcca7
callq 0x598a0
movq -0x10(%rbp), %rax
movq 0xb10(%rax), %rdi
addq $-0x2, %rdi
movq -0x30(%rbp), %rdx
xorl %esi, %esi
callq 0x5a200
movq -0x10(%rbp), %rdi
callq 0x1439a0
movq -0x10(%rbp), %rax
movq 0xaf8(%rax), %rdi
movq -0x20(%rbp), %rdx
xorl %esi, %esi
callq 0x5a200
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)