// File: /workspace/github_c_makefile_star2_O1/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:
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
testq %rdi, %rdi
je 0x43fe
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpq $0x0, 0x58(%rdi)
je 0x43f0
cmpq $0x0, (%rbx)
je 0x43f0
cmpq $0x0, 0x18(%rbx)
je 0x43f0
cmpl $0x1, 0x48(%rbx)
jbe 0x43ff
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
cmpl $0x4, %esi
setne %al
leal -0x5(%rax,%rax,4), %ebp
movl $0xfffffffb, %eax       # imm = 0xFFFFFFFB
leaq 0x4d11(%rip), %r14      # 0x9128
leaq 0x4d42(%rip), %r12      # 0x9160
leaq 0x4d6a(%rip), %r13      # 0x918f
leaq 0x4d7a(%rip), %r15      # 0x91a6
movq 0x58(%rbx), %rcx
movl (%rcx), %edx
cmpq $0xd, %rdx
ja 0x4683
movslq (%r14,%rdx,4), %rdx
addq %r14, %rdx
jmpq *%rdx
movl 0x8(%rbx), %edx
testl %edx, %edx
je 0x43f0
decl %edx
movl %edx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movzbl (%rax), %edx
movl %edx, 0x8(%rcx)
andl $0xf, %edx
movq 0x58(%rbx), %rax
cmpl $0x5, %edx
jne 0x4495
movl 0x8(%rax), %ecx
shrl $0x4, %ecx
addl $0x8, %ecx
cmpl 0x1c(%rax), %ecx
jbe 0x44a4
movl $0xd, (%rax)
leaq 0x4cef(%rip), %rcx      # 0x917b
movq %rcx, 0x50(%rbx)
jmp 0x465b
movl $0xd, (%rax)
movq %r12, 0x50(%rbx)
jmp 0x465b
movl $0x1, (%rax)
movl %ebp, %eax
movl 0x8(%rbx), %ecx
testl %ecx, %ecx
je 0x43f0
decl %ecx
movl %ecx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rcx
movq 0x58(%rbx), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movzbl (%rcx), %ecx
movl 0x8(%rax), %edx
shll $0x8, %edx
orl %ecx, %edx
imull $0xbdef7bdf, %edx, %ecx # imm = 0xBDEF7BDF
cmpl $0x8421085, %ecx        # imm = 0x8421085
jb 0x44f6
movl $0xd, (%rax)
movq %r13, 0x50(%rbx)
jmp 0x465b
movl $0x7, (%rax)
movl %ebp, %eax
movq 0x58(%rbx), %rcx
movq 0x20(%rcx), %rdi
movq %rbx, %rsi
movl %eax, %edx
callq 0x66df
testl %eax, %eax
je 0x4534
cmpl $-0x3, %eax
jne 0x4536
movq 0x58(%rbx), %rax
movl $0xd, (%rax)
movl $0x0, 0x8(%rax)
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jmp 0x442c
movl %ebp, %eax
cmpl $0x1, %eax
jne 0x43f0
movq 0x58(%rbx), %rdx
movq 0x20(%rdx), %rdi
addq $0x8, %rdx
movq %rbx, %rsi
callq 0x6590
movq 0x58(%rbx), %rax
cmpl $0x0, 0x18(%rax)
je 0x456a
movl $0xc, (%rax)
movl %ebp, %eax
jmp 0x442c
movl $0x8, (%rax)
movl %ebp, %eax
movl 0x8(%rbx), %ecx
testl %ecx, %ecx
je 0x43f0
decl %ecx
movl %ecx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
movq 0x58(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movzbl (%rax), %eax
shll $0x18, %eax
movq %rax, 0x10(%rcx)
movq 0x58(%rbx), %rax
movl $0x9, (%rax)
movl %ebp, %eax
movl 0x8(%rbx), %ecx
testl %ecx, %ecx
je 0x43f0
decl %ecx
movl %ecx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
movq 0x58(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movzbl (%rax), %eax
shll $0x10, %eax
addq %rax, 0x10(%rcx)
movq 0x58(%rbx), %rax
movl $0xa, (%rax)
movl %ebp, %eax
movl 0x8(%rbx), %ecx
testl %ecx, %ecx
je 0x43f0
decl %ecx
movl %ecx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
movq 0x58(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
movzbl (%rax), %eax
shll $0x8, %eax
addq %rax, 0x10(%rcx)
movq 0x58(%rbx), %rax
movl $0xb, (%rax)
movl %ebp, %eax
movl 0x8(%rbx), %ecx
testl %ecx, %ecx
je 0x43f0
decl %ecx
movl %ecx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
movq 0x58(%rbx), %rcx
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 0x4669
movl $0xd, (%rax)
movq %r15, 0x50(%rbx)
movl $0x5, 0x8(%rax)
movl %ebp, %eax
jmp 0x442c
movl $0xc, (%rax)
movl $0x1, %eax
jmp 0x43f0
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jmp 0x43f0
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0x43f0