// File: /workspace/github_c_makefile_star2_O0/Paxa[P]fast_excel/libxlsxwriter/third_party/minizip/zip.c
// Function: zip64local_SearchCentralDir64
local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) {
  unsigned char* buf;
  ZPOS64_T uSizeFile;
  ZPOS64_T uBackRead;
  ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
  ZPOS64_T uPosFound=0;
  uLong uL;
  ZPOS64_T relativeOffset;

  if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
    return 0;

  uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);

  if (uMaxBack>uSizeFile)
    uMaxBack = uSizeFile;

  buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
  if (buf==NULL)
    return 0;

  uBackRead = 4;
  while (uBackRead<uMaxBack)
  {
    uLong uReadSize;
    ZPOS64_T uReadPos;
    int i;
    if (uBackRead+BUFREADCOMMENT>uMaxBack)
      uBackRead = uMaxBack;
    else
      uBackRead+=BUFREADCOMMENT;
    uReadPos = uSizeFile-uBackRead ;

    uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
      (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
    if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
      break;

    if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
      break;

    for (i=(int)uReadSize-3; (i--)>0;)
    {
      // Signature "0x07064b50" Zip64 end of central directory locater
      if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
      {
        uPosFound = uReadPos+(unsigned)i;
        break;
      }
    }

      if (uPosFound!=0)
        break;
  }

  free(buf);
  if (uPosFound == 0)
    return 0;

  /* Zip64 end of central directory locator */
  if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
    return 0;

  /* the signature, already checked */
  if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
    return 0;

  /* number of the disk with the start of the zip64 end of  central directory */
  if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
    return 0;
  if (uL != 0)
    return 0;

  /* relative offset of the zip64 end of central directory record */
  if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK)
    return 0;

  /* total number of disks */
  if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
    return 0;
  if (uL != 1)
    return 0;

  /* Goto Zip64 end of central directory record */
  if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
    return 0;

  /* the signature */
  if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
    return 0;

  if (uL != 0x06064b50) // signature of 'Zip64 end of central directory'
    return 0;

  return relativeOffset;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0xffff, -0x38(%rbp)    # imm = 0xFFFF
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
movl $0x2, %ecx
callq 0xc540
cmpq $0x0, %rax
je 0x10c59
movq $0x0, -0x8(%rbp)
jmp 0x10f31
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xcf60
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x28(%rbp), %rax
jbe 0x10c7c
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x404, %edi            # imm = 0x404
callq 0xcaf0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x10c9e
movq $0x0, -0x8(%rbp)
jmp 0x10f31
movq $0x4, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x10de1
movq -0x30(%rbp), %rax
addq $0x400, %rax            # imm = 0x400
cmpq -0x38(%rbp), %rax
jbe 0x10cce
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x10cdc
movq -0x30(%rbp), %rax
addq $0x400, %rax            # imm = 0x400
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
subq -0x30(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rcx
subq -0x60(%rbp), %rcx
movl $0x404, %eax            # imm = 0x404
cmpq %rcx, %rax
jae 0x10d05
movl $0x404, %eax            # imm = 0x404
movq %rax, -0x70(%rbp)
jmp 0x10d11
movq -0x28(%rbp), %rax
subq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x60(%rbp), %rdx
xorl %ecx, %ecx
callq 0xc540
cmpq $0x0, %rax
je 0x10d37
jmp 0x10de1
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq *%rax
cmpq -0x58(%rbp), %rax
je 0x10d60
jmp 0x10de1
movq -0x58(%rbp), %rax
subl $0x3, %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x64(%rbp)
cmpl $0x0, %eax
jle 0x10dd3
movq -0x20(%rbp), %rax
movslq -0x64(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x50, %eax
jne 0x10dd1
movq -0x20(%rbp), %rax
movslq -0x64(%rbp), %rcx
movzbl 0x1(%rax,%rcx), %eax
cmpl $0x4b, %eax
jne 0x10dd1
movq -0x20(%rbp), %rax
movslq -0x64(%rbp), %rcx
movzbl 0x2(%rax,%rcx), %eax
cmpl $0x6, %eax
jne 0x10dd1
movq -0x20(%rbp), %rax
movslq -0x64(%rbp), %rcx
movzbl 0x3(%rax,%rcx), %eax
cmpl $0x7, %eax
jne 0x10dd1
movq -0x60(%rbp), %rax
movl -0x64(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
jmp 0x10dd3
jmp 0x10d6a
cmpq $0x0, -0x40(%rbp)
je 0x10ddc
jmp 0x10de1
jmp 0x10ca6
movq -0x20(%rbp), %rdi
callq 0xc0d0
cmpq $0x0, -0x40(%rbp)
jne 0x10dfe
movq $0x0, -0x8(%rbp)
jmp 0x10f31
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
xorl %ecx, %ecx
callq 0xc540
cmpq $0x0, %rax
je 0x10e24
movq $0x0, -0x8(%rbp)
jmp 0x10f31
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x11130
cmpl $0x0, %eax
je 0x10e47
movq $0x0, -0x8(%rbp)
jmp 0x10f31
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x11130
cmpl $0x0, %eax
je 0x10e6a
movq $0x0, -0x8(%rbp)
jmp 0x10f31
cmpq $0x0, -0x48(%rbp)
je 0x10e7e
movq $0x0, -0x8(%rbp)
jmp 0x10f31
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x11210
cmpl $0x0, %eax
je 0x10ea1
movq $0x0, -0x8(%rbp)
jmp 0x10f31
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x11130
cmpl $0x0, %eax
je 0x10ec1
movq $0x0, -0x8(%rbp)
jmp 0x10f31
cmpq $0x1, -0x48(%rbp)
je 0x10ed2
movq $0x0, -0x8(%rbp)
jmp 0x10f31
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x50(%rbp), %rdx
xorl %ecx, %ecx
callq 0xc540
cmpq $0x0, %rax
je 0x10ef5
movq $0x0, -0x8(%rbp)
jmp 0x10f31
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x11130
cmpl $0x0, %eax
je 0x10f15
movq $0x0, -0x8(%rbp)
jmp 0x10f31
cmpq $0x6064b50, -0x48(%rbp) # imm = 0x6064B50
je 0x10f29
movq $0x0, -0x8(%rbp)
jmp 0x10f31
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)