// File: /workspace/github_c_makefile_star2_O0/Paxa[P]fast_excel/libxlsxwriter/third_party/minizip/zip.c
// Function: LoadCentralDirectoryRecord
local int LoadCentralDirectoryRecord(zip64_internal* pziinit) {
  int err=ZIP_OK;
  ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/

  ZPOS64_T size_central_dir;     /* size of the central directory  */
  ZPOS64_T offset_central_dir;   /* offset of start of central directory */
  ZPOS64_T central_pos;
  uLong uL;

  uLong number_disk;          /* number of the current dist, used for
                              spanning ZIP, unsupported, always 0*/
  uLong number_disk_with_CD;  /* number the the disk with central dir, used
                              for spanning ZIP, unsupported, always 0*/
  ZPOS64_T number_entry;
  ZPOS64_T number_entry_CD;      /* total number of entries in
                                the central dir
                                (same than number_entry on nospan) */
  uLong VersionMadeBy;
  uLong VersionNeeded;
  uLong size_comment;

  int hasZIP64Record = 0;

  // check first if we find a ZIP64 record
  central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream);
  if(central_pos > 0)
  {
    hasZIP64Record = 1;
  }
  else if(central_pos == 0)
  {
    central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream);
  }

/* disable to allow appending to empty ZIP archive
        if (central_pos==0)
            err=ZIP_ERRNO;
*/

  if(hasZIP64Record)
  {
    ZPOS64_T sizeEndOfCentralDirectory;
    if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
      err=ZIP_ERRNO;

    /* the signature, already checked */
    if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
      err=ZIP_ERRNO;

    /* size of zip64 end of central directory record */
    if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK)
      err=ZIP_ERRNO;

    /* version made by */
    if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK)
      err=ZIP_ERRNO;

    /* version needed to extract */
    if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK)
      err=ZIP_ERRNO;

    /* number of this disk */
    if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
      err=ZIP_ERRNO;

    /* number of the disk with the start of the central directory */
    if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
      err=ZIP_ERRNO;

    /* total number of entries in the central directory on this disk */
    if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK)
      err=ZIP_ERRNO;

    /* total number of entries in the central directory */
    if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK)
      err=ZIP_ERRNO;

    if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
      err=ZIP_BADZIPFILE;

    /* size of the central directory */
    if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK)
      err=ZIP_ERRNO;

    /* offset of start of central directory with respect to the
    starting disk number */
    if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK)
      err=ZIP_ERRNO;

    // TODO..
    // read the comment from the standard central header.
    size_comment = 0;
  }
  else
  {
    // Read End of central Directory info
    if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
      err=ZIP_ERRNO;

    /* the signature, already checked */
    if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
      err=ZIP_ERRNO;

    /* number of this disk */
    if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
      err=ZIP_ERRNO;

    /* number of the disk with the start of the central directory */
    if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
      err=ZIP_ERRNO;

    /* total number of entries in the central dir on this disk */
    number_entry = 0;
    if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
      err=ZIP_ERRNO;
    else
      number_entry = uL;

    /* total number of entries in the central dir */
    number_entry_CD = 0;
    if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
      err=ZIP_ERRNO;
    else
      number_entry_CD = uL;

    if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
      err=ZIP_BADZIPFILE;

    /* size of the central directory */
    size_central_dir = 0;
    if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
      err=ZIP_ERRNO;
    else
      size_central_dir = uL;

    /* offset of start of central directory with respect to the starting disk number */
    offset_central_dir = 0;
    if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
      err=ZIP_ERRNO;
    else
      offset_central_dir = uL;


    /* zipfile global comment length */
    if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK)
      err=ZIP_ERRNO;
  }

  if ((central_pos<offset_central_dir+size_central_dir) &&
    (err==ZIP_OK))
    err=ZIP_BADZIPFILE;

  if (err!=ZIP_OK)
  {
    ZCLOSE64(pziinit->z_filefunc, pziinit->filestream);
    return ZIP_ERRNO;
  }

  if (size_comment>0)
  {
    pziinit->globalcomment = (char*)ALLOC(size_comment+1);
    if (pziinit->globalcomment)
    {
      size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment);
      pziinit->globalcomment[size_comment]=0;
    }
  }

  byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir);
  pziinit->add_position_when_writing_offset = byte_before_the_zipfile;

  {
    ZPOS64_T size_central_dir_to_read = size_central_dir;
    size_t buf_size = SIZEDATA_INDATABLOCK;
    void* buf_read = (void*)ALLOC(buf_size);
    if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
      err=ZIP_ERRNO;

    while ((size_central_dir_to_read>0) && (err==ZIP_OK))
    {
      ZPOS64_T read_this = SIZEDATA_INDATABLOCK;
      if (read_this > size_central_dir_to_read)
        read_this = size_central_dir_to_read;

      if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this)
        err=ZIP_ERRNO;

      if (err==ZIP_OK)
        err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this);

      size_central_dir_to_read-=read_this;
    }
    free(buf_read);
  }
  pziinit->begin_pos = byte_before_the_zipfile;
  pziinit->number_entry = number_entry_CD;

  if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0)
    err=ZIP_ERRNO;

  return err;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x7c(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
callq 0x10c10
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jbe 0xdbd2
movl $0x1, -0x7c(%rbp)
jmp 0xdbf0
cmpq $0x0, -0x38(%rbp)
jne 0xdbee
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
callq 0x10f40
movq %rax, -0x38(%rbp)
jmp 0xdbf0
cmpl $0x0, -0x7c(%rbp)
je 0xdd97
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x38(%rbp), %rdx
xorl %ecx, %ecx
callq 0xc540
cmpq $0x0, %rax
je 0xdc1e
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x40(%rbp), %rdx
callq 0x11130
cmpl $0x0, %eax
je 0xdc3f
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x88(%rbp), %rdx
callq 0x11210
cmpl $0x0, %eax
je 0xdc63
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x68(%rbp), %rdx
callq 0x113a0
cmpl $0x0, %eax
je 0xdc84
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x70(%rbp), %rdx
callq 0x113a0
cmpl $0x0, %eax
je 0xdca5
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x48(%rbp), %rdx
callq 0x11130
cmpl $0x0, %eax
je 0xdcc6
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x50(%rbp), %rdx
callq 0x11130
cmpl $0x0, %eax
je 0xdce7
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x58(%rbp), %rdx
callq 0x11210
cmpl $0x0, %eax
je 0xdd08
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x60(%rbp), %rdx
callq 0x11210
cmpl $0x0, %eax
je 0xdd29
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x60(%rbp), %rax
cmpq -0x58(%rbp), %rax
jne 0xdd41
cmpq $0x0, -0x50(%rbp)
jne 0xdd41
cmpq $0x0, -0x48(%rbp)
je 0xdd48
movl $0xffffff99, -0x14(%rbp) # imm = 0xFFFFFF99
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x28(%rbp), %rdx
callq 0x11210
cmpl $0x0, %eax
je 0xdd69
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x30(%rbp), %rdx
callq 0x11210
cmpl $0x0, %eax
je 0xdd8a
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq $0x0, -0x78(%rbp)
jmp 0xdf2c
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x38(%rbp), %rdx
xorl %ecx, %ecx
callq 0xc540
cmpq $0x0, %rax
je 0xddbb
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x40(%rbp), %rdx
callq 0x11130
cmpl $0x0, %eax
je 0xdddc
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x48(%rbp), %rdx
callq 0x113a0
cmpl $0x0, %eax
je 0xddfd
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x50(%rbp), %rdx
callq 0x113a0
cmpl $0x0, %eax
je 0xde1e
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq $0x0, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x40(%rbp), %rdx
callq 0x113a0
cmpl $0x0, %eax
je 0xde49
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0xde51
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x40(%rbp), %rdx
callq 0x113a0
cmpl $0x0, %eax
je 0xde7c
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0xde84
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x58(%rbp), %rax
jne 0xde9c
cmpq $0x0, -0x50(%rbp)
jne 0xde9c
cmpq $0x0, -0x48(%rbp)
je 0xdea3
movl $0xffffff99, -0x14(%rbp) # imm = 0xFFFFFF99
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x40(%rbp), %rdx
callq 0x11130
cmpl $0x0, %eax
je 0xdece
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0xded6
movq -0x40(%rbp), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x40(%rbp), %rdx
callq 0x11130
cmpl $0x0, %eax
je 0xdf01
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0xdf09
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
leaq -0x78(%rbp), %rdx
callq 0x113a0
cmpl $0x0, %eax
je 0xdf2a
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0xdf2c
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
addq -0x28(%rbp), %rcx
cmpq %rcx, %rax
jae 0xdf4a
cmpl $0x0, -0x14(%rbp)
jne 0xdf4a
movl $0xffffff99, -0x14(%rbp) # imm = 0xFFFFFF99
cmpl $0x0, -0x14(%rbp)
je 0xdf76
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rdi
movq -0x10(%rbp), %rcx
movq 0x58(%rcx), %rsi
callq *%rax
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe185
cmpq $0x0, -0x78(%rbp)
jbe 0xdfe8
movq -0x78(%rbp), %rdi
addq $0x1, %rdi
callq 0xcaf0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10170(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10170(%rax)
je 0xdfe6
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rdi
movq -0x10(%rbp), %rcx
movq 0x58(%rcx), %rsi
movq -0x10(%rbp), %rcx
movq 0x10170(%rcx), %rdx
movq -0x78(%rbp), %rcx
callq *%rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movq 0x10170(%rax), %rax
movq -0x78(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0xdfe8
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
addq -0x28(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10160(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x90(%rbp)
movq $0xff0, -0x98(%rbp) # imm = 0xFF0
movq -0x98(%rbp), %rdi
callq 0xcaf0
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x30(%rbp), %rdx
addq -0x20(%rbp), %rdx
xorl %ecx, %ecx
callq 0xc540
cmpq $0x0, %rax
je 0xe05b
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0xe05d
xorl %eax, %eax
cmpq $0x0, -0x90(%rbp)
movb %al, -0xa9(%rbp)
jbe 0xe07c
cmpl $0x0, -0x14(%rbp)
sete %al
movb %al, -0xa9(%rbp)
movb -0xa9(%rbp), %al
testb $0x1, %al
jne 0xe08b
jmp 0xe12d
movq $0xff0, -0xa8(%rbp) # imm = 0xFF0
movq -0xa8(%rbp), %rax
cmpq -0x90(%rbp), %rax
jbe 0xe0b4
movq -0x90(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rdi
movq -0x10(%rbp), %rcx
movq 0x58(%rcx), %rsi
movq -0xa0(%rbp), %rdx
movq -0xa8(%rbp), %rcx
callq *%rax
cmpq -0xa8(%rbp), %rax
je 0xe0ec
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
cmpl $0x0, -0x14(%rbp)
jne 0xe110
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
movq -0xa0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
callq 0x10130
movl %eax, -0x14(%rbp)
movq -0xa8(%rbp), %rcx
movq -0x90(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x90(%rbp)
jmp 0xe05d
movq -0xa0(%rbp), %rdi
callq 0xc0d0
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10158(%rax)
movq -0x60(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10168(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x30(%rbp), %rdx
addq -0x20(%rbp), %rdx
xorl %ecx, %ecx
callq 0xc540
cmpq $0x0, %rax
je 0xe17f
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)