// File: /workspace/github_c_makefile_star2_O1/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:
movl $0xffffff9a, %eax       # imm = 0xFFFFFF9A
testq %rdi, %rdi
je 0x11ccb
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
cmpl $0x0, 0x70(%rdi)
je 0x11cbd
movq %rdx, %r15
movq %rsi, %r14
leaq 0x78(%rbx), %r12
movl $0x0, 0x80(%rbx)
xorl %ebp, %ebp
cmpl $0x8, 0x120(%rbx)
movl $0x0, %eax
jne 0x11712
cmpl $0x0, 0x124(%rbx)
jne 0x11712
leaq 0x128(%rbx), %r13
cmpl $0x0, 0x98(%rbx)
jne 0x116e7
movq 0x38(%rbx), %rdi
movq 0x58(%rbx), %rsi
movl 0xec(%rbx), %ecx
movq %r13, %rdx
callq *0x10(%rbx)
movl 0xec(%rbx), %eax
addq %rax, 0x10148(%rbx)
movq 0x88(%rbx), %rax
addq %rax, 0x10150(%rbx)
movq $0x0, 0x88(%rbx)
movl $0x0, 0xec(%rbx)
movl $0x10000, 0x98(%rbx)    # imm = 0x10000
movq %r13, 0x90(%rbx)
movl 0xa0(%rbx), %ebp
movq %r12, %rdi
movl $0x4, %esi
callq 0xc610
movl 0xa0(%rbx), %ecx
subl %ebp, %ecx
addl %ecx, 0xec(%rbx)
testl %eax, %eax
je 0x11689
xorl %ebp, %ebp
cmpl $0x1, %eax
cmovnel %eax, %ebp
movl 0xec(%rbx), %ecx
testq %rcx, %rcx
je 0x11774
testl %ebp, %ebp
jne 0x11774
movq 0x38(%rbx), %rdi
movq 0x58(%rbx), %rsi
leaq 0x128(%rbx), %rdx
callq *0x10(%rbx)
movl 0xec(%rbx), %ecx
xorl %ebp, %ebp
cmpq %rcx, %rax
setne %bpl
addq %rcx, 0x10148(%rbx)
movq 0x88(%rbx), %rax
addq %rax, 0x10150(%rbx)
movq $0x0, 0x88(%rbx)
movl $0x0, 0xec(%rbx)
negl %ebp
cmpl $0x8, 0x120(%rbx)
jne 0x1179d
cmpl $0x0, 0x124(%rbx)
jne 0x1179d
movq %r12, %rdi
callq 0xcb70
testl %ebp, %ebp
cmovel %eax, %ebp
movl $0x0, 0xe8(%rbx)
cmpl $0x0, 0x124(%rbx)
jne 0x117b4
movq 0x10130(%rbx), %r15
movq 0x10150(%rbx), %r14
movl $0xfffffffe, %r9d       # imm = 0xFFFFFFFE
movq 0x10148(%rbx), %r13
cmpq %r9, %r13
seta %al
cmpq %r9, %r14
seta %cl
orb %al, %cl
jne 0x117da
cmpq %r9, 0xf0(%rbx)
jbe 0x1180e
movq 0xf8(%rbx), %rax
movb $0x2d, %dl
xorl %ecx, %ecx
movb %dl, 0x4(%rax,%rcx)
incq %rcx
xorl %edx, %edx
cmpq $0x2, %rcx
jne 0x117e5
movq 0xf8(%rbx), %rax
movb $0x2d, %dl
xorl %ecx, %ecx
movb %dl, 0x6(%rax,%rcx)
incq %rcx
xorl %edx, %edx
cmpq $0x2, %rcx
jne 0x117ff
movq 0xf8(%rbx), %rax
xorl %ecx, %ecx
movq %r15, %rdx
movq %rdx, %rsi
movb %sil, 0x10(%rax,%rcx)
shrq $0x8, %rdx
incq %rcx
cmpq $0x4, %rcx
jne 0x1181a
cmpq $0x100, %rsi            # imm = 0x100
jb 0x1183f
movl $0xffffffff, 0x10(%rax) # imm = 0xFFFFFFFF
movq 0xf8(%rbx), %rax
cmpq %r9, %r13
jbe 0x11864
leaq 0x1(%r9), %rcx
xorl %edx, %edx
movb %cl, 0x14(%rax,%rdx)
shrq $0x8, %rcx
incq %rdx
cmpq $0x4, %rdx
jne 0x11851
jmp 0x1188e
xorl %ecx, %ecx
movq %r13, %rdx
movq %rdx, %rsi
movb %sil, 0x14(%rax,%rcx)
shrq $0x8, %rdx
incq %rcx
cmpq $0x4, %rcx
jne 0x11869
cmpq $0x100, %rsi            # imm = 0x100
jb 0x1188e
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
cmpl $0x1, 0xd0(%rbx)
jne 0x118b1
movq 0xf8(%rbx), %rax
movb $0x1, %dl
xorl %ecx, %ecx
movb %dl, 0x24(%rax,%rcx)
incq %rcx
xorl %edx, %edx
cmpq $0x2, %rcx
jne 0x118a2
movq 0xf8(%rbx), %rax
cmpq %r9, %r14
jbe 0x118db
leaq 0x1(%r9), %rcx
xorl %edx, %edx
movb %cl, 0x18(%rax,%rdx)
shrq $0x8, %rcx
incq %rdx
cmpq $0x4, %rdx
jne 0x118c3
movl $0x8, %ecx
jmp 0x11907
xorl %ecx, %ecx
movq %r14, %rdx
movq %rdx, %rsi
movb %sil, 0x18(%rax,%rcx)
shrq $0x8, %rdx
incq %rcx
cmpq $0x4, %rcx
jne 0x118e0
xorl %ecx, %ecx
cmpq $0x100, %rsi            # imm = 0x100
jb 0x11907
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
leal 0x8(%rcx), %eax
cmpq %r9, %r13
cmovbel %ecx, %eax
leal 0x8(%rax), %esi
cmpq %r9, 0xf0(%rbx)
cmovbel %eax, %esi
testl %esi, %esi
je 0x11a56
movl %esi, %ecx
orl $0x4, %ecx
movl $0xffffff99, %eax       # imm = 0xFFFFFF99
cmpq %rcx, 0x110(%rbx)
jb 0x11cbd
movq 0xf8(%rbx), %rdx
addq 0x108(%rbx), %rdx
movb $0x1, %dil
xorl %eax, %eax
movb %dil, (%rdx,%rax)
incq %rax
xorl %edi, %edi
cmpq $0x2, %rax
jne 0x1194f
xorl %eax, %eax
movb %sil, 0x2(%rdx,%rax)
incq %rax
xorl %esi, %esi
cmpq $0x2, %rax
jne 0x11960
leaq 0x4(%rdx), %rax
cmpq %r9, %r14
jbe 0x119a9
xorl %esi, %esi
movq %r14, %rdi
movq %rdi, %r8
movb %r8b, (%rax,%rsi)
shrq $0x8, %rdi
incq %rsi
cmpq $0x8, %rsi
jne 0x1197e
cmpq $0x100, %r8             # imm = 0x100
jb 0x119a2
movq $-0x1, (%rax)
addq $0xc, %rdx
movq %rdx, %rax
cmpq %r9, %r13
jbe 0x119db
xorl %edx, %edx
movq %r13, %rsi
movq %rsi, %rdi
movb %dil, (%rax,%rdx)
shrq $0x8, %rsi
incq %rdx
cmpq $0x8, %rdx
jne 0x119b3
cmpq $0x100, %rdi            # imm = 0x100
jb 0x119d7
movq $-0x1, (%rax)
addq $0x8, %rax
movq 0xf0(%rbx), %rdx
cmpq %r9, %rdx
jbe 0x11a0d
xorl %esi, %esi
movq %rdx, %rdi
movb %dil, (%rax,%rsi)
shrq $0x8, %rdx
incq %rsi
cmpq $0x8, %rsi
jne 0x119e9
cmpq $0x100, %rdi            # imm = 0x100
jb 0x11a0d
movq $-0x1, (%rax)
subq %rcx, 0x110(%rbx)
addq %rcx, 0x108(%rbx)
addq 0x100(%rbx), %rcx
movq %rcx, 0x100(%rbx)
movq 0xf8(%rbx), %rax
xorl %edx, %edx
movq %rcx, %rsi
movb %sil, 0x1e(%rax,%rdx)
shrq $0x8, %rcx
incq %rdx
cmpq $0x2, %rdx
jne 0x11a32
cmpq $0x100, %rsi            # imm = 0x100
jb 0x11a56
movw $0xffff, 0x1e(%rax)     # imm = 0xFFFF
testl %ebp, %ebp
jne 0x11a73
leaq 0x60(%rbx), %rdi
movq 0xf8(%rbx), %rsi
movq 0x108(%rbx), %rdx
callq 0x11ccc
movl %eax, %ebp
movq 0xf8(%rbx), %rdi
callq 0xc0c0
testl %ebp, %ebp
jne 0x11cad
movq 0x58(%rbx), %rsi
movq %rbx, %rdi
callq 0xceb0
movq %rax, 0x10(%rsp)
movq 0x58(%rbx), %rsi
movq 0xf0(%rbx), %rdx
addq $0xe, %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0xc4e0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testq %rax, %rax
jne 0x11b06
movq 0x58(%rbx), %rsi
xorl %eax, %eax
movq %r15, %rcx
movb %cl, 0x8(%rsp,%rax)
shrq $0x8, %r15
incq %rax
cmpq $0x4, %rax
jne 0x11ac2
cmpq $0x100, %rcx            # imm = 0x100
jb 0x11ae7
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x4, %ecx
callq *0x10(%rbx)
xorl %r12d, %r12d
cmpq $0x4, %rax
setne %r12b
negl %r12d
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
cmpq %rcx, %r14
setbe %al
cmpq %rcx, %r13
setbe %cl
testb %cl, %al
jne 0x11bea
movq 0x10140(%rbx), %rdx
testq %rdx, %rdx
je 0x11c8a
movq 0x58(%rbx), %rsi
addq $0x4, %rdx
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0xc4e0
negq %rax
sbbl %ebp, %ebp
orl %ebp, %r12d
jne 0x11b98
movq 0x58(%rbx), %rsi
xorl %eax, %eax
movq %r14, %rcx
movb %cl, 0x8(%rsp,%rax)
shrq $0x8, %r14
incq %rax
cmpq $0x8, %rax
jne 0x11b53
cmpq $0x100, %rcx            # imm = 0x100
jb 0x11b79
movq $-0x1, 0x8(%rsp)
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x8, %ecx
callq *0x10(%rbx)
xorl %r12d, %r12d
cmpq $0x8, %rax
setne %r12b
negl %r12d
testl %r12d, %r12d
jne 0x11c90
movq 0x58(%rbx), %rsi
xorl %eax, %eax
movq %r13, %rcx
movb %cl, 0x8(%rsp,%rax)
shrq $0x8, %r13
incq %rax
cmpq $0x8, %rax
jne 0x11ba7
cmpq $0x100, %rcx            # imm = 0x100
jb 0x11bcd
movq $-0x1, 0x8(%rsp)
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x8, %ecx
callq *0x10(%rbx)
xorl %r12d, %r12d
cmpq $0x8, %rax
jmp 0x11c81
testl %r12d, %r12d
jne 0x11c39
movq 0x58(%rbx), %rsi
xorl %eax, %eax
movq %r13, %rcx
movb %cl, 0x8(%rsp,%rax)
shrq $0x8, %r13
incq %rax
cmpq $0x4, %rax
jne 0x11bf5
cmpq $0x100, %rcx            # imm = 0x100
jb 0x11c1a
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x4, %ecx
callq *0x10(%rbx)
xorl %r12d, %r12d
cmpq $0x4, %rax
setne %r12b
negl %r12d
testl %r12d, %r12d
jne 0x11c90
movq 0x58(%rbx), %rsi
xorl %eax, %eax
movq %r14, %rcx
movb %cl, 0x8(%rsp,%rax)
shrq $0x8, %r14
incq %rax
cmpq $0x4, %rax
jne 0x11c44
cmpq $0x100, %rcx            # imm = 0x100
jb 0x11c69
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x4, %ecx
callq *0x10(%rbx)
xorl %r12d, %r12d
cmpq $0x4, %rax
setne %r12b
negl %r12d
jmp 0x11c90
movl $0xffffff99, %r12d      # imm = 0xFFFFFF99
movq 0x58(%rbx), %rsi
xorl %ebp, %ebp
movq %rbx, %rdi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0xc4e0
negq %rax
sbbl %ebp, %ebp
orl %r12d, %ebp
incq 0x10168(%rbx)
movl $0x0, 0x70(%rbx)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq