// File: /workspace/github_c_makefile_star2_O0/Paxa[P]fast_excel/libxlsxwriter/third_party/minizip/zip.c
// Function: zipRemoveExtraInfoBlock
extern int ZEXPORT zipRemoveExtraInfoBlock(char* pData, int* dataLen, short sHeader) {
  char* p = pData;
  int size = 0;
  char* pNewHeader;
  char* pTmp;
  short header;
  short dataSize;

  int retVal = ZIP_OK;

  if(pData == NULL || dataLen == NULL || *dataLen < 4)
    return ZIP_PARAMERROR;

  pNewHeader = (char*)ALLOC((unsigned)*dataLen);
  pTmp = pNewHeader;

  while(p < (pData + *dataLen))
  {
    header = *(short*)p;
    dataSize = *(((short*)p)+1);

    if( header == sHeader ) // Header found.
    {
      p += dataSize + 4; // skip it. do not copy to temp buffer
    }
    else
    {
      // Extra Info block should not be removed, So copy it to the temp buffer.
      memcpy(pTmp, p, dataSize + 4);
      p += dataSize + 4;
      size += dataSize + 4;
    }

  }

  if(size < *dataLen)
  {
    // clean old extra info block.
    memset(pData,0, *dataLen);

    // copy the new extra info block over the old
    if(size > 0)
      memcpy(pData, pNewHeader, size);

    // set the new extra info size
    *dataLen = size;

    retVal = ZIP_OK;
  }
  else
    retVal = ZIP_ERRNO;

  free(pNewHeader);

  return retVal;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movw %dx, %ax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movw %ax, -0x1a(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x48(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x10af4
cmpq $0x0, -0x18(%rbp)
je 0x10af4
movq -0x18(%rbp), %rax
cmpl $0x4, (%rax)
jge 0x10b00
movl $0xffffff9a, -0x4(%rbp) # imm = 0xFFFFFF9A
jmp 0x10c04
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, %edi
callq 0xcaf0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rdx
movslq (%rdx), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x10ba8
movq -0x28(%rbp), %rax
movw (%rax), %ax
movw %ax, -0x42(%rbp)
movq -0x28(%rbp), %rax
movw 0x2(%rax), %ax
movw %ax, -0x44(%rbp)
movswl -0x42(%rbp), %eax
movswl -0x1a(%rbp), %ecx
cmpl %ecx, %eax
jne 0x10b6a
movswl -0x44(%rbp), %ecx
addl $0x4, %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
jmp 0x10ba3
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rsi
movswl -0x44(%rbp), %eax
addl $0x4, %eax
movslq %eax, %rdx
callq 0xc980
movswl -0x44(%rbp), %ecx
addl $0x4, %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movswl -0x44(%rbp), %eax
addl $0x4, %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x10b19
movl -0x2c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x10bee
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq (%rax), %rdx
xorl %esi, %esi
callq 0xc6a0
cmpl $0x0, -0x2c(%rbp)
jle 0x10bdc
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movslq -0x2c(%rbp), %rdx
callq 0xc980
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x48(%rbp)
jmp 0x10bf5
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movq -0x38(%rbp), %rdi
callq 0xc0d0
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)