// File: /workspace/github_c_makefile_star2_O2/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
subq $0x38, %rsp
xorl %ebx, %ebx
testq %rdi, %rdi
je 0xcaa2c
movq %rsi, %r12
movq %rdi, %r14
andl $0x0, (%rdi)
leaq 0x53527(%rip), %rax     # 0x11deb4
movq %rax, 0x8(%rdi)
testq %rsi, %rsi
je 0xca9b1
movq 0x60(%r12), %r15
cmpq $0x3, %r15
ja 0xca9c1
movq $0x7, (%r14)
leaq 0x4e8fa(%rip), %rax     # 0x1192a9
jmp 0xcaa28
movq $0x2, (%r14)
leaq 0x4e8c5(%rip), %rax     # 0x119284
jmp 0xcaa28
movq 0x68(%r12), %rbp
movzbl (%rbp), %ecx
movzwl 0x1(%rbp), %eax
shll $0x8, %eax
orl %ecx, %eax
movl %ecx, %edx
andb $0x1, %dl
movl %edx, %esi
xorb $0x1, %sil
movb %sil, 0x44(%r14)
movl %ecx, %esi
shrb %sil
andb $0x7, %sil
movb %sil, 0x45(%r14)
shrb $0x4, %cl
andb $0x1, %cl
movb %cl, 0x46(%r14)
shrl $0x5, %eax
movl %eax, 0x48(%r14)
cmpb $0x4, %sil
jb 0xcaa16
movq $0x3, (%r14)
leaq 0x4e8a7(%rip), %rax     # 0x1192bb
jmp 0xcaa28
testb %cl, %cl
jne 0xcaa3d
movq $0x4, (%r14)
leaq 0x4e8b2(%rip), %rax     # 0x1192da
movq %rax, 0x8(%r14)
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3(%rbp), %rcx
leaq -0x3(%r15), %rsi
testb %dl, %dl
jne 0xcab54
cmpq $0x6, %rsi
ja 0xcaa63
movq $0x7, (%r14)
leaq 0x4e890(%rip), %rax     # 0x1192f1
jmp 0xcaa28
movq %rcx, %rdi
callq 0x57d90
testl %eax, %eax
je 0xcad7b
movzbl 0x7(%rbp), %ecx
movzbl 0x6(%rbp), %esi
andl $0x3f, %ecx
shll $0x8, %ecx
leal (%rcx,%rsi), %eax
movw %ax, 0x4c(%r14)
movb 0x7(%rbp), %dl
shrb $0x6, %dl
movb %dl, 0x50(%r14)
movzbl 0x9(%rbp), %edi
movzbl 0x8(%rbp), %r8d
andl $0x3f, %edi
shll $0x8, %edi
leal (%rdi,%r8), %edx
movw %dx, 0x4e(%r14)
movb 0x9(%rbp), %r9b
shrb $0x6, %r9b
movb %r9b, 0x51(%r14)
addl %esi, %ecx
addl $0xf, %ecx
shrl $0x4, %ecx
movl %ecx, 0x198(%r14)
leal (%rdi,%r8), %ecx
addl $0xf, %ecx
shrl $0x4, %ecx
movl %ecx, 0x19c(%r14)
movl %eax, (%r12)
movl %edx, 0x4(%r12)
andq $0x0, 0x74(%r12)
andl $0x0, 0x80(%r12)
addq $0xa, %rbp
addq $-0xa, %r15
movl %eax, 0x7c(%r12)
movl %edx, 0x84(%r12)
andl $0x0, 0x88(%r12)
movl %eax, 0x8c(%r12)
movl %edx, 0x90(%r12)
movl %eax, 0xc(%r12)
movl %edx, 0x10(%r12)
leaq 0x4a8(%r14), %rdi
callq 0xe2550
movaps 0x4e696(%rip), %xmm0    # 0x1191d0
movups %xmm0, 0x84(%r14)
andl $0x0, 0x94(%r14)
movl 0x48(%r14), %eax
movq %r15, %rsi
movq %rbp, %rcx
movl %eax, %edx
cmpq %rdx, %rsi
jae 0xcab78
cmpl $0x0, (%r14)
jne 0xcaa2c
movq $0x7, (%r14)
leaq 0x4e7a8(%rip), %rax     # 0x11931b
jmp 0xcaa28
movq %rsi, (%rsp)
leaq 0x10(%r14), %r12
movq %r12, %rdi
movq %rcx, 0x10(%rsp)
movq %rcx, %rsi
callq 0xe057a
movl 0x48(%r14), %r15d
cmpb $0x0, 0x44(%r14)
je 0xcabba
pushq $0x1
popq %rbp
movq %r12, %rdi
movl %ebp, %esi
callq 0xe06e5
movb %al, 0x52(%r14)
movq %r12, %rdi
movl %ebp, %esi
callq 0xe06e5
movb %al, 0x53(%r14)
movq %r15, 0x8(%rsp)
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0xe06e5
movl %eax, 0x84(%r14)
testl %eax, %eax
je 0xcacc8
pushq $0x1
popq %rbp
movq %r12, %rdi
movl %ebp, %esi
callq 0xe06e5
movl %eax, 0x88(%r14)
movq %r12, %rdi
movl %ebp, %esi
callq 0xe06e5
testl %eax, %eax
je 0xcac84
pushq $0x1
popq %rbp
movq %r12, %rdi
movl %ebp, %esi
callq 0xe06e5
movl %eax, 0x8c(%r14)
xorl %r13d, %r13d
pushq $0x7
popq %r15
cmpq $0x4, %r13
je 0xcac4a
movq %r12, %rdi
movl %ebp, %esi
callq 0xe06e5
testl %eax, %eax
je 0xcac3b
movq %r12, %rdi
movl %r15d, %esi
callq 0xe0777
jmp 0xcac3d
xorl %eax, %eax
movb %al, 0x90(%r14,%r13)
incq %r13
jmp 0xcac1a
xorl %r13d, %r13d
pushq $0x1
popq %rbp
pushq $0x6
popq %r15
cmpq $0x4, %r13
je 0xcac84
movq %r12, %rdi
movl %ebp, %esi
callq 0xe06e5
testl %eax, %eax
je 0xcac75
movq %r12, %rdi
movl %r15d, %esi
callq 0xe0777
jmp 0xcac77
xorl %eax, %eax
movb %al, 0x94(%r14,%r13)
incq %r13
jmp 0xcac54
cmpl $0x0, 0x88(%r14)
je 0xcacd0
xorl %r13d, %r13d
pushq $0x1
popq %rbp
pushq $0x8
popq %r15
cmpq $0x3, %r13
je 0xcacd0
movq %r12, %rdi
movl %ebp, %esi
callq 0xe06e5
testl %eax, %eax
je 0xcacb9
movq %r12, %rdi
movl %r15d, %esi
callq 0xe06e5
jmp 0xcacbb
movb $-0x1, %al
movb %al, 0x4a8(%r14,%r13)
incq %r13
jmp 0xcac98
andl $0x0, 0x88(%r14)
cmpl $0x0, 0x38(%r14)
je 0xcacf4
cmpl $0x0, (%r14)
jne 0xcaa2c
movq $0x3, (%r14)
leaq 0x4e641(%rip), %rax     # 0x119330
jmp 0xcaa28
pushq $0x1
popq %rbx
movq %r12, %rdi
movl %ebx, %esi
callq 0xe06e5
movl %eax, 0x54(%r14)
pushq $0x6
popq %rsi
movq %r12, %rdi
callq 0xe06e5
movl %eax, 0x58(%r14)
pushq $0x3
popq %rsi
movq %r12, %rdi
callq 0xe06e5
movl %eax, 0x5c(%r14)
movq %r12, %rdi
movl %ebx, %esi
callq 0xe06e5
movl %eax, 0x60(%r14)
testl %eax, %eax
je 0xcadc1
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0xe06e5
testl %eax, %eax
je 0xcadc1
xorl %r13d, %r13d
pushq $0x1
popq %rbp
pushq $0x6
popq %r15
cmpq $0x4, %r13
je 0xcad8e
movq %r12, %rdi
movl %ebp, %esi
callq 0xe06e5
testl %eax, %eax
je 0xcad76
movq %r12, %rdi
movl %r15d, %esi
callq 0xe0777
movl %eax, 0x64(%r14,%r13,4)
incq %r13
jmp 0xcad52
movq $0x3, (%r14)
leaq 0x4e584(%rip), %rax     # 0x11930d
jmp 0xcaa28
xorl %r13d, %r13d
pushq $0x1
popq %rbp
pushq $0x6
popq %r15
cmpq $0x4, %r13
je 0xcadc1
movq %r12, %rdi
movl %ebp, %esi
callq 0xe06e5
testl %eax, %eax
je 0xcadbc
movq %r12, %rdi
movl %r15d, %esi
callq 0xe0777
movl %eax, 0x74(%r14,%r13,4)
incq %r13
jmp 0xcad98
cmpl $0x0, 0x58(%r14)
je 0xcadd4
xorl %eax, %eax
cmpl $0x1, 0x54(%r14)
adcl $0x1, %eax
jmp 0xcadd6
xorl %eax, %eax
movq (%rsp), %r15
movl %eax, 0xb68(%r14)
cmpl $0x0, 0x38(%r14)
je 0xcae07
xorl %ebx, %ebx
cmpl $0x0, (%r14)
jne 0xcaa2c
movq $0x3, (%r14)
leaq 0x4e54a(%rip), %rax     # 0x11934c
jmp 0xcaa28
movq %r15, %rbp
movq 0x8(%rsp), %r13
subq %r13, %rbp
pushq $0x2
popq %rsi
movq %r12, %rdi
callq 0xe06e5
movq %rbp, %rdx
pushq $-0x1
popq %rsi
movl %eax, %ecx
shll %cl, %esi
notl %esi
movl %esi, 0x1b0(%r14)
leaq (%rsi,%rsi,2), %rcx
subq %rcx, %rdx
jae 0xcae41
pushq $0x7
popq %rsi
jmp 0xcaf2e
movq %rsi, 0x20(%rsp)
movq 0x10(%rsp), %rax
addq %rax, %r13
addq %rax, %r15
movq %r15, (%rsp)
movq %r13, 0x8(%rsp)
leaq (%rcx,%r13), %r15
leaq 0x1b8(%r14), %rbp
xorl %esi, %esi
movq %rbp, 0x18(%rsp)
movq %rcx, 0x28(%rsp)
cmpq %rsi, %rcx
je 0xcaed0
movq 0x8(%rsp), %rcx
movzwl (%rcx,%rsi), %eax
movzbl 0x2(%rcx,%rsi), %r13d
shll $0x10, %r13d
orq %rax, %r13
cmpq %rdx, %r13
cmovaeq %rdx, %r13
movq %rbp, %rdi
movq %rsi, 0x10(%rsp)
movq %r15, %rsi
movq %r15, 0x30(%rsp)
movq %rdx, %r15
movq %r13, %rdx
callq 0xe057a
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rcx
movq %r15, %rdx
movq 0x30(%rsp), %r15
addq %r13, %r15
subq %r13, %rdx
addq $0x3, %rsi
addq $0x30, %rbp
jmp 0xcae71
imulq $0x30, 0x20(%rsp), %rax
movq 0x18(%rsp), %rdi
addq %rax, %rdi
movq %r15, %rsi
callq 0xe057a
cmpq (%rsp), %r15
jae 0xcaf1d
movq %r14, %rdi
callq 0xe2318
cmpb $0x0, 0x44(%r14)
je 0xcaf44
movq %r12, %rdi
movl %ebx, %esi
callq 0xe06e5
movq %r12, %rdi
movq %r14, %rsi
callq 0xe27ce
movl $0x1, 0x4(%r14)
jmp 0xcaa2c
xorl %eax, %eax
cmpl $0x0, 0x40(%r14)
sete %al
leal 0x5(,%rax,2), %esi
leaq 0x4e432(%rip), %rdx     # 0x119367
movq %r14, %rdi
callq 0xca862
xorl %ebx, %ebx
jmp 0xcaa2c
xorl %ebx, %ebx
cmpl $0x0, (%r14)
jne 0xcaa2c
movq $0x4, (%r14)
leaq 0x4e421(%rip), %rax     # 0x11937f
jmp 0xcaa28