// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/libraries/libwebp/src/dec/webp_dec.c
// Function: ParseHeadersInternal
static VP8StatusCode ParseHeadersInternal(const uint8_t* data,
                                          size_t data_size,
                                          int* const width,
                                          int* const height,
                                          int* const has_alpha,
                                          int* const has_animation,
                                          int* const format,
                                          WebPHeaderStructure* const headers) {
  int canvas_width = 0;
  int canvas_height = 0;
  int image_width = 0;
  int image_height = 0;
  int found_riff = 0;
  int found_vp8x = 0;
  int animation_present = 0;
  const int have_all_data = (headers != NULL) ? headers->have_all_data : 0;

  VP8StatusCode status;
  WebPHeaderStructure hdrs;

  if (data == NULL || data_size < RIFF_HEADER_SIZE) {
    return VP8_STATUS_NOT_ENOUGH_DATA;
  }
  memset(&hdrs, 0, sizeof(hdrs));
  hdrs.data = data;
  hdrs.data_size = data_size;

  // Skip over RIFF header.
  status = ParseRIFF(&data, &data_size, have_all_data, &hdrs.riff_size);
  if (status != VP8_STATUS_OK) {
    return status;   // Wrong RIFF header / insufficient data.
  }
  found_riff = (hdrs.riff_size > 0);

  // Skip over VP8X.
  {
    uint32_t flags = 0;
    status = ParseVP8X(&data, &data_size, &found_vp8x,
                       &canvas_width, &canvas_height, &flags);
    if (status != VP8_STATUS_OK) {
      return status;  // Wrong VP8X / insufficient data.
    }
    animation_present = !!(flags & ANIMATION_FLAG);
    if (!found_riff && found_vp8x) {
      // Note: This restriction may be removed in the future, if it becomes
      // necessary to send VP8X chunk to the decoder.
      return VP8_STATUS_BITSTREAM_ERROR;
    }
    if (has_alpha != NULL) *has_alpha = !!(flags & ALPHA_FLAG);
    if (has_animation != NULL) *has_animation = animation_present;
    if (format != NULL) *format = 0;   // default = undefined

    image_width = canvas_width;
    image_height = canvas_height;
    if (found_vp8x && animation_present && headers == NULL) {
      status = VP8_STATUS_OK;
      goto ReturnWidthHeight;  // Just return features from VP8X header.
    }
  }

  if (data_size < TAG_SIZE) {
    status = VP8_STATUS_NOT_ENOUGH_DATA;
    goto ReturnWidthHeight;
  }

  // Skip over optional chunks if data started with "RIFF + VP8X" or "ALPH".
  if ((found_riff && found_vp8x) ||
      (!found_riff && !found_vp8x && !memcmp(data, "ALPH", TAG_SIZE))) {
    status = ParseOptionalChunks(&data, &data_size, hdrs.riff_size,
                                 &hdrs.alpha_data, &hdrs.alpha_data_size);
    if (status != VP8_STATUS_OK) {
      goto ReturnWidthHeight;  // Invalid chunk size / insufficient data.
    }
  }

  // Skip over VP8/VP8L header.
  status = ParseVP8Header(&data, &data_size, have_all_data, hdrs.riff_size,
                          &hdrs.compressed_size, &hdrs.is_lossless);
  if (status != VP8_STATUS_OK) {
    goto ReturnWidthHeight;  // Wrong VP8/VP8L chunk-header / insufficient data.
  }
  if (hdrs.compressed_size > MAX_CHUNK_PAYLOAD) {
    return VP8_STATUS_BITSTREAM_ERROR;
  }

  if (format != NULL && !animation_present) {
    *format = hdrs.is_lossless ? 2 : 1;
  }

  if (!hdrs.is_lossless) {
    if (data_size < VP8_FRAME_HEADER_SIZE) {
      status = VP8_STATUS_NOT_ENOUGH_DATA;
      goto ReturnWidthHeight;
    }
    // Validates raw VP8 data.
    if (!VP8GetInfo(data, data_size, (uint32_t)hdrs.compressed_size,
                    &image_width, &image_height)) {
      return VP8_STATUS_BITSTREAM_ERROR;
    }
  } else {
    if (data_size < VP8L_FRAME_HEADER_SIZE) {
      status = VP8_STATUS_NOT_ENOUGH_DATA;
      goto ReturnWidthHeight;
    }
    // Validates raw VP8L data.
    if (!VP8LGetInfo(data, data_size, &image_width, &image_height, has_alpha)) {
      return VP8_STATUS_BITSTREAM_ERROR;
    }
  }
  // Validates image size coherency.
  if (found_vp8x) {
    if (canvas_width != image_width || canvas_height != image_height) {
      return VP8_STATUS_BITSTREAM_ERROR;
    }
  }
  if (headers != NULL) {
    *headers = hdrs;
    headers->offset = data - headers->data;
    assert((uint64_t)(data - headers->data) < MAX_CHUNK_PAYLOAD);
    assert(headers->offset == headers->data_size - data_size);
  }
 ReturnWidthHeight:
  if (status == VP8_STATUS_OK ||
      (status == VP8_STATUS_NOT_ENOUGH_DATA && found_vp8x && headers == NULL)) {
    if (has_alpha != NULL) {
      // If the data did not contain a VP8X/VP8L chunk the only definitive way
      // to set this is by looking for alpha data (from an ALPH chunk).
      *has_alpha |= (hdrs.alpha_data != NULL);
    }
    if (width != NULL) *width = image_width;
    if (height != NULL) *height = image_height;
    return VP8_STATUS_OK;
  } else {
    return status;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r8, %r15
movq %rcx, %r11
movq %rdx, %r14
movq 0xc8(%rsp), %r12
movq %rdi, 0x20(%rsp)
movq %rsi, 0x28(%rsp)
xorl %ebp, %ebp
movl %ebp, 0x1c(%rsp)
movl %ebp, 0x18(%rsp)
testq %r12, %r12
je 0xce457
movl 0x10(%r12), %ebp
testq %rdi, %rdi
sete %al
cmpq $0xc, %rsi
setb %cl
orb %al, %cl
movl $0x7, %r13d
jne 0xce508
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
xorl %eax, %eax
movq %rax, 0x80(%rsp)
movq %rdi, 0x40(%rsp)
movq %rsi, 0x48(%rsp)
movq %rax, 0x78(%rsp)
cmpl $0x46464952, (%rdi)     # imm = 0x46464952
je 0xce4af
xorl %r13d, %r13d
jmp 0xce503
cmpl $0x50424557, 0x8(%rdi)  # imm = 0x50424557
movl $0x3, %r13d
jne 0xce503
movl 0x4(%rdi), %eax
leal 0x9(%rax), %ecx
cmpl $0x15, %ecx
jae 0xce4cd
xorl %eax, %eax
jmp 0xce4ff
movl %eax, %eax
testl %ebp, %ebp
je 0xce4e6
leaq -0x8(%rsi), %rcx
cmpq %rax, %rcx
jae 0xce4e6
xorl %eax, %eax
movl $0x7, %r13d
jmp 0xce4ff
movq %rax, 0x78(%rsp)
addq $0xc, %rdi
movq %rdi, 0x20(%rsp)
addq $-0xc, %rsi
movq %rsi, 0x28(%rsp)
movb $0x1, %al
testb %al, %al
jne 0xce4aa
testl %r13d, %r13d
je 0xce51d
movl %r13d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%rsp), %rsi
cmpq $0x8, %rsi
jae 0xce552
movb $0x1, %bl
movl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
xorl %eax, %eax
xorl %r8d, %r8d
movl $0x7, %r13d
jmp 0xce62c
movq 0x20(%rsp), %rdi
cmpl $0x58385056, (%rdi)     # imm = 0x58385056
movb $0x1, %bl
je 0xce586
movl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
xorl %eax, %eax
movb $0x1, %r8b
xorl %r13d, %r13d
jmp 0xce62c
movl $0x3, %r13d
cmpl $0xa, 0x4(%rdi)
jne 0xce60f
cmpq $0x12, %rsi
jb 0xce52a
movzwl 0xc(%rdi), %eax
movzbl 0xe(%rdi), %ecx
shll $0x10, %ecx
addl %eax, %ecx
incl %ecx
movzwl 0xf(%rdi), %eax
movzbl 0x11(%rdi), %edx
shll $0x10, %edx
leal (%rax,%rdx), %r10d
incl %r10d
movl $0x0, 0x14(%rsp)
movl %ecx, %eax
mull %r10d
movl $0x0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
movl $0x0, %eax
movl $0x0, %r8d
jo 0xce62c
movzbl 0x8(%rdi), %eax
addq $0x12, %rdi
movq %rdi, 0x20(%rsp)
addq $-0x12, %rsi
movq %rsi, 0x28(%rsp)
xorl %ebx, %ebx
movb $0x1, %dl
movl %edx, 0xc(%rsp)
movl %ecx, 0x14(%rsp)
movl %r10d, 0x10(%rsp)
jmp 0xce57b
movl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
xorl %eax, %eax
xorl %r8d, %r8d
movq 0x78(%rsp), %rdx
movl $0x1, %ecx
testb %r8b, %r8b
movl %ebx, 0x3c(%rsp)
je 0xce6c3
testq %rdx, %rdx
sete %dil
movl %eax, %esi
andl $0x2, %esi
movl %esi, %r10d
shrl %r10d
movl %ebx, %r8d
xorb $0x1, %r8b
xorl %ebx, %ebx
movl $0x3, %r13d
testb %r8b, %dil
jne 0xce6c9
testq %r15, %r15
je 0xce677
shrl $0x4, %eax
andl $0x1, %eax
movl %eax, (%r15)
testq %r9, %r9
movq 0xc0(%rsp), %rax
je 0xce687
movl %r10d, (%r9)
testq %rax, %rax
je 0xce692
movl $0x0, (%rax)
testl %esi, %esi
setne %al
testq %r12, %r12
sete %cl
movl 0x14(%rsp), %esi
movl %esi, 0x1c(%rsp)
movl 0x10(%rsp), %esi
movl %esi, 0x18(%rsp)
andb 0xc(%rsp), %al
andb %cl, %al
movl $0x1, %ecx
cmovnel %ecx, %r10d
movzbl %al, %ecx
addl %ecx, %ecx
jmp 0xce6c9
movl %r13d, %ebx
xorl %r10d, %r10d
cmpl $0x2, %ecx
je 0xce762
testl %ecx, %ecx
jne 0xce508
movl $0x7, %ebx
cmpq $0x4, 0x28(%rsp)
jb 0xce762
movl %r10d, 0x38(%rsp)
movq %r11, 0x30(%rsp)
testq %rdx, %rdx
setne %al
testb %al, 0xc(%rsp)
je 0xce71c
leaq 0x60(%rsp), %rcx
leaq 0x68(%rsp), %r8
leaq 0x20(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xcf3d6
testl %eax, %eax
jne 0xce75b
jmp 0xce735
testq %rdx, %rdx
setne %al
orb 0xc(%rsp), %al
jne 0xce735
movq 0x20(%rsp), %rax
cmpl $0x48504c41, (%rax)     # imm = 0x48504C41
je 0xce6fd
leaq 0x70(%rsp), %r8
movq 0x8(%r8), %rcx
leaq 0x80(%rsp), %r9
leaq 0x20(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movl %ebp, %edx
callq 0xcf532
testl %eax, %eax
je 0xce7bb
movl %eax, %ebx
movq 0x30(%rsp), %r11
testl %ebx, %ebx
je 0xce784
cmpl $0x7, %ebx
sete %al
movl %ebx, %r13d
testq %r12, %r12
jne 0xce508
movl 0xc(%rsp), %ecx
andb %al, %cl
je 0xce508
testq %r15, %r15
je 0xce797
xorl %eax, %eax
cmpq $0x0, 0x60(%rsp)
setne %al
orl %eax, (%r15)
testq %r14, %r14
je 0xce7a3
movl 0x1c(%rsp), %eax
movl %eax, (%r14)
xorl %r13d, %r13d
testq %r11, %r11
je 0xce508
movl 0x18(%rsp), %eax
movl %eax, (%r11)
jmp 0xce508
movl $0xfffffff6, %ebp       # imm = 0xFFFFFFF6
movq 0x70(%rsp), %rdx
movl $0x3, %r13d
cmpq %rbp, %rdx
movq 0x30(%rsp), %r11
ja 0xce508
movq 0xc0(%rsp), %rcx
testq %rcx, %rcx
je 0xce7ff
cmpl $0x0, 0x38(%rsp)
jne 0xce7ff
cmpl $0x1, 0x80(%rsp)
movl $0x2, %eax
sbbl $0x0, %eax
movl %eax, (%rcx)
cmpl $0x0, 0x80(%rsp)
movq 0x28(%rsp), %rsi
je 0xce831
cmpq $0x5, %rsi
jb 0xce762
movq 0x20(%rsp), %rdi
leaq 0x1c(%rsp), %rdx
leaq 0x18(%rsp), %rcx
movq %r15, %r8
callq 0x58920
jmp 0xce84f
cmpq $0xa, %rsi
jb 0xce762
movq 0x20(%rsp), %rdi
leaq 0x1c(%rsp), %rcx
leaq 0x18(%rsp), %r8
callq 0x58690
testl %eax, %eax
je 0xce508
cmpb $0x0, 0x3c(%rsp)
movq 0x30(%rsp), %r11
jne 0xce87f
movl 0x14(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jne 0xce508
movl 0x10(%rsp), %eax
cmpl 0x18(%rsp), %eax
jne 0xce508
xorl %ebx, %ebx
testq %r12, %r12
je 0xce762
leaq 0x40(%rsp), %rsi
movl $0x9, %ecx
movq %r12, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq 0x20(%rsp), %rax
subq (%r12), %rax
movq %rax, 0x18(%r12)
cmpq %rbp, %rax
jae 0xce8df
movq 0x8(%r12), %rcx
subq 0x28(%rsp), %rcx
cmpq %rcx, %rax
je 0xce762
leaq 0x5af92(%rip), %rdi     # 0x129859
leaq 0x5adec(%rip), %rsi     # 0x1296ba
leaq 0x5aef0(%rip), %rcx     # 0x1297c5
movl $0x18f, %edx            # imm = 0x18F
callq 0x55710
leaq 0x5aeaa(%rip), %rdi     # 0x129790
leaq 0x5adcd(%rip), %rsi     # 0x1296ba
leaq 0x5aed1(%rip), %rcx     # 0x1297c5
movl $0x18e, %edx            # imm = 0x18E
callq 0x55710