// File: /workspace/github_c_makefile_star2_O2/Paxa[P]fast_excel/libxlsxwriter/third_party/minizip/zip.c
// Function: zipClose
extern int ZEXPORT zipClose(zipFile file, const char* global_comment) {
    zip64_internal* zi;
    int err = 0;
    uLong size_centraldir = 0;
    ZPOS64_T centraldir_pos_inzip;
    ZPOS64_T pos;

    if (file == NULL)
        return ZIP_PARAMERROR;

    zi = (zip64_internal*)file;

    if (zi->in_opened_file_inzip == 1)
    {
        err = zipCloseFileInZip (file);
    }

#ifndef NO_ADDFILEINEXISTINGZIP
    if (global_comment==NULL)
        global_comment = zi->globalcomment;
#endif

    centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);

    if (err==ZIP_OK)
    {
        linkedlist_datablock_internal* ldi = zi->central_dir.first_block;
        while (ldi!=NULL)
        {
            if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
            {
                if (ZWRITE64(zi->z_filefunc,zi->filestream, ldi->data, ldi->filled_in_this_block) != ldi->filled_in_this_block)
                    err = ZIP_ERRNO;
            }

            size_centraldir += ldi->filled_in_this_block;
            ldi = ldi->next_datablock;
        }
    }
    free_linkedlist(&(zi->central_dir));

    pos = centraldir_pos_inzip - zi->add_position_when_writing_offset;
    if(pos >= 0xffffffff || zi->number_entry > 0xFFFF)
    {
      ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream);
      Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);

      Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos);
    }

    if (err==ZIP_OK)
      err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);

    if(err == ZIP_OK)
      err = Write_GlobalComment(zi, global_comment);

    if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0)
        if (err == ZIP_OK)
            err = ZIP_ERRNO;

#ifndef NO_ADDFILEINEXISTINGZIP
    free(zi->globalcomment);
#endif
    free(zi);

    return err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0xf152
movq %rsi, %r14
movq %rdi, %rbx
xorl %ebp, %ebp
cmpl $0x1, 0x70(%rdi)
jne 0xf12b
movq %rbx, %rdi
callq 0xc210
movl %eax, %ebp
testq %r14, %r14
jne 0xf137
movq 0x10170(%rbx), %r14
movq 0x58(%rbx), %rsi
movq %rbx, %rdi
callq 0xcf30
movq %rax, (%rsp)
xorl %edx, %edx
testl %ebp, %ebp
je 0xf15b
xorl %r12d, %r12d
jmp 0xf1a9
pushq $-0x66
popq %r14
jmp 0xf437
leaq 0x60(%rbx), %r13
pushq $-0x1
popq %rbp
xorl %r12d, %r12d
movq (%r13), %r13
testq %r13, %r13
je 0xf1a7
movq 0x10(%r13), %rcx
testl %edx, %edx
je 0xf17a
movl %ebp, %edx
jmp 0xf1a2
testq %rcx, %rcx
je 0xf19e
movq 0x38(%rbx), %rdi
movq 0x58(%rbx), %rsi
leaq 0x20(%r13), %rdx
callq *0x10(%rbx)
movq 0x10(%r13), %rcx
xorl %edx, %edx
cmpq %rcx, %rax
setne %dl
negl %edx
jmp 0xf1a2
xorl %ecx, %ecx
xorl %edx, %edx
addq %rcx, %r12
jmp 0xf165
movl %edx, %ebp
leaq 0x60(%rbx), %r13
movq 0x60(%rbx), %rdi
testq %rdi, %rdi
je 0xf1c3
movq (%rdi), %r15
callq 0xc0d0
movq %r15, %rdi
jmp 0xf1b1
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
movq (%rsp), %rax
subq 0x10160(%rbx), %rax
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
cmpq %rcx, %rax
ja 0xf1f1
cmpq $0x10000, 0x10168(%rbx) # imm = 0x10000
jb 0xf354
movq 0x58(%rbx), %rsi
movq %rbx, %rdi
callq 0xcf30
movq %rax, %r13
movq 0x58(%rbx), %rsi
pushq $0x4
popq %rcx
movl $0x6064b50, %edx        # imm = 0x6064B50
movq %rbx, %rdi
callq 0xf0a2
testl %eax, %eax
jne 0xf2f8
movq 0x58(%rbx), %rsi
pushq $0x2c
popq %rdx
pushq $0x8
popq %rcx
movq %rbx, %rdi
callq 0xf0a2
testl %eax, %eax
jne 0xf2f8
movq 0x58(%rbx), %rsi
pushq $0x2d
popq %rdx
pushq $0x2
popq %rcx
movq %rbx, %rdi
callq 0xf0a2
testl %eax, %eax
jne 0xf2f8
movq 0x58(%rbx), %rsi
pushq $0x2d
popq %rdx
pushq $0x2
popq %rcx
movq %rbx, %rdi
callq 0xf0a2
testl %eax, %eax
jne 0xf2f8
movq 0x58(%rbx), %rsi
pushq $0x4
popq %rcx
movq %rbx, %rdi
xorl %edx, %edx
callq 0xf0a2
testl %eax, %eax
jne 0xf2f8
movq 0x58(%rbx), %rsi
pushq $0x4
popq %rcx
movq %rbx, %rdi
xorl %edx, %edx
callq 0xf0a2
testl %eax, %eax
jne 0xf2f8
movq 0x58(%rbx), %rsi
movq 0x10168(%rbx), %rdx
pushq $0x8
popq %rcx
movq %rbx, %rdi
callq 0xf0a2
testl %eax, %eax
jne 0xf2f8
movq 0x58(%rbx), %rsi
movq 0x10168(%rbx), %rdx
pushq $0x8
popq %rcx
movq %rbx, %rdi
callq 0xf0a2
testl %eax, %eax
jne 0xf2f8
movq 0x58(%rbx), %rsi
pushq $0x8
popq %rcx
movq %rbx, %rdi
movq %r12, %rdx
callq 0xf0a2
testl %eax, %eax
jne 0xf2f8
movq (%rsp), %rdx
subq 0x10160(%rbx), %rdx
movq 0x58(%rbx), %rsi
pushq $0x8
popq %rcx
movq %rbx, %rdi
callq 0xf0a2
subq 0x10160(%rbx), %r13
movq 0x58(%rbx), %rsi
pushq $0x4
popq %rcx
movl $0x7064b50, %edx        # imm = 0x7064B50
movq %rbx, %rdi
callq 0xf0a2
testl %eax, %eax
jne 0xf354
movq 0x58(%rbx), %rsi
pushq $0x4
popq %rcx
movq %rbx, %rdi
xorl %edx, %edx
callq 0xf0a2
testl %eax, %eax
jne 0xf354
movq 0x58(%rbx), %rsi
pushq $0x8
popq %rcx
movq %rbx, %rdi
movq %r13, %rdx
callq 0xf0a2
testl %eax, %eax
jne 0xf354
movq 0x58(%rbx), %rsi
pushq $0x1
popq %rdx
pushq $0x4
popq %rcx
movq %rbx, %rdi
callq 0xf0a2
testl %ebp, %ebp
jne 0xf406
movq 0x58(%rbx), %rsi
pushq $0x4
popq %rcx
movl $0x6054b50, %edx        # imm = 0x6054B50
movq %rbx, %rdi
callq 0xf0a2
testl %eax, %eax
jne 0xf403
movq 0x58(%rbx), %rsi
pushq $0x2
popq %rcx
movq %rbx, %rdi
xorl %edx, %edx
callq 0xf0a2
testl %eax, %eax
jne 0xf403
movq 0x58(%rbx), %rsi
pushq $0x2
popq %rcx
movq %rbx, %rdi
xorl %edx, %edx
callq 0xf0a2
testl %eax, %eax
jne 0xf403
movq 0x10168(%rbx), %rdx
movq 0x58(%rbx), %rsi
movl $0xffff, %r13d          # imm = 0xFFFF
cmpq %r13, %rdx
cmovaeq %r13, %rdx
pushq $0x2
popq %rcx
movq %rbx, %rdi
callq 0xf0a2
testl %eax, %eax
jne 0xf403
movq 0x10168(%rbx), %rax
movq 0x58(%rbx), %rsi
cmpq %r13, %rax
cmovbq %rax, %r13
pushq $0x2
popq %rcx
movq %rbx, %rdi
movq %r13, %rdx
callq 0xf0a2
testl %eax, %eax
jne 0xf403
movq 0x58(%rbx), %rsi
pushq $0x4
popq %rcx
movq %rbx, %rdi
movq %r12, %rdx
callq 0xf0a2
testl %eax, %eax
je 0xf449
pushq $-0x1
popq %rbp
movq 0x38(%rbx), %rdi
movq 0x58(%rbx), %rsi
callq *0x28(%rbx)
xorl %r14d, %r14d
cmpl $0x1, %ebp
sbbl %r14d, %r14d
orl %ebp, %r14d
testl %eax, %eax
cmovel %ebp, %r14d
movq 0x10170(%rbx), %rdi
callq 0xc0d0
movq %rbx, %rdi
callq 0xc0d0
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rdx
subq 0x10160(%rbx), %rdx
movq 0x58(%rbx), %rsi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rdx
cmovaeq %rax, %rdx
pushq $0x4
popq %rcx
movq %rbx, %rdi
callq 0xf0a2
pushq $-0x1
popq %rbp
testl %eax, %eax
jne 0xf406
testq %r14, %r14
je 0xf488
movq %r14, %rdi
callq 0xc4c0
movq %rax, %r12
jmp 0xf48b
xorl %r12d, %r12d
movq 0x58(%rbx), %rsi
movl %r12d, %r15d
pushq $0x2
popq %rcx
movq %rbx, %rdi
movq %r15, %rdx
callq 0xf0a2
movl %eax, %ebp
testl %eax, %eax
setne %al
testl %r12d, %r12d
sete %cl
orb %al, %cl
jne 0xf406
movq 0x38(%rbx), %rdi
movq 0x58(%rbx), %rsi
movq %r14, %rdx
movq %r15, %rcx
callq *0x10(%rbx)
xorl %ebp, %ebp
cmpq %r15, %rax
setne %bpl
negl %ebp
jmp 0xf406