// File: /workspace/github_c_makefile_star2_O2/snej[P]zdelta/inflate.c
// Function: zd_inflate
int ZEXPORT zd_inflate(z, f)
     zd_streamp z;
     int f;
{
  int r;
  uInt b;

  if (z == ZD_NULL || z->state == ZD_NULL || z->next_in == ZD_NULL ||
      z->next_out == ZD_NULL || z->refnum<0 || z->refnum>REFNUM)
    return ZD_STREAM_ERROR;
  f = f == ZD_FINISH ? ZD_BUF_ERROR : ZD_OK;
  r = ZD_BUF_ERROR;
  while (1) switch (z->state->mode)
  {
  case METHOD:
    NEEDBYTE
    if (((z->state->sub.method = NEXTBYTE) & 0xf) != ZD_DEFLATED)
    {
      z->state->mode = BAD;
      z->msg = (char*)"unknown compression method";
      z->state->sub.marker = 5;       /* can't try inflateSync */
      break;
    }

    if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
    {
      z->state->mode = BAD;
      z->msg = (char*)"invalid window size";
      z->state->sub.marker = 5;       /* can't try inflateSync */
      break;
    }

    z->state->mode = FLAG;
  case FLAG:
    NEEDBYTE
    b = NEXTBYTE;
    if (((z->state->sub.method << 8) + b) % 31)
    {
      z->state->mode = BAD;
      z->msg = (char*)"incorrect header check";
      z->state->sub.marker = 5;       /* can't try inflateSync */
      break;
    }
    /* zdelta: no dictionary */
    z->state->mode = BLOCKS;

  case BLOCKS:
    r = inflate_blocks(z->state->blocks, z, r);
    if (r == ZD_DATA_ERROR)
    {
      z->state->mode = BAD;
      z->state->sub.marker = 0;       /* can try inflateSync */
      break;
    }
    if (r == ZD_OK)
      r = f;
    if (r != ZD_STREAM_END)
      return r;
    r = f;
    inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
    if (z->state->nowrap)
    {
      z->state->mode = DONE;
      break;
    }
    z->state->mode = CHECK4;
  case CHECK4:
    NEEDBYTE
    z->state->sub.check.need = (uLong)NEXTBYTE << 24;
    z->state->mode = CHECK3;
  case CHECK3:
    NEEDBYTE
    z->state->sub.check.need += (uLong)NEXTBYTE << 16;
    z->state->mode = CHECK2;
  case CHECK2:
    NEEDBYTE
    z->state->sub.check.need += (uLong)NEXTBYTE << 8;
    z->state->mode = CHECK1;
  case CHECK1:
    NEEDBYTE
    z->state->sub.check.need += (uLong)NEXTBYTE;
    if (z->state->sub.check.was != z->state->sub.check.need)
    {
      z->state->mode = BAD;
      z->msg = (char*)"incorrect data check";
      z->state->sub.marker = 5;       /* can't try inflateSync */
      break;
    }
    Tracev((stderr, "inflate: zlib check ok\n"));
    z->state->mode = DONE;
  case DONE:
    return ZD_STREAM_END;
  case BAD:
    return ZD_DATA_ERROR;
  default:
    return ZD_STREAM_ERROR;
  }

// Assembly:
pushq $-0x2
popq %rax
testq %rdi, %rdi
je 0x4499
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x58(%rdi), %rcx
testq %rcx, %rcx
je 0x448b
cmpq $0x0, (%rbx)
je 0x448b
cmpq $0x0, 0x18(%rbx)
je 0x448b
cmpl $0x1, 0x48(%rbx)
ja 0x448b
xorl %eax, %eax
cmpl $0x4, %esi
setne %al
leal -0x5(%rax,%rax,4), %r14d
pushq $-0x5
popq %rax
pushq $-0x2
popq %rbp
leaq 0x4ee1(%rip), %r12      # 0x9128
pushq $0x1f
popq %r13
leaq 0x4f54(%rip), %r15      # 0x91a6
movl (%rcx), %edx
cmpq $0xd, %rdx
ja 0x4489
movslq (%r12,%rdx,4), %rdx
addq %r12, %rdx
jmpq *%rdx
movl 0x8(%rbx), %edx
testl %edx, %edx
je 0x448b
decl %edx
movl %edx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movzbl (%rax), %eax
movl %eax, 0x8(%rcx)
andl $0xf, %eax
movq 0x58(%rbx), %rcx
cmpl $0x5, %eax
jne 0x42b4
movl 0x8(%rcx), %eax
shrl $0x4, %eax
addl $0x8, %eax
cmpl 0x1c(%rcx), %eax
jbe 0x42c3
movl $0xd, (%rcx)
leaq 0x4ec9(%rip), %rax      # 0x917b
jmp 0x430b
movl $0xd, (%rcx)
leaq 0x4e9f(%rip), %rax      # 0x9160
jmp 0x430b
movl $0x1, (%rcx)
movl %r14d, %eax
movl 0x8(%rbx), %edx
testl %edx, %edx
je 0x448b
decl %edx
movl %edx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movzbl (%rax), %edx
movl 0x8(%rcx), %eax
shll $0x8, %eax
orl %edx, %eax
xorl %edx, %edx
divl %r13d
testl %edx, %edx
je 0x431b
movl $0xd, (%rcx)
leaq 0x4e84(%rip), %rax      # 0x918f
movq %rax, 0x50(%rbx)
movl $0x5, 0x8(%rcx)
jmp 0x4469
movl $0x7, (%rcx)
movl %r14d, %eax
movq 0x20(%rcx), %rdi
movq %rbx, %rsi
movl %eax, %edx
callq 0x62e3
cmpl $-0x3, %eax
je 0x436b
movl %eax, %ecx
cmpl $0x1, %eax
jne 0x4480
movq 0x58(%rbx), %rdx
movq 0x20(%rdx), %rdi
addq $0x8, %rdx
movq %rbx, %rsi
callq 0x61a8
movq 0x58(%rbx), %rcx
cmpl $0x0, 0x18(%rcx)
je 0x4381
movl $0xc, (%rcx)
jmp 0x4469
movq 0x58(%rbx), %rax
movl $0xd, (%rax)
andl $0x0, 0x8(%rax)
pushq $-0x3
popq %rax
jmp 0x446c
movl $0x8, (%rcx)
movl %r14d, %eax
movl 0x8(%rbx), %edx
testl %edx, %edx
je 0x448b
decl %edx
movl %edx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movzbl (%rax), %eax
shll $0x18, %eax
movq %rax, 0x10(%rcx)
movq 0x58(%rbx), %rcx
movl $0x9, (%rcx)
movl %r14d, %eax
movl 0x8(%rbx), %edx
testl %edx, %edx
je 0x448b
decl %edx
movl %edx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movzbl (%rax), %eax
shll $0x10, %eax
addq %rax, 0x10(%rcx)
movq 0x58(%rbx), %rcx
movl $0xa, (%rcx)
movl %r14d, %eax
movl 0x8(%rbx), %edx
testl %edx, %edx
je 0x448b
decl %edx
movl %edx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movzbl (%rax), %eax
shll $0x8, %eax
addq %rax, 0x10(%rcx)
movq 0x58(%rbx), %rcx
movl $0xb, (%rcx)
movl %r14d, %eax
movl 0x8(%rbx), %edx
testl %edx, %edx
je 0x448b
decl %edx
movl %edx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movzbl (%rax), %eax
addq %rax, 0x10(%rcx)
movq 0x58(%rbx), %rax
movq 0x8(%rax), %rcx
cmpq 0x10(%rax), %rcx
je 0x4475
movl $0xd, (%rax)
movq %r15, 0x50(%rbx)
movl $0x5, 0x8(%rax)
movl %r14d, %eax
movq 0x58(%rbx), %rcx
jmp 0x4252
movl $0xc, (%rax)
pushq $0x1
popq %rax
jmp 0x448b
movl %ecx, %ebp
movl %r14d, %eax
testl %ecx, %ecx
je 0x448b
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x3
jmp 0x447d