// File: /workspace/github_c_makefile_star2_O1/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 0xd289f
movq %rdi, %r14
movl $0x0, (%rdi)
leaq 0x5c6ea(%rip), %rax     # 0x12ef54
movq %rax, 0x8(%rdi)
testq %rsi, %rsi
je 0xd288d
movq 0x60(%rsi), %r15
cmpq $0x3, %r15
ja 0xd28b0
movq $0x7, (%r14)
leaq 0x57ace(%rip), %rax     # 0x12a359
jmp 0xd289b
movq $0x2, (%r14)
leaq 0x57a99(%rip), %rax     # 0x12a334
movq %rax, 0x8(%r14)
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x68(%rsi), %r12
movzbl (%r12), %ecx
movzbl 0x1(%r12), %edx
shll $0x8, %edx
movzbl 0x2(%r12), %eax
shll $0x10, %eax
orl %ecx, %edx
orl %eax, %edx
movl %ecx, %eax
andb $0x1, %al
movl %eax, %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, %edx
movl %edx, 0x48(%r14)
cmpb $0x4, %dil
jb 0xd2911
movq $0x3, (%r14)
leaq 0x57a5c(%rip), %rcx     # 0x12a36b
jmp 0xd2923
testb %cl, %cl
jne 0xd292b
movq $0x4, (%r14)
leaq 0x57a67(%rip), %rcx     # 0x12a38a
movq %rcx, 0x8(%r14)
xorl %ecx, %ecx
jmp 0xd2935
addq $0x3, %r12
addq $-0x3, %r15
movb $0x1, %cl
testb %cl, %cl
je 0xd289f
testb %al, %al
jne 0xd2a5c
cmpq $0x6, %r15
ja 0xd2968
cmpl $0x0, (%r14)
jne 0xd289f
movq $0x7, (%r14)
leaq 0x57a3e(%rip), %rax     # 0x12a3a1
jmp 0xd289b
cmpb $-0x63, (%r12)
jne 0xd2bc3
cmpb $0x1, 0x1(%r12)
jne 0xd2bc3
cmpb $0x2a, 0x2(%r12)
jne 0xd2bc3
movzbl 0x4(%r12), %ecx
movzbl 0x3(%r12), %edx
andl $0x3f, %ecx
shll $0x8, %ecx
leal (%rcx,%rdx), %eax
movw %ax, 0x4c(%r14)
movb 0x4(%r12), %dil
shrb $0x6, %dil
movb %dil, 0x50(%r14)
movzbl 0x6(%r12), %r8d
movzbl 0x5(%r12), %r9d
andl $0x3f, %r8d
shll $0x8, %r8d
leal (%r8,%r9), %edi
movw %di, 0x4e(%r14)
movb 0x6(%r12), %r10b
shrb $0x6, %r10b
movb %r10b, 0x51(%r14)
addq $0x7, %r12
addq $-0x7, %r15
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 %ebp, %ebp
movl %ebp, 0x80(%rsi)
movl %eax, 0x7c(%rsi)
movl %edi, 0x84(%rsi)
movl %ebp, 0x88(%rsi)
movl %eax, 0x8c(%rsi)
movl %edi, 0x90(%rsi)
movl %eax, 0xc(%rsi)
movl %edi, 0x10(%rsi)
leaq 0x4a8(%r14), %rdi
callq 0xf2ad4
movaps 0x57833(%rip), %xmm0    # 0x12a280
movups %xmm0, 0x84(%r14)
movl %ebp, 0x94(%r14)
movl 0x48(%r14), %edx
cmpq %rdx, %r15
jae 0xd2a82
cmpl $0x0, (%r14)
jne 0xd289f
movq $0x7, (%r14)
leaq 0x5794e(%rip), %rax     # 0x12a3cb
jmp 0xd289b
leaq 0x10(%r14), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0xf087a
movl 0x48(%r14), %eax
movq %rax, (%rsp)
cmpb $0x0, 0x44(%r14)
je 0xd2ac2
movq %r13, %rdi
movl $0x1, %esi
callq 0xf09dd
movb %al, 0x52(%r14)
movq %r13, %rdi
movl $0x1, %esi
callq 0xf09dd
movb %al, 0x53(%r14)
movq %r13, %rdi
movl $0x1, %esi
callq 0xf09dd
movl %eax, 0x84(%r14)
testl %eax, %eax
je 0xd2be0
movq %r13, %rdi
movl $0x1, %esi
callq 0xf09dd
movl %eax, 0x88(%r14)
movq %r13, %rdi
movl $0x1, %esi
callq 0xf09dd
testl %eax, %eax
je 0xd2b81
movq %r13, %rdi
movl $0x1, %esi
callq 0xf09dd
movl %eax, 0x8c(%r14)
xorl %ebp, %ebp
movq %r13, %rdi
movl $0x1, %esi
callq 0xf09dd
testl %eax, %eax
je 0xd2b39
movq %r13, %rdi
movl $0x7, %esi
callq 0xf0ada
jmp 0xd2b3b
xorl %eax, %eax
movb %al, 0x90(%r14,%rbp)
incq %rbp
cmpq $0x4, %rbp
jne 0xd2b19
xorl %ebp, %ebp
movq %r13, %rdi
movl $0x1, %esi
callq 0xf09dd
testl %eax, %eax
je 0xd2b6e
movq %r13, %rdi
movl $0x6, %esi
callq 0xf0ada
jmp 0xd2b70
xorl %eax, %eax
movb %al, 0x94(%r14,%rbp)
incq %rbp
cmpq $0x4, %rbp
jne 0xd2b4e
cmpl $0x0, 0x88(%r14)
je 0xd2beb
movq $-0x3, %rbp
movq %r13, %rdi
movl $0x1, %esi
callq 0xf09dd
testl %eax, %eax
je 0xd2bb2
movq %r13, %rdi
movl $0x8, %esi
callq 0xf09dd
jmp 0xd2bb4
movb $-0x1, %al
movb %al, 0x4ab(%r14,%rbp)
incq %rbp
jne 0xd2b92
jmp 0xd2beb
cmpl $0x0, (%r14)
jne 0xd289f
movq $0x3, (%r14)
leaq 0x577e2(%rip), %rax     # 0x12a3bd
jmp 0xd289b
movl $0x0, 0x88(%r14)
cmpl $0x0, 0x38(%r14)
je 0xd2c0f
cmpl $0x0, (%r14)
jne 0xd289f
movq $0x3, (%r14)
leaq 0x577d6(%rip), %rax     # 0x12a3e0
jmp 0xd289b
movq %r13, %rdi
movq %r14, %rsi
callq 0xd2cc3
testl %eax, %eax
je 0xd2c50
movq (%rsp), %rax
addq %rax, %r12
subq %rax, %r15
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xd2dad
testl %eax, %eax
je 0xd2c6d
leaq 0x577d6(%rip), %rdx     # 0x12a417
movq %r14, %rdi
movl %eax, %esi
callq 0xd2755
jmp 0xd289f
cmpl $0x0, (%r14)
jne 0xd289f
movq $0x3, (%r14)
leaq 0x57794(%rip), %rax     # 0x12a3fc
jmp 0xd289b
movq %r14, %rdi
callq 0xf287c
cmpb $0x0, 0x44(%r14)
je 0xd2ca6
movl $0x1, %ebx
movq %r13, %rdi
movl $0x1, %esi
callq 0xf09dd
movq %r13, %rdi
movq %r14, %rsi
callq 0xf353b
movl $0x1, 0x4(%r14)
jmp 0xd289f
cmpl $0x0, (%r14)
jne 0xd289f
movq $0x4, (%r14)
leaq 0x57771(%rip), %rax     # 0x12a42f
jmp 0xd289b