// File: /workspace/github_c_makefile_star2_O2/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 $0x68, %rsp
movq %rcx, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq %rsi, %r12
movq %rdi, %r13
movq 0xa8(%rsp), %r15
testq %r15, %r15
je 0xc69dc
cmpl $0x0, 0x10(%r15)
setne %r10b
jmp 0xc69df
xorl %r10d, %r10d
testq %r13, %r13
sete %al
cmpq $0xc, %r12
setb %dl
orb %al, %dl
pushq $0x7
popq %rbp
jne 0xc6cf7
cmpl $0x46464952, (%r13)     # imm = 0x46464952
setne %dil
pushq $0x3
popq %rdx
je 0xc6ac5
movq $0x0, 0x40(%rsp)
movq %r8, %r11
movq %r13, %r14
xorl %eax, %eax
movq %r12, %rbx
cmpl $0x58385056, (%r14)     # imm = 0x58385056
setne %cl
je 0xc6b26
movl $0x0, 0x24(%rsp)
xorl %esi, %esi
xorl %r8d, %r8d
movb %cl, %r8b
testl %r8d, %r8d
sete %cl
testb %cl, %dil
jne 0xc6cf5
movl %r8d, 0x4c(%rsp)
movq %rax, 0x18(%rsp)
movq %r11, %r8
testq %r11, %r11
je 0xc6a6c
movl %esi, %eax
shrl $0x4, %eax
andl $0x1, %eax
movl %eax, (%r8)
andl $0x2, %esi
movq 0xa0(%rsp), %rdx
testq %r9, %r9
je 0xc6a83
movl %esi, %eax
shrl %eax
movl %eax, (%r9)
movb %cl, 0x28(%rsp)
testq %rdx, %rdx
je 0xc6a8f
andl $0x0, (%rdx)
movl %esi, 0xc(%rsp)
testl %esi, %esi
setne %al
movq 0x40(%rsp), %rdx
movl %edx, 0x14(%rsp)
movl 0x24(%rsp), %ecx
movl %ecx, 0x10(%rsp)
testq %r15, %r15
movb 0x28(%rsp), %cl
jne 0xc6b7b
andb %cl, %al
je 0xc6b7b
xorl %ecx, %ecx
jmp 0xc6d82
cmpl $0x50424557, 0x8(%r13)  # imm = 0x50424557
jne 0xc6cf5
movl 0x4(%r13), %r11d
leal 0x9(%r11), %eax
cmpl $0x15, %eax
jb 0xc6cf5
leaq -0x8(%r12), %rax
movq %r11, 0x18(%rsp)
cmpq %r11, %rax
setb %al
leaq -0xc(%r12), %rbx
cmpq $0x8, %rbx
jb 0xc6cf7
andb %r10b, %al
jne 0xc6cf7
movq $0x0, 0x40(%rsp)
movq %r8, %r11
leaq 0xc(%r13), %r14
movq 0x18(%rsp), %rax
jmp 0xc6a20
cmpl $0xa, 0x4(%r14)
jne 0xc6cf5
cmpq $0x12, %rbx
jb 0xc6cf7
movq %rax, 0x18(%rsp)
movzwl 0xc(%r14), %eax
movzbl 0xe(%r14), %edx
shll $0x10, %edx
addl %edx, %eax
incl %eax
movzwl 0xf(%r14), %esi
movzbl 0x11(%r14), %edx
shll $0x10, %edx
addl %esi, %edx
incl %edx
movq %rax, 0x40(%rsp)
movl %edx, 0x24(%rsp)
mull %edx
jno 0xc6c0e
pushq $0x3
popq %rbp
jmp 0xc6cf7
cmpq $0x4, %rbx
jae 0xc6b88
xorl %ecx, %ecx
jmp 0xc6d6d
xorl %esi, %esi
movb %dil, %sil
testl %esi, %esi
sete %al
testb %cl, %al
je 0xc6c27
pushq $0x16
popq %rax
xorl %ecx, %ecx
xorl %r9d, %r9d
cmpq $0x8, %rbx
jb 0xc6d6d
movl 0x4(%r14), %edi
movl $0xfffffff6, %edx       # imm = 0xFFFFFFF6
cmpq %rdx, %rdi
ja 0xc6b73
movq %r8, %r11
leal 0x9(%rdi), %r8d
andl $-0x2, %r8d
addl %r8d, %eax
testl %esi, %esi
jne 0xc6bd2
cmpl %eax, 0x18(%rsp)
jb 0xc6b73
cmpl $0x20385056, (%r14)     # imm = 0x20385056
je 0xc6c48
cmpl $0x4c385056, (%r14)     # imm = 0x4C385056
je 0xc6c48
subq %r8, %rbx
jb 0xc6d6a
movq %r9, %rdx
leaq 0x8(%r14), %r9
cmpl $0x48504c41, (%r14)     # imm = 0x48504C41
cmoveq %r9, %rcx
movq %rdx, %r9
cmoveq %rdi, %r9
addq %r8, %r14
movq %r11, %r8
jmp 0xc6ba2
movl 0x8(%r14), %esi
addq $0x12, %r14
addq $-0x12, %rbx
pushq $0x3
popq %rdx
movq 0x18(%rsp), %rax
jmp 0xc6a3a
testl %esi, %esi
sete %al
xorl %ecx, %ecx
orb 0x28(%rsp), %al
jne 0xc6c43
xorl %ecx, %ecx
cmpl $0x48504c41, (%r14)     # imm = 0x48504C41
je 0xc6b9a
xorl %r9d, %r9d
jmp 0xc6c4b
movq %r11, %r8
xorl %edx, %edx
xorl %eax, %eax
cmpl $0x4c385056, (%r14)     # imm = 0x4C385056
setne %sil
sete %dil
cmpq $0x8, %rbx
jb 0xc6d6d
movb %sil, %dl
testl %edx, %edx
sete %dl
cmpl $0x20385056, (%r14)     # imm = 0x20385056
sete %sil
orb %dl, %sil
cmpb $0x1, %sil
jne 0xc6cc1
movl 0x4(%r14), %r11d
movq 0x18(%rsp), %rdx
cmpq $0xc, %rdx
jb 0xc6ca0
addq $-0xc, %rdx
cmpq %r11, %rdx
jb 0xc6b73
addq $-0x8, %rbx
cmpq %r11, %rbx
setb %dl
testb %dl, %r10b
jne 0xc6d6d
movq %r9, 0x50(%rsp)
movb %dil, %al
addq $0x8, %r14
jmp 0xc6ce8
movq %r9, 0x50(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r8, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
callq 0x59620
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %r8
movq %rbx, %r11
movl $0xfffffff6, %edx       # imm = 0xFFFFFFF6
cmpq %rdx, %r11
pushq $0x3
popq %rdx
jbe 0xc6d08
movl %edx, %ebp
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0xa0(%rsp)
je 0xc6d2d
cmpl $0x0, 0xc(%rsp)
jne 0xc6d2d
cmpl $0x1, %eax
pushq $0x2
popq %rdi
sbbl $0x0, %edi
movq 0xa0(%rsp), %rsi
movl %edi, (%rsi)
testl %eax, %eax
je 0xc6dc3
cmpq $0x5, %rbx
jb 0xc6d6d
movq %r11, 0x28(%rsp)
movl %eax, 0xc(%rsp)
movq %rcx, 0x30(%rsp)
movl %edx, %ebp
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r14, %rdi
movq %rbx, %rsi
movq %r8, 0x38(%rsp)
callq 0x59c50
jmp 0xc6df6
movq %r11, %r8
testq %r15, %r15
setne %al
movb 0x28(%rsp), %dl
xorb $0x1, %dl
orb %al, %dl
jne 0xc6cf7
testq %r8, %r8
je 0xc6d92
xorl %eax, %eax
testq %rcx, %rcx
setne %al
orl %eax, (%r8)
cmpq $0x0, 0x58(%rsp)
je 0xc6da5
movl 0x14(%rsp), %eax
movq 0x58(%rsp), %rcx
movl %eax, (%rcx)
xorl %ebp, %ebp
cmpq $0x0, 0x60(%rsp)
je 0xc6cf7
movl 0x10(%rsp), %eax
movq 0x60(%rsp), %rcx
movl %eax, (%rcx)
jmp 0xc6cf7
cmpq $0xa, %rbx
jb 0xc6d6d
movl %eax, 0xc(%rsp)
movq %rcx, 0x30(%rsp)
movl %edx, %ebp
movq %r8, 0x38(%rsp)
leaq 0x14(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r14, %rdi
movq %rbx, %rsi
movq %r11, 0x28(%rsp)
movq %r11, %rdx
callq 0x59980
testl %eax, %eax
je 0xc6cf7
cmpl $0x0, 0x4c(%rsp)
movq 0x38(%rsp), %r8
movq 0x18(%rsp), %rax
movq 0x30(%rsp), %rcx
movq 0x50(%rsp), %rdi
movq 0x28(%rsp), %r9
jne 0xc6e41
movq 0x40(%rsp), %rdx
cmpl 0x14(%rsp), %edx
jne 0xc6cf7
movq %rcx, %rsi
movl 0x24(%rsp), %ecx
cmpl 0x10(%rsp), %ecx
movq %rsi, %rcx
jne 0xc6cf7
testq %r15, %r15
je 0xc6d82
movq %r13, (%r15)
movq %r12, 0x8(%r15)
andq $0x0, 0x10(%r15)
movq %rcx, 0x20(%r15)
movq %rdi, 0x28(%r15)
movq %r9, 0x30(%r15)
movq %rax, 0x38(%r15)
movl 0xc(%rsp), %eax
movl %eax, 0x40(%r15)
andl $0x0, 0x44(%r15)
subq %r13, %r14
movq %r14, 0x18(%r15)
movl $0xfffffff6, %eax       # imm = 0xFFFFFFF6
cmpq %rax, %r14
jae 0xc6eaf
subq %rbx, %r12
cmpq %r12, %r14
je 0xc6d82
leaq 0x51a62(%rip), %rdi     # 0x1188f9
leaq 0x518bc(%rip), %rsi     # 0x11875a
leaq 0x519c0(%rip), %rcx     # 0x118865
movl $0x18f, %edx            # imm = 0x18F
callq 0x56770
leaq 0x5197a(%rip), %rdi     # 0x118830
leaq 0x5189d(%rip), %rsi     # 0x11875a
leaq 0x519a1(%rip), %rcx     # 0x118865
movl $0x18e, %edx            # imm = 0x18E
callq 0x56770