// File: /workspace/github_c_makefile_star2_O3/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
subq $0x18, %rsp
testq %rdi, %rdi
je 0x1253d
movq %rsi, %r14
movq %rdi, %rbx
xorl %r15d, %r15d
cmpl $0x1, 0x70(%rdi)
jne 0x120ce
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xc410
movl %eax, %r15d
testq %r14, %r14
jne 0x120da
movq 0x10170(%rbx), %r14
movq 0x58(%rbx), %rsi
movq %rbx, %rdi
callq 0xceb0
movq %rax, %r12
xorl %ebp, %ebp
testl %r15d, %r15d
jne 0x12145
movq 0x60(%rbx), %r13
xorl %r15d, %r15d
testq %r13, %r13
je 0x12145
xorl %ebp, %ebp
movq 0x10(%r13), %rcx
testl %r15d, %r15d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jne 0x12139
testq %rcx, %rcx
je 0x12134
movq 0x38(%rbx), %rdi
movq 0x58(%rbx), %rsi
leaq 0x20(%r13), %rdx
callq *0x10(%rbx)
movq 0x10(%r13), %rcx
xorl %r15d, %r15d
cmpq %rcx, %rax
setne %r15b
negl %r15d
jmp 0x12139
xorl %ecx, %ecx
xorl %r15d, %r15d
addq %rcx, %rbp
movq (%r13), %r13
testq %r13, %r13
jne 0x120fe
movq %r14, 0x10(%rsp)
leaq 0x60(%rbx), %r14
movq 0x60(%rbx), %rdi
testq %rdi, %rdi
je 0x12167
movq (%rdi), %r13
callq 0xc0c0
movq %r13, %rdi
testq %r13, %r13
jne 0x12157
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movq %r12, %rax
subq 0x10160(%rbx), %rax
cmpq %rcx, %rax
ja 0x12193
cmpq $0x10000, 0x10168(%rbx) # imm = 0x10000
jb 0x12491
movq 0x58(%rbx), %rsi
movq %rbx, %rdi
callq 0xceb0
movq %rax, %r13
movq 0x58(%rbx), %rsi
movl $0x6064b50, %eax        # imm = 0x6064B50
xorl %ecx, %ecx
movb %al, 0x8(%rsp,%rcx)
shrl $0x8, %eax
incq %rcx
cmpq $0x4, %rcx
jne 0x121ad
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x4, %ecx
callq *0x10(%rbx)
cmpq $0x4, %rax
jne 0x123c5
movq 0x58(%rbx), %rsi
movb $0x2c, %cl
xorl %eax, %eax
movb %cl, 0x8(%rsp,%rax)
incq %rax
xorl %ecx, %ecx
cmpq $0x8, %rax
jne 0x121e0
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x8, %ecx
callq *0x10(%rbx)
cmpq $0x8, %rax
jne 0x123c5
movq 0x58(%rbx), %rsi
leaq 0x8(%rsp), %rdx
movw $0x2d, (%rdx)
movq 0x38(%rbx), %rdi
movl $0x2, %ecx
callq *0x10(%rbx)
cmpq $0x2, %rax
jne 0x123c5
movq 0x58(%rbx), %rsi
leaq 0x8(%rsp), %rdx
movw $0x2d, (%rdx)
movq 0x38(%rbx), %rdi
movl $0x2, %ecx
callq *0x10(%rbx)
cmpq $0x2, %rax
jne 0x123c5
movq 0x58(%rbx), %rsi
leaq 0x8(%rsp), %rdx
movl $0x0, (%rdx)
movq 0x38(%rbx), %rdi
movl $0x4, %ecx
callq *0x10(%rbx)
cmpq $0x4, %rax
jne 0x123c5
movq 0x58(%rbx), %rsi
leaq 0x8(%rsp), %rdx
movl $0x0, (%rdx)
movq 0x38(%rbx), %rdi
movl $0x4, %ecx
callq *0x10(%rbx)
cmpq $0x4, %rax
jne 0x123c5
movq 0x58(%rbx), %rsi
movq 0x10168(%rbx), %rax
xorl %ecx, %ecx
movq %rax, %rdx
movb %dl, 0x8(%rsp,%rcx)
shrq $0x8, %rax
incq %rcx
cmpq $0x8, %rcx
jne 0x122a9
cmpq $0x100, %rdx            # imm = 0x100
jb 0x122cf
movq $-0x1, 0x8(%rsp)
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x8, %ecx
callq *0x10(%rbx)
cmpq $0x8, %rax
jne 0x123c5
movq 0x58(%rbx), %rsi
movq 0x10168(%rbx), %rax
xorl %ecx, %ecx
movq %rax, %rdx
movb %dl, 0x8(%rsp,%rcx)
shrq $0x8, %rax
incq %rcx
cmpq $0x8, %rcx
jne 0x122f7
cmpq $0x100, %rdx            # imm = 0x100
jb 0x1231d
movq $-0x1, 0x8(%rsp)
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x8, %ecx
callq *0x10(%rbx)
cmpq $0x8, %rax
jne 0x123c5
movq 0x58(%rbx), %rsi
xorl %eax, %eax
movq %rbp, %rcx
movq %rcx, %rdx
movb %dl, 0x8(%rsp,%rax)
shrq $0x8, %rcx
incq %rax
cmpq $0x8, %rax
jne 0x12341
cmpq $0x100, %rdx            # imm = 0x100
jb 0x12367
movq $-0x1, 0x8(%rsp)
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x8, %ecx
callq *0x10(%rbx)
cmpq $0x8, %rax
jne 0x123c5
movq %r12, %rax
subq 0x10160(%rbx), %rax
movq 0x58(%rbx), %rsi
xorl %ecx, %ecx
movq %rax, %rdx
movb %dl, 0x8(%rsp,%rcx)
shrq $0x8, %rax
incq %rcx
cmpq $0x8, %rcx
jne 0x1238e
cmpq $0x100, %rdx            # imm = 0x100
jb 0x123b4
movq $-0x1, 0x8(%rsp)
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x8, %ecx
callq *0x10(%rbx)
movq 0x10160(%rbx), %r14
movq 0x58(%rbx), %rsi
movl $0x7064b50, %eax        # imm = 0x7064B50
xorl %ecx, %ecx
movb %al, 0x8(%rsp,%rcx)
shrl $0x8, %eax
incq %rcx
cmpq $0x4, %rcx
jne 0x123d7
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x4, %ecx
callq *0x10(%rbx)
cmpq $0x4, %rax
jne 0x12491
movq 0x58(%rbx), %rsi
leaq 0x8(%rsp), %rdx
movl $0x0, (%rdx)
movq 0x38(%rbx), %rdi
movl $0x4, %ecx
callq *0x10(%rbx)
cmpq $0x4, %rax
jne 0x12491
subq %r14, %r13
movq 0x58(%rbx), %rsi
xorl %eax, %eax
movq %r13, %rcx
movb %cl, 0x8(%rsp,%rax)
shrq $0x8, %r13
incq %rax
cmpq $0x8, %rax
jne 0x1242c
cmpq $0x100, %rcx            # imm = 0x100
jb 0x12452
movq $-0x1, 0x8(%rsp)
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x8, %ecx
callq *0x10(%rbx)
cmpq $0x8, %rax
jne 0x12491
movq 0x58(%rbx), %rsi
movb $0x1, %cl
xorl %eax, %eax
movb %cl, 0x8(%rsp,%rax)
incq %rax
xorl %ecx, %ecx
cmpq $0x4, %rax
jne 0x12471
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x4, %ecx
callq *0x10(%rbx)
testl %r15d, %r15d
jne 0x126da
movq 0x58(%rbx), %rsi
movl $0x6054b50, %eax        # imm = 0x6054B50
xorl %ecx, %ecx
movb %al, 0x8(%rsp,%rcx)
shrl $0x8, %eax
incq %rcx
cmpq $0x4, %rcx
jne 0x124a5
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x4, %ecx
callq *0x10(%rbx)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpq $0x4, %rax
jne 0x126da
movq 0x58(%rbx), %rsi
leaq 0x8(%rsp), %rdx
movw $0x0, (%rdx)
movq 0x38(%rbx), %rdi
movl $0x2, %ecx
callq *0x10(%rbx)
cmpq $0x2, %rax
jne 0x126da
movq 0x58(%rbx), %rsi
leaq 0x8(%rsp), %rdx
movw $0x0, (%rdx)
movq 0x38(%rbx), %rdi
movl $0x2, %ecx
callq *0x10(%rbx)
cmpq $0x2, %rax
jne 0x126da
movq 0x10168(%rbx), %rax
movq 0x58(%rbx), %rsi
leaq 0x8(%rsp), %rdx
cmpq $0xffff, %rax           # imm = 0xFFFF
jb 0x12547
movw $0xffff, (%rdx)         # imm = 0xFFFF
jmp 0x1254a
movl $0xffffff9a, %ebp       # imm = 0xFFFFFF9A
jmp 0x1270a
movw %ax, (%rdx)
movq 0x38(%rbx), %rdi
movl $0x2, %ecx
callq *0x10(%rbx)
cmpq $0x2, %rax
jne 0x126da
movq 0x10168(%rbx), %rax
movq 0x58(%rbx), %rsi
leaq 0x8(%rsp), %rdx
cmpq $0xffff, %rax           # imm = 0xFFFF
jb 0x1257f
movw $0xffff, (%rdx)         # imm = 0xFFFF
jmp 0x12582
movw %ax, (%rdx)
movq 0x38(%rbx), %rdi
movl $0x2, %ecx
callq *0x10(%rbx)
cmpq $0x2, %rax
jne 0x126da
movq 0x58(%rbx), %rsi
xorl %eax, %eax
movq %rbp, %rcx
movb %cl, 0x8(%rsp,%rax)
shrq $0x8, %rbp
incq %rax
cmpq $0x4, %rax
jne 0x1259e
cmpq $0x100, %rcx            # imm = 0x100
jb 0x125c3
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x4, %ecx
callq *0x10(%rbx)
cmpq $0x4, %rax
jne 0x126da
subq 0x10160(%rbx), %r12
movq 0x58(%rbx), %rsi
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmpq %rax, %r12
jbe 0x1260c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movb %al, 0x8(%rsp,%rcx)
shrl $0x8, %eax
incq %rcx
cmpq $0x4, %rcx
jne 0x125fa
jmp 0x12633
xorl %eax, %eax
movq %r12, %rcx
movb %cl, 0x8(%rsp,%rax)
shrq $0x8, %r12
incq %rax
cmpq $0x4, %rax
jne 0x1260e
cmpq $0x100, %rcx            # imm = 0x100
jb 0x12633
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x4, %ecx
callq *0x10(%rbx)
cmpq $0x4, %rax
jne 0x126da
movq 0x10(%rsp), %r14
testq %r14, %r14
je 0x12688
movq %r14, %rdi
callq 0xc480
movq %rax, %r12
movq 0x58(%rbx), %rsi
movl %r12d, %r15d
movw %r12w, 0x8(%rsp)
cmpl $0x10000, %r12d         # imm = 0x10000
jb 0x12699
movw $0xffff, 0x8(%rsp)      # imm = 0xFFFF
movl $0x1, %r12d
jmp 0x12699
movq 0x58(%rbx), %rsi
movw $0x0, 0x8(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x38(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movl $0x2, %ecx
callq *0x10(%rbx)
cmpq $0x2, %rax
setne %cl
testl %r12d, %r12d
je 0x126d3
cmpq $0x2, %rax
jne 0x126d3
movq 0x38(%rbx), %rdi
movq 0x58(%rbx), %rsi
movq %r14, %rdx
movq %r15, %rcx
callq *0x10(%rbx)
cmpq %r15, %rax
setne %cl
movzbl %cl, %r15d
negl %r15d
movq 0x38(%rbx), %rdi
movq 0x58(%rbx), %rsi
callq *0x28(%rbx)
xorl %ebp, %ebp
cmpl $0x1, %r15d
sbbl %ebp, %ebp
orl %r15d, %ebp
testl %eax, %eax
cmovel %r15d, %ebp
movq 0x10170(%rbx), %rdi
callq 0xc0c0
movq %rbx, %rdi
callq 0xc0c0
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq