// File: /workspace/github_c_makefile_star2_O0/Paxa[P]fast_excel/libxlsxwriter/third_party/minizip/zip.c
// Function: zipWriteInFileInZip
extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void* buf, unsigned int len) {
    zip64_internal* zi;
    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.crc32 = crc32(zi->ci.crc32,buf,(uInt)len);

#ifdef HAVE_BZIP2
    if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw))
    {
      zi->ci.bstream.next_in = (void*)buf;
      zi->ci.bstream.avail_in = len;
      err = BZ_RUN_OK;

      while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0))
      {
        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;
        }


        if(err != BZ_RUN_OK)
          break;

        if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
        {
          uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32;
//          uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32;
          err=BZ2_bzCompress(&zi->ci.bstream,  BZ_RUN);

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

      if(err == BZ_RUN_OK)
        err = ZIP_OK;
    }
    else
#endif
    {
      zi->ci.stream.next_in = (Bytef*)(uintptr_t)buf;
      zi->ci.stream.avail_in = len;

      while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
      {
          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;
          }


          if(err != ZIP_OK)
              break;

          if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
          {
              uLong uTotalOutBefore = zi->ci.stream.total_out;
              err=deflate(&zi->ci.stream,  Z_NO_FLUSH);

              zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
          }
          else
          {
              uInt copy_this,i;
              if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
                  copy_this = zi->ci.stream.avail_in;
              else
                  copy_this = zi->ci.stream.avail_out;

              for (i = 0; i < copy_this; i++)
                  *(((char*)zi->ci.stream.next_out)+i) =
                      *(((const char*)zi->ci.stream.next_in)+i);
              {
                  zi->ci.stream.avail_in -= copy_this;
                  zi->ci.stream.avail_out-= copy_this;
                  zi->ci.stream.next_in+= copy_this;
                  zi->ci.stream.next_out+= copy_this;
                  zi->ci.stream.total_in+= copy_this;
                  zi->ci.stream.total_out+= copy_this;
                  zi->ci.pos_in_buffered_data += copy_this;
              }
          }
      }// while(...)
    }

    return err;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl $0x0, -0x2c(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xf6dd
movl $0xffffff9a, -0x4(%rbp) # imm = 0xFFFFFF9A
jmp 0xf926
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x70(%rax)
jne 0xf6fb
movl $0xffffff9a, -0x4(%rbp) # imm = 0xFFFFFF9A
jmp 0xf926
movq -0x28(%rbp), %rax
movq 0x10130(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0xc350
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10130(%rax)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x78(%rax)
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x80(%rax)
xorl %eax, %eax
cmpl $0x0, -0x2c(%rbp)
movb %al, -0x41(%rbp)
jne 0xf755
movq -0x28(%rbp), %rax
cmpl $0x0, 0x80(%rax)
seta %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0xf761
jmp 0xf920
movq -0x28(%rbp), %rax
cmpl $0x0, 0x98(%rax)
jne 0xf7ab
movq -0x28(%rbp), %rdi
callq 0xf930
cmpl $-0x1, %eax
jne 0xf783
movl $0xffffffff, -0x2c(%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)
cmpl $0x0, -0x2c(%rbp)
je 0xf7b6
jmp 0xf920
movq -0x28(%rbp), %rax
cmpl $0x8, 0x120(%rax)
jne 0xf817
movq -0x28(%rbp), %rax
cmpl $0x0, 0x124(%rax)
jne 0xf817
movq -0x28(%rbp), %rax
movq 0xa0(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
addq $0x78, %rdi
xorl %esi, %esi
callq 0xc670
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movq 0xa0(%rax), %rax
subq -0x38(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addl 0xec(%rax), %ecx
movl %ecx, 0xec(%rax)
jmp 0xf91b
movq -0x28(%rbp), %rax
movl 0x80(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x98(%rcx), %eax
jae 0xf83c
movq -0x28(%rbp), %rax
movl 0x80(%rax), %eax
movl %eax, -0x3c(%rbp)
jmp 0xf849
movq -0x28(%rbp), %rax
movl 0x98(%rax), %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jae 0xf882
movq -0x28(%rbp), %rax
movq 0x78(%rax), %rax
movl -0x40(%rbp), %ecx
movb (%rax,%rcx), %dl
movq -0x28(%rbp), %rax
movq 0x90(%rax), %rax
movl -0x40(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xf850
movl -0x3c(%rbp), %edx
movq -0x28(%rbp), %rax
movl 0x80(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x80(%rax)
movl -0x3c(%rbp), %edx
movq -0x28(%rbp), %rax
movl 0x98(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x98(%rax)
movl -0x3c(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x78(%rax), %rcx
movl %edx, %edx
addq %rdx, %rcx
movq %rcx, 0x78(%rax)
movl -0x3c(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x90(%rax), %rcx
movl %edx, %edx
addq %rdx, %rcx
movq %rcx, 0x90(%rax)
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq 0x88(%rax), %rcx
movq %rcx, 0x88(%rax)
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq 0xa0(%rax), %rcx
movq %rcx, 0xa0(%rax)
movl -0x3c(%rbp), %ecx
movq -0x28(%rbp), %rax
addl 0xec(%rax), %ecx
movl %ecx, 0xec(%rax)
jmp 0xf739
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop