// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/libraries/libwebp/src/dec/vp8_dec.c
// Function: VP8GetHeaders
int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io) {
  const uint8_t* buf;
  size_t buf_size;
  VP8FrameHeader* frm_hdr;
  VP8PictureHeader* pic_hdr;
  VP8BitReader* br;
  VP8StatusCode status;

  if (dec == NULL) {
    return 0;
  }
  SetOk(dec);
  if (io == NULL) {
    return VP8SetError(dec, VP8_STATUS_INVALID_PARAM,
                       "null VP8Io passed to VP8GetHeaders()");
  }
  buf = io->data;
  buf_size = io->data_size;
  if (buf_size < 4) {
    return VP8SetError(dec, VP8_STATUS_NOT_ENOUGH_DATA,
                       "Truncated header.");
  }

  // Paragraph 9.1
  {
    const uint32_t bits = buf[0] | (buf[1] << 8) | (buf[2] << 16);
    frm_hdr = &dec->frm_hdr_;
    frm_hdr->key_frame_ = !(bits & 1);
    frm_hdr->profile_ = (bits >> 1) & 7;
    frm_hdr->show_ = (bits >> 4) & 1;
    frm_hdr->partition_length_ = (bits >> 5);
    if (frm_hdr->profile_ > 3) {
      return VP8SetError(dec, VP8_STATUS_BITSTREAM_ERROR,
                         "Incorrect keyframe parameters.");
    }
    if (!frm_hdr->show_) {
      return VP8SetError(dec, VP8_STATUS_UNSUPPORTED_FEATURE,
                         "Frame not displayable.");
    }
    buf += 3;
    buf_size -= 3;
  }

  pic_hdr = &dec->pic_hdr_;
  if (frm_hdr->key_frame_) {
    // Paragraph 9.2
    if (buf_size < 7) {
      return VP8SetError(dec, VP8_STATUS_NOT_ENOUGH_DATA,
                         "cannot parse picture header");
    }
    if (!VP8CheckSignature(buf, buf_size)) {
      return VP8SetError(dec, VP8_STATUS_BITSTREAM_ERROR,
                         "Bad code word");
    }
    pic_hdr->width_ = ((buf[4] << 8) | buf[3]) & 0x3fff;
    pic_hdr->xscale_ = buf[4] >> 6;   // ratio: 1, 5/4 5/3 or 2
    pic_hdr->height_ = ((buf[6] << 8) | buf[5]) & 0x3fff;
    pic_hdr->yscale_ = buf[6] >> 6;
    buf += 7;
    buf_size -= 7;

    dec->mb_w_ = (pic_hdr->width_ + 15) >> 4;
    dec->mb_h_ = (pic_hdr->height_ + 15) >> 4;

    // Setup default output area (can be later modified during io->setup())
    io->width = pic_hdr->width_;
    io->height = pic_hdr->height_;
    // IMPORTANT! use some sane dimensions in crop_* and scaled_* fields.
    // So they can be used interchangeably without always testing for
    // 'use_cropping'.
    io->use_cropping = 0;
    io->crop_top  = 0;
    io->crop_left = 0;
    io->crop_right  = io->width;
    io->crop_bottom = io->height;
    io->use_scaling  = 0;
    io->scaled_width = io->width;
    io->scaled_height = io->height;

    io->mb_w = io->width;   // for soundness
    io->mb_h = io->height;  // ditto

    VP8ResetProba(&dec->proba_);
    ResetSegmentHeader(&dec->segment_hdr_);
  }

  // Check if we have all the partition #0 available, and initialize dec->br_
  // to read this partition (and this partition only).
  if (frm_hdr->partition_length_ > buf_size) {
    return VP8SetError(dec, VP8_STATUS_NOT_ENOUGH_DATA,
                       "bad partition length");
  }

  br = &dec->br_;
  VP8InitBitReader(br, buf, frm_hdr->partition_length_);
  buf += frm_hdr->partition_length_;
  buf_size -= frm_hdr->partition_length_;

  if (frm_hdr->key_frame_) {
    pic_hdr->colorspace_ = VP8Get(br, "global-header");
    pic_hdr->clamp_type_ = VP8Get(br, "global-header");
  }
  if (!ParseSegmentHeader(br, &dec->segment_hdr_, &dec->proba_)) {
    return VP8SetError(dec, VP8_STATUS_BITSTREAM_ERROR,
                       "cannot parse segment header");
  }
  // Filter specs
  if (!ParseFilterHeader(br, dec)) {
    return VP8SetError(dec, VP8_STATUS_BITSTREAM_ERROR,
                       "cannot parse filter header");
  }
  status = ParsePartitions(dec, buf, buf_size);
  if (status != VP8_STATUS_OK) {
    return VP8SetError(dec, status, "cannot parse partitions");
  }

  // quantizer change
  VP8ParseQuant(dec);

  // Frame buffer marking
  if (!frm_hdr->key_frame_) {
    return VP8SetError(dec, VP8_STATUS_UNSUPPORTED_FEATURE,
                       "Not a key frame.");
  }

  VP8Get(br, "global-header");   // ignore the value of update_proba_

  VP8ParseProba(br, dec);

  // sanitized state
  dec->ready_ = 1;
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
xorl %ebx, %ebx
testq %rdi, %rdi
je 0xd1a7f
movq %rdi, %r14
movl $0x0, (%rdi)
leaq 0x5c766(%rip), %rax     # 0x12e148
movq %rax, 0x8(%rdi)
testq %rsi, %rsi
je 0xd1a05
movq 0x60(%rsi), %r12
cmpq $0x3, %r12
ja 0xd1a15
movq $0x7, (%r14)
leaq 0x57b76(%rip), %rax     # 0x129579
jmp 0xd1a7b
movq $0x2, (%r14)
leaq 0x57b41(%rip), %rax     # 0x129554
jmp 0xd1a7b
movq 0x68(%rsi), %rbp
movzbl (%rbp), %ecx
movzwl 0x1(%rbp), %eax
shll $0x8, %eax
orl %ecx, %eax
movl %ecx, %edx
andb $0x1, %dl
movl %edx, %edi
xorb $0x1, %dil
movb %dil, 0x44(%r14)
movl %ecx, %edi
shrb %dil
andb $0x7, %dil
movb %dil, 0x45(%r14)
shrb $0x4, %cl
andb $0x1, %cl
movb %cl, 0x46(%r14)
shrl $0x5, %eax
movl %eax, 0x48(%r14)
cmpb $0x4, %dil
jb 0xd1a69
movq $0x3, (%r14)
leaq 0x57b24(%rip), %rax     # 0x12958b
jmp 0xd1a7b
testb %cl, %cl
jne 0xd1a90
movq $0x4, (%r14)
leaq 0x57b2f(%rip), %rax     # 0x1295aa
movq %rax, 0x8(%r14)
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3(%rbp), %r15
leaq -0x3(%r12), %r13
testb %dl, %dl
jne 0xd1bab
cmpq $0x6, %r13
ja 0xd1ab7
movq $0x7, (%r14)
leaq 0x57b0c(%rip), %rax     # 0x1295c1
jmp 0xd1a7b
cmpb $-0x63, (%r15)
jne 0xd1d10
cmpb $0x1, 0x4(%rbp)
jne 0xd1d10
cmpb $0x2a, 0x5(%rbp)
jne 0xd1d10
movzbl 0x7(%rbp), %ecx
movzbl 0x6(%rbp), %edx
andl $0x3f, %ecx
shll $0x8, %ecx
leal (%rcx,%rdx), %eax
movw %ax, 0x4c(%r14)
movb 0x7(%rbp), %dil
shrb $0x6, %dil
movb %dil, 0x50(%r14)
movzbl 0x9(%rbp), %r8d
movzbl 0x8(%rbp), %r9d
andl $0x3f, %r8d
shll $0x8, %r8d
leal (%r8,%r9), %edi
movw %di, 0x4e(%r14)
movb 0x9(%rbp), %r10b
shrb $0x6, %r10b
movb %r10b, 0x51(%r14)
addq $0xa, %rbp
addq $-0xa, %r12
addl %edx, %ecx
addl $0xf, %ecx
shrl $0x4, %ecx
movl %ecx, 0x198(%r14)
leal (%r8,%r9), %ecx
addl $0xf, %ecx
shrl $0x4, %ecx
movl %ecx, 0x19c(%r14)
movl %eax, (%rsi)
movl %edi, 0x4(%rsi)
movq $0x0, 0x74(%rsi)
xorl %r15d, %r15d
movl %r15d, 0x80(%rsi)
movl %eax, 0x7c(%rsi)
movl %edi, 0x84(%rsi)
movl %r15d, 0x88(%rsi)
movl %eax, 0x8c(%rsi)
movl %edi, 0x90(%rsi)
movl %eax, 0xc(%rsi)
movl %edi, 0x10(%rsi)
leaq 0x4a8(%r14), %rdi
callq 0xf1cd8
movaps 0x411de(%rip), %xmm0    # 0x112d70
movups %xmm0, 0x84(%r14)
movl %r15d, 0x94(%r14)
movl 0x48(%r14), %eax
movq %r12, %r13
movq %rbp, %r15
movl %eax, %edx
cmpq %rdx, %r13
jae 0xd1bcf
cmpl $0x0, (%r14)
jne 0xd1a7f
movq $0x7, (%r14)
leaq 0x57a21(%rip), %rax     # 0x1295eb
jmp 0xd1a7b
leaq 0x10(%r14), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0xefab2
movl 0x48(%r14), %eax
movq %rax, (%rsp)
cmpb $0x0, 0x44(%r14)
je 0xd1c0f
movq %r12, %rdi
movl $0x1, %esi
callq 0xefc15
movb %al, 0x52(%r14)
movq %r12, %rdi
movl $0x1, %esi
callq 0xefc15
movb %al, 0x53(%r14)
movq %r12, %rdi
movl $0x1, %esi
callq 0xefc15
movl %eax, 0x84(%r14)
testl %eax, %eax
je 0xd1d23
movq %r12, %rdi
movl $0x1, %esi
callq 0xefc15
movl %eax, 0x88(%r14)
movq %r12, %rdi
movl $0x1, %esi
callq 0xefc15
testl %eax, %eax
je 0xd1cce
movq %r12, %rdi
movl $0x1, %esi
callq 0xefc15
movl %eax, 0x8c(%r14)
xorl %ebp, %ebp
movq %r12, %rdi
movl $0x1, %esi
callq 0xefc15
testl %eax, %eax
je 0xd1c86
movq %r12, %rdi
movl $0x7, %esi
callq 0xefd0b
jmp 0xd1c88
xorl %eax, %eax
movb %al, 0x90(%r14,%rbp)
incq %rbp
cmpq $0x4, %rbp
jne 0xd1c66
xorl %ebp, %ebp
movq %r12, %rdi
movl $0x1, %esi
callq 0xefc15
testl %eax, %eax
je 0xd1cbb
movq %r12, %rdi
movl $0x6, %esi
callq 0xefd0b
jmp 0xd1cbd
xorl %eax, %eax
movb %al, 0x94(%r14,%rbp)
incq %rbp
cmpq $0x4, %rbp
jne 0xd1c9b
cmpl $0x0, 0x88(%r14)
je 0xd1d2e
movq $-0x3, %rbp
movq %r12, %rdi
movl $0x1, %esi
callq 0xefc15
testl %eax, %eax
je 0xd1cff
movq %r12, %rdi
movl $0x8, %esi
callq 0xefc15
jmp 0xd1d01
movb $-0x1, %al
movb %al, 0x4ab(%r14,%rbp)
incq %rbp
jne 0xd1cdf
jmp 0xd1d2e
movq $0x3, (%r14)
leaq 0x578bf(%rip), %rax     # 0x1295dd
jmp 0xd1a7b
movl $0x0, 0x88(%r14)
cmpl $0x0, 0x38(%r14)
je 0xd1d52
cmpl $0x0, (%r14)
jne 0xd1a7f
movq $0x3, (%r14)
leaq 0x578b3(%rip), %rax     # 0x129600
jmp 0xd1a7b
movq %r12, %rdi
movq %r14, %rsi
callq 0xd1e06
testl %eax, %eax
je 0xd1d93
movq (%rsp), %rax
addq %rax, %r15
subq %rax, %r13
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xd1ef0
testl %eax, %eax
je 0xd1db0
leaq 0x578b3(%rip), %rdx     # 0x129637
movq %r14, %rdi
movl %eax, %esi
callq 0xd18d5
jmp 0xd1a7f
cmpl $0x0, (%r14)
jne 0xd1a7f
movq $0x3, (%r14)
leaq 0x57871(%rip), %rax     # 0x12961c
jmp 0xd1a7b
movq %r14, %rdi
callq 0xf1a80
cmpb $0x0, 0x44(%r14)
je 0xd1de9
movl $0x1, %ebx
movq %r12, %rdi
movl $0x1, %esi
callq 0xefc15
movq %r12, %rdi
movq %r14, %rsi
callq 0xf26dc
movl $0x1, 0x4(%r14)
jmp 0xd1a7f
cmpl $0x0, (%r14)
jne 0xd1a7f
movq $0x4, (%r14)
leaq 0x5784e(%rip), %rax     # 0x12964f
jmp 0xd1a7b