// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::ProcessBlock(int, unsigned int, int, int)
int CCapsImageStd::ProcessBlock(int blk, uint32_t bitpos, int datasize, int gapsize)
{
	int res;

	// set encoding parameters
	di.encbitpos=bitpos;
	di.encwritebc=0;
	di.encgsvalid=0;
	di.encgapsplit=0;

	// check parameters
	if (blk<0 || blk>=di.blockcount || datasize<0 || gapsize<0)
		return imgeGeneric;

	if (blk >= di.pdt->sipsize)
		return imgeGeneric;

	// set encoding information
	di.block[blk].fdenc=ibieNA;
	di.block[blk].fdbitpos=bitpos;

	PDISKSECTORINFO si=di.pdt->sip+blk;
	si->descdatasize=di.block[blk].blockbits;
	si->descgapsize=di.block[blk].gapbits;
	si->celltype=di.block[blk].celltype;
	si->enctype=di.block[blk].enctype;

	// create block data
	si->datastart=di.encbitpos;
	si->datasize=datasize;
	res=ProcessBlockData(blk, datasize);
	if (res != imgeOk)
		return res;

	// create gap data
	si->gapstart=di.encbitpos;
	si->gapsize=gapsize;
	res=ProcessBlockGap(blk, gapsize);
	if (res != imgeOk)
		return res;

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x18(%rbp), %ecx
movl %ecx, 0x1d8(%rax)
movl $0x0, 0x1dc(%rax)
movl $0x0, 0x1e0(%rax)
movl $0x0, 0x1e4(%rax)
cmpl $0x0, -0x14(%rbp)
jl 0xfae9
movq -0x38(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0x204(%rcx), %eax
jge 0xfae9
cmpl $0x0, -0x1c(%rbp)
jl 0xfae9
cmpl $0x0, -0x20(%rbp)
jge 0xfaf5
movl $0x2, -0x4(%rbp)
jmp 0xfc48
movq -0x38(%rbp), %rcx
movl -0x14(%rbp), %eax
movq 0x210(%rcx), %rcx
cmpl 0xf4(%rcx), %eax
jl 0xfb17
movl $0x2, -0x4(%rbp)
jmp 0xfc48
movq -0x38(%rbp), %rdi
movq 0x1f8(%rdi), %rax
movslq -0x14(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x20(%rax)
movl -0x18(%rbp), %ecx
movq 0x1f8(%rdi), %rax
movslq -0x14(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x24(%rax)
movq 0x210(%rdi), %rax
movq 0xf8(%rax), %rax
movslq -0x14(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq 0x1f8(%rdi), %rax
movslq -0x14(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq 0x1f8(%rdi), %rax
movslq -0x14(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4(%rax)
movq 0x1f8(%rdi), %rax
movslq -0x14(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x28(%rax)
movq 0x1f8(%rdi), %rax
movslq -0x14(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl 0x1d8(%rdi), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x1c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x14(%rbp), %esi
movl -0x1c(%rbp), %edx
callq 0x12d10
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xfc0a
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xfc48
movq -0x38(%rbp), %rdi
movl 0x1d8(%rdi), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x20(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x14(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0x12df0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xfc41
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xfc48
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)