// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/libraries/libwebp/src/dec/buffer_dec.c
// Function: AllocateBuffer
static VP8StatusCode AllocateBuffer(WebPDecBuffer* const buffer) {
  const int w = buffer->width;
  const int h = buffer->height;
  const WEBP_CSP_MODE mode = buffer->colorspace;

  if (w <= 0 || h <= 0 || !IsValidColorspace(mode)) {
    return VP8_STATUS_INVALID_PARAM;
  }

  if (buffer->is_external_memory <= 0 && buffer->private_memory == NULL) {
    uint8_t* output;
    int uv_stride = 0, a_stride = 0;
    uint64_t uv_size = 0, a_size = 0, total_size;
    // We need memory and it hasn't been allocated yet.
    // => initialize output buffer, now that dimensions are known.
    int stride;
    uint64_t size;

    if ((uint64_t)w * kModeBpp[mode] >= (1ull << 31)) {
      return VP8_STATUS_INVALID_PARAM;
    }
    stride = w * kModeBpp[mode];
    size = (uint64_t)stride * h;
    if (!WebPIsRGBMode(mode)) {
      uv_stride = (w + 1) / 2;
      uv_size = (uint64_t)uv_stride * ((h + 1) / 2);
      if (mode == MODE_YUVA) {
        a_stride = w;
        a_size = (uint64_t)a_stride * h;
      }
    }
    total_size = size + 2 * uv_size + a_size;

    output = (uint8_t*)WebPSafeMalloc(total_size, sizeof(*output));
    if (output == NULL) {
      return VP8_STATUS_OUT_OF_MEMORY;
    }
    buffer->private_memory = output;

    if (!WebPIsRGBMode(mode)) {   // YUVA initialization
      WebPYUVABuffer* const buf = &buffer->u.YUVA;
      buf->y = output;
      buf->y_stride = stride;
      buf->y_size = (size_t)size;
      buf->u = output + size;
      buf->u_stride = uv_stride;
      buf->u_size = (size_t)uv_size;
      buf->v = output + size + uv_size;
      buf->v_stride = uv_stride;
      buf->v_size = (size_t)uv_size;
      if (mode == MODE_YUVA) {
        buf->a = output + size + 2 * uv_size;
      }
      buf->a_size = (size_t)a_size;
      buf->a_stride = a_stride;
    } else {  // RGBA initialization
      WebPRGBABuffer* const buf = &buffer->u.RGBA;
      buf->rgba = output;
      buf->stride = stride;
      buf->size = (size_t)size;
    }
  }
  return CheckDecBuffer(buffer);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x13aa22
cmpl $0x0, -0x18(%rbp)
jle 0x13aa22
movl -0x1c(%rbp), %edi
callq 0x13b4b0
cmpl $0x0, %eax
jne 0x13aa2e
movl $0x2, -0x4(%rbp)
jmp 0x13ac6b
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jg 0x13ac5f
movq -0x10(%rbp), %rax
cmpq $0x0, 0x70(%rax)
jne 0x13ac5f
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movslq -0x14(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %edx
leaq 0x817bd(%rip), %rcx     # 0x1bc236
movzbl (%rcx,%rdx), %ecx
imulq %rcx, %rax
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jb 0x13aa97
movl $0x2, -0x4(%rbp)
jmp 0x13ac6b
movl -0x14(%rbp), %eax
movl -0x1c(%rbp), %ecx
movl %ecx, %edx
leaq 0x81790(%rip), %rcx     # 0x1bc236
movzbl (%rcx,%rdx), %ecx
imull %ecx, %eax
movl %eax, -0x4c(%rbp)
movslq -0x4c(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq %rcx, %rax
movq %rax, -0x58(%rbp)
movl -0x1c(%rbp), %edi
callq 0x13a860
cmpl $0x0, %eax
jne 0x13ab23
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x2c(%rbp)
movslq -0x2c(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x70(%rbp), %rax
movslq %ecx, %rcx
imulq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpl $0xc, -0x1c(%rbp)
jne 0x13ab21
movl -0x14(%rbp), %eax
movl %eax, -0x30(%rbp)
movslq -0x30(%rbp), %rax
movslq -0x18(%rbp), %rcx
imulq %rcx, %rax
movq %rax, -0x40(%rbp)
jmp 0x13ab23
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq %rcx
addq %rcx, %rax
addq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x5b060
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x13ab5e
movl $0x1, -0x4(%rbp)
jmp 0x13ac6b
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
movl -0x1c(%rbp), %edi
callq 0x13a860
cmpl $0x0, %eax
jne 0x13ac30
movq -0x10(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, (%rax)
movl -0x4c(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x58(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x28(%rbp), %rcx
addq -0x58(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x2c(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x38(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x28(%rbp), %rcx
addq -0x58(%rbp), %rcx
addq -0x38(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x2c(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x38(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x40(%rax)
cmpl $0xc, -0x1c(%rbp)
jne 0x13ac18
movq -0x28(%rbp), %rcx
addq -0x58(%rbp), %rcx
movq -0x38(%rbp), %rax
shlq %rax
addq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x48(%rax)
movl -0x30(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x2c(%rax)
jmp 0x13ac5d
movq -0x10(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, (%rax)
movl -0x4c(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x58(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x13ac5f
movq -0x10(%rbp), %rdi
callq 0x13b050
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)