// File: /workspace/github_c_makefile_star2_O3/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 0x11f7c
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
cmpl $0x0, 0x70(%rdi)
je 0x11f6e
movq %rdx, %r15
movq %rsi, %r14
leaq 0x78(%rbx), %r12
movl $0x0, 0x80(%rbx)
cmpl $0x8, 0x120(%rbx)
jne 0x119f2
cmpl $0x0, 0x124(%rbx)
jne 0x119f2
movq %r14, 0x8(%rsp)
leaq 0x128(%rbx), %r13
cmpl $0x0, 0x98(%rbx)
jne 0x119bb
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), %r14d
movq %r12, %rdi
movl $0x4, %esi
callq 0xc610
movl %eax, %ebp
movl 0xa0(%rbx), %eax
subl %r14d, %eax
addl %eax, 0xec(%rbx)
testl %ebp, %ebp
je 0x1195d
cmpl $0x1, %ebp
movq 0x8(%rsp), %r14
jne 0x11a4e
movl 0xec(%rbx), %ecx
testq %rcx, %rcx
je 0x11a4c
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
jmp 0x11a4e
xorl %ebp, %ebp
cmpl $0x8, 0x120(%rbx)
jne 0x11a77
cmpl $0x0, 0x124(%rbx)
jne 0x11a77
movq %r12, %rdi
callq 0xcb70
testl %ebp, %ebp
cmovel %eax, %ebp
movl $0x0, 0xe8(%rbx)
cmpl $0x0, 0x124(%rbx)
jne 0x11a8e
movq 0x10130(%rbx), %r15
movq 0x10150(%rbx), %r14
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
movq 0x10148(%rbx), %r13
cmpq %r12, %r13
seta %al
cmpq %r12, %r14
seta %cl
orb %al, %cl
jne 0x11ab4
cmpq %r12, 0xf0(%rbx)
jbe 0x11ace
movq 0xf8(%rbx), %rax
movw $0x2d, %cx
movw %cx, 0x4(%rax)
movq 0xf8(%rbx), %rax
movw %cx, 0x6(%rax)
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 0x11ada
cmpq $0x100, %rsi            # imm = 0x100
jb 0x11aff
movl $0xffffffff, 0x10(%rax) # imm = 0xFFFFFFFF
movq 0xf8(%rbx), %rax
cmpq %r12, %r13
jbe 0x11b25
leaq 0x1(%r12), %rcx
xorl %edx, %edx
movb %cl, 0x14(%rax,%rdx)
shrq $0x8, %rcx
incq %rdx
cmpq $0x4, %rdx
jne 0x11b12
jmp 0x11b4f
xorl %ecx, %ecx
movq %r13, %rdx
movq %rdx, %rsi
movb %sil, 0x14(%rax,%rcx)
shrq $0x8, %rdx
incq %rcx
cmpq $0x4, %rcx
jne 0x11b2a
cmpq $0x100, %rsi            # imm = 0x100
jb 0x11b4f
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
cmpl $0x1, 0xd0(%rbx)
jne 0x11b65
movq 0xf8(%rbx), %rax
movw $0x1, 0x24(%rax)
movq 0xf8(%rbx), %rax
cmpq %r12, %r14
jbe 0x11b90
leaq 0x1(%r12), %rcx
xorl %edx, %edx
movb %cl, 0x18(%rax,%rdx)
shrq $0x8, %rcx
incq %rdx
cmpq $0x4, %rdx
jne 0x11b78
movl $0x8, %ecx
jmp 0x11bbc
xorl %ecx, %ecx
movq %r14, %rdx
movq %rdx, %rsi
movb %sil, 0x18(%rax,%rcx)
shrq $0x8, %rdx
incq %rcx
cmpq $0x4, %rcx
jne 0x11b95
xorl %ecx, %ecx
cmpq $0x100, %rsi            # imm = 0x100
jb 0x11bbc
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
leal 0x8(%rcx), %eax
cmpq %r12, %r13
cmovbel %ecx, %eax
leal 0x8(%rax), %esi
cmpq %r12, 0xf0(%rbx)
cmovbel %eax, %esi
testl %esi, %esi
je 0x11ce7
movl %esi, %ecx
orl $0x4, %ecx
movl $0xffffff99, %eax       # imm = 0xFFFFFF99
cmpq %rcx, 0x110(%rbx)
jb 0x11f6e
movq 0xf8(%rbx), %rdx
movq 0x108(%rbx), %rdi
leaq (%rdx,%rdi), %rax
addq $0x4, %rax
movw $0x1, -0x4(%rax)
movb %sil, -0x2(%rax)
movb $0x0, -0x1(%rax)
cmpq %r12, %r14
jbe 0x11c4d
addq %rdi, %rdx
xorl %esi, %esi
movq %r14, %rdi
movq %rdi, %r8
movb %r8b, (%rax,%rsi)
shrq $0x8, %rdi
incq %rsi
cmpq $0x8, %rsi
jne 0x11c22
cmpq $0x100, %r8             # imm = 0x100
jb 0x11c46
movq $-0x1, (%rax)
addq $0xc, %rdx
movq %rdx, %rax
cmpq %r12, %r13
jbe 0x11c7f
xorl %edx, %edx
movq %r13, %rsi
movq %rsi, %rdi
movb %dil, (%rax,%rdx)
shrq $0x8, %rsi
incq %rdx
cmpq $0x8, %rdx
jne 0x11c57
cmpq $0x100, %rdi            # imm = 0x100
jb 0x11c7b
movq $-0x1, (%rax)
addq $0x8, %rax
movq 0xf0(%rbx), %rdx
cmpq %r12, %rdx
jbe 0x11cb1
xorl %esi, %esi
movq %rdx, %rdi
movb %dil, (%rax,%rsi)
shrq $0x8, %rdx
incq %rsi
cmpq $0x8, %rsi
jne 0x11c8d
cmpq $0x100, %rdi            # imm = 0x100
jb 0x11cb1
movq $-0x1, (%rax)
subq %rcx, 0x110(%rbx)
addq %rcx, 0x108(%rbx)
addq 0x100(%rbx), %rcx
movq %rcx, 0x100(%rbx)
movq 0xf8(%rbx), %rax
movw %cx, 0x1e(%rax)
cmpq $0x10000, %rcx          # imm = 0x10000
jb 0x11ce7
movw $0xffff, 0x1e(%rax)     # imm = 0xFFFF
testl %ebp, %ebp
je 0x11cfc
movq 0xf8(%rbx), %rdi
callq 0xc0c0
jmp 0x11f5e
leaq 0x60(%rbx), %rdi
movq 0xf8(%rbx), %rsi
movq 0x108(%rbx), %rdx
callq 0x11f7d
movl %eax, %ebp
movq 0xf8(%rbx), %rdi
callq 0xc0c0
testl %ebp, %ebp
jne 0x11f5e
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
testq %rax, %rax
je 0x11d78
cmpq %r12, %r14
setbe %al
cmpq %r12, %r13
setbe %cl
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testb %cl, %al
je 0x11ddf
jmp 0x11f41
movq 0x58(%rbx), %rsi
xorl %eax, %eax
movq %r15, %rcx
movb %cl, (%rsp,%rax)
shrq $0x8, %r15
incq %rax
cmpq $0x4, %rax
jne 0x11d7e
cmpq $0x100, %rcx            # imm = 0x100
jb 0x11da1
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movq %r14, 0x8(%rsp)
cmpq %r12, %r14
seta %r14b
cmpq %r12, %r13
seta %r15b
movq 0x38(%rbx), %rdi
movq %rsp, %rdx
movl $0x4, %ecx
callq *0x10(%rbx)
xorl %ebp, %ebp
cmpq $0x4, %rax
setne %cl
orb %r14b, %r15b
je 0x11ea0
movb %cl, %bpl
negl %ebp
movq 0x8(%rsp), %r14
movq 0x10140(%rbx), %rdx
testq %rdx, %rdx
je 0x11f3b
movq 0x58(%rbx), %rsi
addq $0x4, %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0xc4e0
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %rax, %rax
jne 0x11f41
testl %ebp, %ebp
jne 0x11f41
movq 0x58(%rbx), %rsi
xorl %eax, %eax
movq %r14, %rcx
movb %cl, (%rsp,%rax)
shrq $0x8, %r14
incq %rax
cmpq $0x8, %rax
jne 0x11e1e
cmpq $0x100, %rcx            # imm = 0x100
jb 0x11e42
movq $-0x1, (%rsp)
movq 0x38(%rbx), %rdi
movq %rsp, %rdx
movl $0x8, %ecx
callq *0x10(%rbx)
cmpq $0x8, %rax
jne 0x11f41
movq 0x58(%rbx), %rsi
xorl %eax, %eax
movq %r13, %rcx
movb %cl, (%rsp,%rax)
shrq $0x8, %r13
incq %rax
cmpq $0x8, %rax
jne 0x11e61
cmpq $0x100, %rcx            # imm = 0x100
jb 0x11e85
movq $-0x1, (%rsp)
movq 0x38(%rbx), %rdi
movq %rsp, %rdx
movl $0x8, %ecx
callq *0x10(%rbx)
xorl %r15d, %r15d
cmpq $0x8, %rax
jmp 0x11f32
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpq $0x4, %rax
jne 0x11f41
movq 0x58(%rbx), %rsi
xorl %eax, %eax
movq %r13, %rcx
movb %cl, (%rsp,%rax)
shrq $0x8, %r13
incq %rax
cmpq $0x4, %rax
jne 0x11eb6
cmpq $0x100, %rcx            # imm = 0x100
movq 0x8(%rsp), %r14
jb 0x11ede
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movq 0x38(%rbx), %rdi
movq %rsp, %rdx
movl $0x4, %ecx
callq *0x10(%rbx)
cmpq $0x4, %rax
jne 0x11f41
movq 0x58(%rbx), %rsi
xorl %eax, %eax
movq %r14, %rcx
movb %cl, (%rsp,%rax)
shrq $0x8, %r14
incq %rax
cmpq $0x4, %rax
jne 0x11ef9
cmpq $0x100, %rcx            # imm = 0x100
jb 0x11f1c
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movq 0x38(%rbx), %rdi
movq %rsp, %rdx
movl $0x4, %ecx
callq *0x10(%rbx)
xorl %r15d, %r15d
cmpq $0x4, %rax
setne %r15b
negl %r15d
jmp 0x11f41
movl $0xffffff99, %r15d      # 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 %r15d, %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