// File: /workspace/github_c_makefile_star2_O0/Paxa[P]fast_excel/libxlsxwriter/third_party/minizip/zip.c
// Function: zipCloseFileInZipRaw64
extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_size, uLong crc32) {
    zip64_internal* zi;
    ZPOS64_T compressed_size;
    uLong invalidValue = 0xffffffff;
    unsigned datasize = 0;
    int err=ZIP_OK;

    if (file == NULL)
        return ZIP_PARAMERROR;
    zi = (zip64_internal*)file;

    if (zi->in_opened_file_inzip == 0)
        return ZIP_PARAMERROR;
    zi->ci.stream.avail_in = 0;

    if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
                {
                        while (err==ZIP_OK)
                        {
                                uLong uTotalOutBefore;
                                if (zi->ci.stream.avail_out == 0)
                                {
                                        if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
                                                err = ZIP_ERRNO;
                                        zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
                                        zi->ci.stream.next_out = zi->ci.buffered_data;
                                }
                                uTotalOutBefore = zi->ci.stream.total_out;
                                err=deflate(&zi->ci.stream,  Z_FINISH);
                                zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
                        }
                }
    else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
    {
#ifdef HAVE_BZIP2
      err = BZ_FINISH_OK;
      while (err==BZ_FINISH_OK)
      {
        uLong uTotalOutBefore;
        if (zi->ci.bstream.avail_out == 0)
        {
          if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
            err = ZIP_ERRNO;
          zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
          zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
        }
        uTotalOutBefore = zi->ci.bstream.total_out_lo32;
        err=BZ2_bzCompress(&zi->ci.bstream,  BZ_FINISH);
        if(err == BZ_STREAM_END)
          err = Z_STREAM_END;

        zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore);
      }

      if(err == BZ_FINISH_OK)
        err = ZIP_OK;
#endif
    }

    if (err==Z_STREAM_END)
        err=ZIP_OK; /* this is normal */

    if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
                {
        if (zip64FlushWriteBuffer(zi)==ZIP_ERRNO)
            err = ZIP_ERRNO;
                }

    if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
    {
        int tmp_err = deflateEnd(&zi->ci.stream);
        if (err == ZIP_OK)
            err = tmp_err;
        zi->ci.stream_initialised = 0;
    }
#ifdef HAVE_BZIP2
    else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
    {
      int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream);
                        if (err==ZIP_OK)
                                err = tmperr;
                        zi->ci.stream_initialised = 0;
    }
#endif

    if (!zi->ci.raw)
    {
        crc32 = (uLong)zi->ci.crc32;
        uncompressed_size = zi->ci.totalUncompressedData;
    }
    compressed_size = zi->ci.totalCompressedData;

#    ifndef NOCRYPT
    compressed_size += zi->ci.crypt_header_size;
#    endif

    // update Current Item crc and sizes,
    if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff)
    {
      /*version Made by*/
      zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2);
      /*version needed*/
      zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2);

    }

    zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/


    if(compressed_size >= 0xffffffff)
      zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4); /*compr size*/
    else
      zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/

    /// set internal file attributes field
    if (zi->ci.stream.data_type == Z_ASCII)
        zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);

    if(uncompressed_size >= 0xffffffff)
      zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4); /*uncompr size*/
    else
      zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/

    // Add ZIP64 extra info field for uncompressed size
    if(uncompressed_size >= 0xffffffff)
      datasize += 8;

    // Add ZIP64 extra info field for compressed size
    if(compressed_size >= 0xffffffff)
      datasize += 8;

    // Add ZIP64 extra info field for relative offset to local file header of current file
    if(zi->ci.pos_local_header >= 0xffffffff)
      datasize += 8;

    if(datasize > 0)
    {
      char* p = NULL;

      if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree)
      {
        // we can not write more data to the buffer that we have room for.
        return ZIP_BADZIPFILE;
      }

      p = zi->ci.central_header + zi->ci.size_centralheader;

      // Add Extra Information Header for 'ZIP64 information'
      zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID
      p += 2;
      zip64local_putValue_inmemory(p, datasize, 2); // DataSize
      p += 2;

      if(uncompressed_size >= 0xffffffff)
      {
        zip64local_putValue_inmemory(p, uncompressed_size, 8);
        p += 8;
      }

      if(compressed_size >= 0xffffffff)
      {
        zip64local_putValue_inmemory(p, compressed_size, 8);
        p += 8;
      }

      if(zi->ci.pos_local_header >= 0xffffffff)
      {
        zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8);
        p += 8;
      }

      // Update how much extra free space we got in the memory buffer
      // and increase the centralheader size so the new ZIP64 fields are included
      // ( 4 below is the size of HeaderID and DataSize field )
      zi->ci.size_centralExtraFree -= datasize + 4;
      zi->ci.size_centralheader += datasize + 4;

      // Update the extra info size field
      zi->ci.size_centralExtra += datasize + 4;
      zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2);
    }

    if (err==ZIP_OK)
        err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);

    free(zi->ci.central_header);

    if (err==ZIP_OK)
    {
        // Update the LocalFileHeader with the new values.

        ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);

        if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)
            err = ZIP_ERRNO;

        if (err==ZIP_OK)
            err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */

        if(uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff )
        {
          if(zi->ci.pos_zip64extrainfo > 0)
          {
            // Update the size in the ZIP64 extended field.
            if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0)
              err = ZIP_ERRNO;

            if (err==ZIP_OK) /* compressed size, unknown */
              err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8);

            if (err==ZIP_OK) /* uncompressed size, unknown */
              err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8);
          }
          else
              err = ZIP_BADZIPFILE; // Caller passed zip64 = 0, so no room for zip64 info -> fatal
        }
        else
        {
          if (err==ZIP_OK) /* compressed size, unknown */
              err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);

          if (err==ZIP_OK) /* uncompressed size, unknown */
              err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
        }

        if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
            err = ZIP_ERRNO;
    }

    zi->number_entry ++;
    zi->in_opened_file_inzip = 0;

    return err;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xfa6e
movl $0xffffff9a, -0x4(%rbp) # imm = 0xFFFFFF9A
jmp 0x10127
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x70(%rax)
jne 0xfa8c
movl $0xffffff9a, -0x4(%rbp) # imm = 0xFFFFFF9A
jmp 0x10127
movq -0x28(%rbp), %rax
movl $0x0, 0x80(%rax)
movq -0x28(%rbp), %rax
cmpl $0x8, 0x120(%rax)
jne 0xfb5e
movq -0x28(%rbp), %rax
cmpl $0x0, 0x124(%rax)
jne 0xfb5e
jmp 0xfabe
cmpl $0x0, -0x40(%rbp)
jne 0xfb5c
movq -0x28(%rbp), %rax
cmpl $0x0, 0x98(%rax)
jne 0xfb12
movq -0x28(%rbp), %rdi
callq 0xf930
cmpl $-0x1, %eax
jne 0xfaea
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movl $0x10000, 0x98(%rax)    # imm = 0x10000
movq -0x28(%rbp), %rcx
addq $0x78, %rcx
addq $0xb0, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x90(%rax)
movq -0x28(%rbp), %rax
movq 0xa0(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rdi
addq $0x78, %rdi
movl $0x4, %esi
callq 0xc670
movl %eax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0xa0(%rax), %rax
subq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addl 0xec(%rax), %ecx
movl %ecx, 0xec(%rax)
jmp 0xfabe
jmp 0xfb7c
movq -0x28(%rbp), %rax
cmpl $0xc, 0x120(%rax)
jne 0xfb7a
movq -0x28(%rbp), %rax
cmpl $0x0, 0x124(%rax)
jne 0xfb7a
jmp 0xfb7a
jmp 0xfb7c
cmpl $0x1, -0x40(%rbp)
jne 0xfb89
movl $0x0, -0x40(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0xec(%rax)
jbe 0xfbb3
cmpl $0x0, -0x40(%rbp)
jne 0xfbb3
movq -0x28(%rbp), %rdi
callq 0xf930
cmpl $-0x1, %eax
jne 0xfbb1
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
jmp 0xfbb3
movq -0x28(%rbp), %rax
cmpl $0x8, 0x120(%rax)
jne 0xfbf7
movq -0x28(%rbp), %rax
cmpl $0x0, 0x124(%rax)
jne 0xfbf7
movq -0x28(%rbp), %rdi
addq $0x78, %rdi
callq 0xcc10
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0xfbe9
movl -0x4c(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movl $0x0, 0xe8(%rax)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x124(%rax)
jne 0xfc22
movq -0x28(%rbp), %rax
movq 0x10130(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movq 0x10150(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rax
movq 0x10148(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x30(%rbp)
jae 0xfc59
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x18(%rbp)
jae 0xfc59
movq -0x28(%rbp), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, 0xf0(%rax)
jb 0xfc95
movq -0x28(%rbp), %rax
movq 0xf8(%rax), %rdi
addq $0x4, %rdi
movl $0x2d, %esi
movl $0x2, %edx
callq 0xebe0
movq -0x28(%rbp), %rax
movq 0xf8(%rax), %rdi
addq $0x6, %rdi
movl $0x2d, %esi
movl $0x2, %edx
callq 0xebe0
movq -0x28(%rbp), %rax
movq 0xf8(%rax), %rdi
addq $0x10, %rdi
movq -0x20(%rbp), %rsi
movl $0x4, %edx
callq 0xebe0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x30(%rbp)
jb 0xfcdc
movq -0x28(%rbp), %rax
movq 0xf8(%rax), %rdi
addq $0x14, %rdi
movq -0x38(%rbp), %rsi
movl $0x4, %edx
callq 0xebe0
jmp 0xfcf9
movq -0x28(%rbp), %rax
movq 0xf8(%rax), %rdi
addq $0x14, %rdi
movq -0x30(%rbp), %rsi
movl $0x4, %edx
callq 0xebe0
movq -0x28(%rbp), %rax
cmpl $0x1, 0xd0(%rax)
jne 0xfd24
movq -0x28(%rbp), %rax
movq 0xf8(%rax), %rdi
addq $0x24, %rdi
movl $0x1, %esi
movl $0x2, %edx
callq 0xebe0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x18(%rbp)
jb 0xfd4e
movq -0x28(%rbp), %rax
movq 0xf8(%rax), %rdi
addq $0x18, %rdi
movq -0x38(%rbp), %rsi
movl $0x4, %edx
callq 0xebe0
jmp 0xfd6b
movq -0x28(%rbp), %rax
movq 0xf8(%rax), %rdi
addq $0x18, %rdi
movq -0x18(%rbp), %rsi
movl $0x4, %edx
callq 0xebe0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x18(%rbp)
jb 0xfd7f
movl -0x3c(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x3c(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x30(%rbp)
jb 0xfd93
movl -0x3c(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, 0xf0(%rax)
jb 0xfdae
movl -0x3c(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jbe 0xff3d
movq $0x0, -0x58(%rbp)
movl -0x3c(%rbp), %eax
addl $0x4, %eax
movl %eax, %eax
movq -0x28(%rbp), %rcx
cmpq 0x110(%rcx), %rax
jbe 0xfde1
movl $0xffffff99, -0x4(%rbp) # imm = 0xFFFFFF99
jmp 0x10127
movq -0x28(%rbp), %rax
movq 0xf8(%rax), %rax
movq -0x28(%rbp), %rcx
addq 0x108(%rcx), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movl $0x1, %esi
movl $0x2, %edx
callq 0xebe0
movq -0x58(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
movl $0x2, %edx
callq 0xebe0
movq -0x58(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x58(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x18(%rbp)
jb 0xfe62
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x8, %edx
callq 0xebe0
movq -0x58(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x58(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x30(%rbp)
jb 0xfe8b
movq -0x58(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl $0x8, %edx
callq 0xebe0
movq -0x58(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, 0xf0(%rax)
jb 0xfec2
movq -0x58(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0xf0(%rax), %rsi
movl $0x8, %edx
callq 0xebe0
movq -0x58(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x58(%rbp)
movl -0x3c(%rbp), %eax
addl $0x4, %eax
movl %eax, %eax
movl %eax, %edx
movq -0x28(%rbp), %rax
movq 0x110(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x110(%rax)
movl -0x3c(%rbp), %eax
addl $0x4, %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq 0x108(%rax), %rcx
movq %rcx, 0x108(%rax)
movl -0x3c(%rbp), %eax
addl $0x4, %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq 0x100(%rax), %rcx
movq %rcx, 0x100(%rax)
movq -0x28(%rbp), %rax
movq 0xf8(%rax), %rdi
addq $0x1e, %rdi
movq -0x28(%rbp), %rax
movq 0x100(%rax), %rsi
movl $0x2, %edx
callq 0xebe0
cmpl $0x0, -0x40(%rbp)
jne 0xff69
movq -0x28(%rbp), %rdi
addq $0x60, %rdi
movq -0x28(%rbp), %rax
movq 0xf8(%rax), %rsi
movq -0x28(%rbp), %rax
movq 0x108(%rax), %rdx
callq 0x10130
movl %eax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0xf8(%rax), %rdi
callq 0xc0d0
cmpl $0x0, -0x40(%rbp)
jne 0x10100
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rsi
callq 0xcf60
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x28(%rbp), %rax
movq 0xf0(%rax), %rdx
addq $0xe, %rdx
xorl %ecx, %ecx
callq 0xc540
cmpq $0x0, %rax
je 0xffc7
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
cmpl $0x0, -0x40(%rbp)
jne 0xffea
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x20(%rbp), %rdx
movl $0x4, %ecx
callq 0x102c0
movl %eax, -0x40(%rbp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x18(%rbp)
jae 0x10004
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x30(%rbp)
jb 0x10092
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10140(%rax)
jbe 0x10089
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x28(%rbp), %rax
movq 0x10140(%rax), %rdx
addq $0x4, %rdx
xorl %ecx, %ecx
callq 0xc540
cmpq $0x0, %rax
je 0x10041
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
cmpl $0x0, -0x40(%rbp)
jne 0x10064
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x18(%rbp), %rdx
movl $0x8, %ecx
callq 0x102c0
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x10087
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x30(%rbp), %rdx
movl $0x8, %ecx
callq 0x102c0
movl %eax, -0x40(%rbp)
jmp 0x10090
movl $0xffffff99, -0x40(%rbp) # imm = 0xFFFFFF99
jmp 0x100da
cmpl $0x0, -0x40(%rbp)
jne 0x100b5
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x30(%rbp), %rdx
movl $0x4, %ecx
callq 0x102c0
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x100d8
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x18(%rbp), %rdx
movl $0x4, %ecx
callq 0x102c0
movl %eax, -0x40(%rbp)
jmp 0x100da
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rsi
movq -0x60(%rbp), %rdx
xorl %ecx, %ecx
callq 0xc540
cmpq $0x0, %rax
je 0x100fe
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
jmp 0x10100
movq -0x28(%rbp), %rax
movq 0x10168(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x10168(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x70(%rax)
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq