// File: /workspace/github_c_makefile_star2_O3/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 0x4369
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x58(%rdi), %rdx
testq %rdx, %rdx
je 0x435b
cmpq $0x0, (%rbx)
je 0x435b
cmpq $0x0, 0x18(%rbx)
je 0x435b
cmpl $0x1, 0x48(%rbx)
jbe 0x436a
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 0x4da6(%rip), %r14      # 0x9128
leaq 0x4dd7(%rip), %r12      # 0x9160
leaq 0x4dff(%rip), %r13      # 0x918f
leaq 0x4e0f(%rip), %r15      # 0x91a6
movl (%rdx), %esi
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
cmpq $0xd, %rsi
ja 0x45d5
movslq (%r14,%rsi,4), %rsi
addq %r14, %rsi
jmpq *%rsi
movl 0x8(%rbx), %ecx
testl %ecx, %ecx
je 0x435b
decl %ecx
movl %ecx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rbx)
movzbl (%rax), %eax
movl %eax, 0x8(%rdx)
andl $0xf, %eax
movq 0x58(%rbx), %rdx
cmpl $0x5, %eax
jne 0x43fe
movl 0x8(%rdx), %eax
shrl $0x4, %eax
addl $0x8, %eax
cmpl 0x1c(%rdx), %eax
jbe 0x440a
movl $0xd, (%rdx)
leaq 0x4d83(%rip), %rax      # 0x917b
movq %rax, 0x50(%rbx)
jmp 0x4452
movl $0xd, (%rdx)
movq %r12, 0x50(%rbx)
jmp 0x4452
movl $0x1, (%rdx)
movl %ebp, %eax
movl 0x8(%rbx), %ecx
testl %ecx, %ecx
je 0x435b
decl %ecx
movl %ecx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rbx)
movzbl (%rax), %eax
movl 0x8(%rdx), %ecx
shll $0x8, %ecx
orl %eax, %ecx
imull $0xbdef7bdf, %ecx, %eax # imm = 0xBDEF7BDF
cmpl $0x8421085, %eax        # imm = 0x8421085
jb 0x445e
movl $0xd, (%rdx)
movq %r13, 0x50(%rbx)
movl $0x5, 0x8(%rdx)
jmp 0x45b0
movl $0x7, (%rdx)
movl %ebp, %eax
movq 0x20(%rdx), %rdi
movq %rbx, %rsi
movl %eax, %edx
callq 0x697f
cmpl $-0x3, %eax
je 0x44ad
movl %eax, %ecx
cmpl $0x1, %eax
jne 0x45cb
movq 0x58(%rbx), %rdx
movq 0x20(%rdx), %rdi
addq $0x8, %rdx
movq %rbx, %rsi
callq 0x682c
movq 0x58(%rbx), %rdx
cmpl $0x0, 0x18(%rdx)
je 0x44c8
movl $0xc, (%rdx)
jmp 0x45b0
movq 0x58(%rbx), %rax
movl $0xd, (%rax)
movl $0x0, 0x8(%rax)
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jmp 0x45b2
movl $0x8, (%rdx)
movl %ebp, %eax
movl 0x8(%rbx), %ecx
testl %ecx, %ecx
je 0x435b
decl %ecx
movl %ecx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rbx)
movzbl (%rax), %eax
shll $0x18, %eax
movq %rax, 0x10(%rdx)
movq 0x58(%rbx), %rdx
movl $0x9, (%rdx)
movl %ebp, %eax
movl 0x8(%rbx), %ecx
testl %ecx, %ecx
je 0x435b
decl %ecx
movl %ecx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rbx)
movzbl (%rax), %eax
shll $0x10, %eax
addq %rax, 0x10(%rdx)
movq 0x58(%rbx), %rdx
movl $0xa, (%rdx)
movl %ebp, %eax
movl 0x8(%rbx), %ecx
testl %ecx, %ecx
je 0x435b
decl %ecx
movl %ecx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rbx)
movzbl (%rax), %eax
shll $0x8, %eax
addq %rax, 0x10(%rdx)
movq 0x58(%rbx), %rdx
movl $0xb, (%rdx)
movl %ebp, %eax
movl 0x8(%rbx), %ecx
testl %ecx, %ecx
je 0x435b
decl %ecx
movl %ecx, 0x8(%rbx)
incq 0x10(%rbx)
movq (%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%rbx)
movzbl (%rax), %eax
addq %rax, 0x10(%rdx)
movq 0x58(%rbx), %rax
movq 0x8(%rax), %rcx
cmpq 0x10(%rax), %rcx
je 0x45bb
movl $0xd, (%rax)
movq %r15, 0x50(%rbx)
movl $0x5, 0x8(%rax)
movl %ebp, %eax
movq 0x58(%rbx), %rdx
jmp 0x4397
movl $0xc, (%rax)
movl $0x1, %eax
jmp 0x435b
movl %ebp, %eax
testl %ecx, %ecx
je 0x435b
movl %ecx, %eax
jmp 0x435b
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jmp 0x435b