// File: /workspace/github_c_makefile_star2_O3/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 $0x78, %rsp
movq %r8, %r15
movq %rcx, %rbx
movq %rdx, %r14
movq 0xb8(%rsp), %r12
movq %rdi, 0x10(%rsp)
movq %rsi, 0x28(%rsp)
testq %r12, %r12
je 0xcd610
movl 0x10(%r12), %ebp
jmp 0xcd612
xorl %ebp, %ebp
testq %rdi, %rdi
sete %al
cmpq $0xc, %rsi
setb %cl
orb %al, %cl
je 0xcd63b
movl $0x7, %r13d
movl %r13d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
movups %xmm0, 0x60(%rsp)
movups %xmm0, 0x50(%rsp)
movups %xmm0, 0x40(%rsp)
movq $0x0, 0x70(%rsp)
movq %rdi, 0x30(%rsp)
movq %rsi, 0x38(%rsp)
xorl %eax, %eax
xorl %r8d, %r8d
cmpl $0x46464952, (%rdi)     # imm = 0x46464952
setne %dl
je 0xcd740
xorl %ecx, %ecx
movb %dl, %r8b
xorl %r11d, %r11d
cmpl $0x58385056, (%rdi)     # imm = 0x58385056
setne %r10b
je 0xcd79d
movl $0x0, 0x20(%rsp)
xorl %edx, %edx
movl $0x0, 0x24(%rsp)
xorl %r13d, %r13d
testq %r15, %r15
je 0xcd6af
shrl $0x4, %edx
andl $0x1, %edx
movl %edx, (%r15)
movq 0xb0(%rsp), %rdx
testq %r9, %r9
je 0xcd6cb
movl 0x20(%rsp), %edx
movl %edx, (%r9)
movq 0xb0(%rsp), %rdx
testq %rdx, %rdx
je 0xcd6d6
movl $0x0, (%rdx)
testq %r12, %r12
sete %dl
movl %r13d, 0x1c(%rsp)
movl %r13d, 0xc(%rsp)
movl 0x24(%rsp), %r9d
movl %r9d, 0x8(%rsp)
testb %al, %dl
jne 0xcd854
movb %r10b, %r11b
movl $0x7, %eax
cmpq $0x4, %rsi
jb 0xcd83e
movl %r8d, %eax
orl %r11d, %eax
movl %r11d, 0x4(%rsp)
je 0xcd7ee
testl %r8d, %r8d
je 0xcd816
testl %r11d, %r11d
je 0xcd816
cmpl $0x48504c41, (%rdi)     # imm = 0x48504C41
je 0xcd7ee
xorl %ecx, %ecx
jmp 0xcd816
cmpl $0x50424557, 0x8(%rdi)  # imm = 0x50424557
movl $0x3, %r13d
jne 0xcd629
movl 0x4(%rdi), %ecx
leal 0x9(%rcx), %r10d
cmpl $0x15, %r10d
jb 0xcd629
movl %ecx, %ecx
testl %ebp, %ebp
je 0xcd777
leaq -0x8(%rsi), %r10
cmpq %rcx, %r10
jb 0xcd623
movq %rcx, 0x68(%rsp)
addq $0xc, %rdi
movq %rdi, 0x10(%rsp)
addq $-0xc, %rsi
movq %rsi, 0x28(%rsp)
cmpq $0x8, %rsi
jb 0xcd623
jmp 0xcd676
cmpl $0xa, 0x4(%rdi)
jne 0xcd7e3
movl $0x7, %r13d
cmpq $0x12, %rsi
jb 0xcd629
movzwl 0xc(%rdi), %eax
movzbl 0xe(%rdi), %edx
shll $0x10, %edx
leal (%rdx,%rax), %r13d
incl %r13d
movzwl 0xf(%rdi), %eax
movzbl 0x11(%rdi), %edx
shll $0x10, %edx
addl %eax, %edx
incl %edx
movl %r13d, %eax
movl %edx, 0x24(%rsp)
mull %edx
jno 0xcd892
movl $0x3, %r13d
jmp 0xcd629
leaq 0x50(%rsp), %rax
leaq 0x58(%rsp), %r8
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movq %rcx, %rdx
movq %rax, %rcx
callq 0xce4d6
testl %eax, %eax
jne 0xcd839
movq 0x68(%rsp), %rcx
leaq 0x60(%rsp), %r8
leaq 0x70(%rsp), %r9
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movl %ebp, %edx
callq 0xce606
testl %eax, %eax
je 0xcd8d0
movl 0x4(%rsp), %r11d
testq %r12, %r12
jne 0xcd88a
testl %r11d, %r11d
jne 0xcd88a
movl %eax, %r13d
cmpl $0x7, %eax
jne 0xcd629
testq %r15, %r15
je 0xcd867
xorl %eax, %eax
cmpq $0x0, 0x50(%rsp)
setne %al
orl %eax, (%r15)
testq %r14, %r14
je 0xcd873
movl 0xc(%rsp), %eax
movl %eax, (%r14)
xorl %r13d, %r13d
testq %rbx, %rbx
je 0xcd629
movl 0x8(%rsp), %eax
movl %eax, (%rbx)
jmp 0xcd629
movl %eax, %r13d
jmp 0xcd629
movl %r13d, 0x1c(%rsp)
movl 0x8(%rdi), %edx
addq $0x12, %rdi
movq %rdi, 0x10(%rsp)
addq $-0x12, %rsi
movq %rsi, 0x28(%rsp)
movl $0x3, %r13d
testl %r8d, %r8d
jne 0xcd629
movl %edx, %eax
andl $0x2, %eax
shrl %eax
movl %eax, 0x20(%rsp)
movl 0x1c(%rsp), %r13d
jmp 0xcd6a1
movl $0xfffffff6, %ebp       # imm = 0xFFFFFFF6
movq 0x60(%rsp), %rdx
movl $0x3, %r13d
cmpq %rbp, %rdx
ja 0xcd629
movl 0x70(%rsp), %eax
cmpq $0x0, 0xb0(%rsp)
je 0xcd914
cmpl $0x0, 0x20(%rsp)
jne 0xcd914
cmpl $0x1, %eax
movl $0x2, %ecx
sbbl $0x0, %ecx
movq 0xb0(%rsp), %rsi
movl %ecx, (%rsi)
movq 0x28(%rsp), %rsi
testl %eax, %eax
movl 0x4(%rsp), %r11d
movl $0x7, %eax
je 0xcd94a
cmpq $0x5, %rsi
jb 0xcd83e
movq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r15, %r8
callq 0x58920
jmp 0xcd968
cmpq $0xa, %rsi
jb 0xcd83e
movq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x58690
testl %eax, %eax
je 0xcd629
cmpl $0x0, 0x4(%rsp)
jne 0xcd993
movl 0x1c(%rsp), %eax
cmpl 0xc(%rsp), %eax
jne 0xcd629
movl 0x24(%rsp), %eax
cmpl 0x8(%rsp), %eax
jne 0xcd629
testq %r12, %r12
je 0xcd854
leaq 0x30(%rsp), %rsi
movl $0x9, %ecx
movq %r12, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq 0x10(%rsp), %rax
subq (%r12), %rax
movq %rax, 0x18(%r12)
cmpq %rbp, %rax
jae 0xcd9f1
movq 0x8(%r12), %rcx
subq 0x28(%rsp), %rcx
cmpq %rcx, %rax
je 0xcd854
leaq 0x5b0a0(%rip), %rdi     # 0x128a79
leaq 0x5aefa(%rip), %rsi     # 0x1288da
leaq 0x5affe(%rip), %rcx     # 0x1289e5
movl $0x18f, %edx            # imm = 0x18F
callq 0x55710
leaq 0x5afb8(%rip), %rdi     # 0x1289b0
leaq 0x5aedb(%rip), %rsi     # 0x1288da
leaq 0x5afdf(%rip), %rcx     # 0x1289e5
movl $0x18e, %edx            # imm = 0x18E
callq 0x55710