// File: /workspace/github_c_makefile_star2_O2/pali[P]bmfdec/./bmfdec.c
// Function: ds_dec
int ds_dec(void* pin,int lin, void* pout, int lout, int flg)
{ 
  __u8 *p, *pend;
  unsigned u, repoffs;
  int r;
  bits_t bits;

  dblb_rdi(&bits,pin,lin);
  p=(__u8*)pout;pend=p+lout;
  if((dblb_rdn(&bits,16))!=0x5344) return -1;
    
  u=dblb_rdn(&bits,16);
  u=((u&0xff)<<8)|((u>>8)&0xff);
  LOG_DECOMP("DMSDOS: DS decompression version %d\n",u);
  
  do
  { r=0;
    RDN_PR(bits,u);
    switch(u&3)
    {
      case 0:
	bits.pb+=2+6;
	repoffs=(u>>2)&63;
	r=dblb_decrep(&bits,&p,pout,pend,repoffs,-1,flg);
	break;
      case 1:
	bits.pb+=2+7;
	*(p++)=(u>>2)|128;
	break;
      case 2:
	bits.pb+=2+7;
	*(p++)=(u>>2)&127;
	break;
      case 3:
	if(u&4) {  bits.pb+=3+12; repoffs=((u>>3)&4095)+320; }
	else  {  bits.pb+=3+8;  repoffs=((u>>3)&255)+64; };
	r=dblb_decrep(&bits,&p,pout,pend,repoffs,-1,flg);
	break;
    }
  }while((r==0)&&(p<pend)&&(bits.pd<bits.pe||(bits.pd==bits.pe&&bits.pb<16)));
  
  if(r<0) return r;

  if(!(flg&0x4000))
  { 
    u=dblb_rdn(&bits,3);if(u==7) u=dblb_rdn(&bits,12)+320;
    if(u!=0x113f)
    { LOG_DECOMP("DMSDOS: decrb: final sync not found?\n");
      return -2;
    }
  }

  return p-(__u8*)pout;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, %ebp
movl %ecx, %r14d
movq %rdx, %r12
leaq 0x8(%rsp), %rax
movl $0x20, 0x4(%rax)
movq %rdi, 0x8(%rax)
incl %esi
andl $-0x2, %esi
addq %rdi, %rsi
movq %rsi, 0x10(%rax)
movq %rdx, 0x20(%rsp)
pushq $0x10
popq %rsi
movq %rax, %rdi
callq 0x1472
cmpl $0x5344, %eax           # imm = 0x5344
jne 0x1420
movslq %r14d, %r14
addq %r12, %r14
leaq 0x8(%rsp), %r15
pushq $0x10
popq %rsi
movq %r15, %rdi
callq 0x1472
leaq 0x4cf9(%rip), %r13      # 0x6010
movq %r12, %rbx
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %r8d
cmpl $0x10, %ecx
jl 0x1357
shrl $0x10, %r8d
movl %r8d, 0x8(%rsp)
addl $-0x10, %ecx
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
jae 0x1357
leaq 0x2(%rax), %rdx
movq %rdx, 0x10(%rsp)
movzwl (%rax), %eax
shll $0x10, %eax
orl %eax, %r8d
movl %r8d, 0x8(%rsp)
shrl %cl, %r8d
movl %r8d, %eax
andl $0x3, %eax
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
addl $0x8, %ecx
movl %ecx, 0xc(%rsp)
shrl $0x2, %r8d
andl $0x3f, %r8d
jmp 0x13bc
addl $0x9, %ecx
movl %ecx, 0xc(%rsp)
shrl $0x2, %r8d
andb $0x7f, %r8b
jmp 0x13e3
movl %r8d, %eax
andl $0x4, %eax
shrl $0x3, %r8d
testl %eax, %eax
movl $0xfff, %edx            # imm = 0xFFF
movl $0xff, %esi
cmovel %esi, %edx
addl %eax, %ecx
addl $0xb, %ecx
shll $0x6, %eax
andl %r8d, %edx
leal (%rdx,%rax), %r8d
addl $0x40, %r8d
movl %ecx, 0xc(%rsp)
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
movq %r12, %rdx
movq %r14, %rcx
movl %ebp, %r9d
callq 0x14b4
jmp 0x13f1
addl $0x9, %ecx
movl %ecx, 0xc(%rsp)
shrl $0x2, %r8d
orb $-0x80, %r8b
leaq 0x1(%rbx), %rax
movq %rax, 0x20(%rsp)
movb %r8b, (%rbx)
xorl %eax, %eax
movq 0x20(%rsp), %rbx
testl %eax, %eax
jne 0x1425
cmpq %r14, %rbx
jae 0x1425
movq 0x18(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jb 0x131a
jne 0x1429
movl 0xc(%rsp), %ecx
cmpl $0x10, %ecx
jl 0x131e
jmp 0x1429
pushq $-0x1
popq %rax
jmp 0x145f
testl %eax, %eax
js 0x145f
btl $0xe, %ebp
jb 0x145a
leaq 0x8(%rsp), %rdi
pushq $0x3
popq %rsi
callq 0x1472
cmpl $0x7, %eax
jne 0x1453
leaq 0x8(%rsp), %rdi
pushq $0xc
popq %rsi
callq 0x1472
addl $0x140, %eax            # imm = 0x140
cmpl $0x113f, %eax           # imm = 0x113F
jne 0x146e
subl %r12d, %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x2
jmp 0x1422