LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::InitDecoder()
int CCapsImageStd::InitDecoder()
{
	// stop if image descriptor is not available
	if (!dii.civalid)
		return imgeIncompatible;

	// allocate and create block descriptors
	AllocImageBlock(di.pdt->ci.blkcnt);
	di.blockcount=di.pdt->ci.blkcnt;

	int blk;

	// initialize block descriptors from image data
	for (blk=0; blk < di.blockcount; blk++) {
		int res=GetBlock(di.block+blk, blk);
		if (res != imgeOk)
			return res;
	}

	// reset track info
	di.dsctrackbc=0;
	di.dscdatabc=0;
	di.dscgapbc=0;
	di.dscstartbit=0;

	// calculate data and gap sizes
	for (blk=0; blk < di.blockcount; blk++) {
		PIMAGEBLOCKINFO pi=di.block+blk;

		// only allow gap size of 1 byte or more
		if (pi->gapbits < 8)
			pi->gapbits=0;

		di.dscdatabc+=pi->blockbits;
		di.dscgapbc+=pi->gapbits;
	}

	// track size
	di.dsctrackbc=di.dscdatabc+di.dscgapbc;

	// set encoding start position, limit to track size
	if (di.dsctrackbc)
		di.dscstartbit=di.pdt->ci.startbit % di.dsctrackbc;

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpl $0x0, 0x48(%rax)
jne 0xf2d6
movl $0xe, -0x4(%rbp)
jmp 0xf446
movq -0x28(%rbp), %rdi
movq 0x210(%rdi), %rax
movl 0x128(%rax), %esi
callq 0x10dc0
movq -0x28(%rbp), %rax
movq 0x210(%rax), %rcx
movl 0x128(%rcx), %ecx
movl %ecx, 0x204(%rax)
movl $0x0, -0x14(%rbp)
movq -0x28(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0x204(%rcx), %eax
jge 0xf358
movq -0x28(%rbp), %rdi
movq 0x1f8(%rdi), %rsi
movslq -0x14(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rsi
movl -0x14(%rbp), %edx
callq 0x10e90
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0xf34b
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xf446
jmp 0xf34d
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xf30a
movq -0x28(%rbp), %rax
movl $0x0, 0x1c8(%rax)
movl $0x0, 0x1cc(%rax)
movl $0x0, 0x1d0(%rax)
movl $0x0, 0x1d4(%rax)
movl $0x0, -0x14(%rbp)
movq -0x28(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0x204(%rcx), %eax
jge 0xf3fd
movq -0x28(%rbp), %rax
movq 0x1f8(%rax), %rax
movslq -0x14(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jae 0xf3c9
movq -0x20(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
addl 0x1cc(%rax), %ecx
movl %ecx, 0x1cc(%rax)
movq -0x20(%rbp), %rcx
movl 0x4(%rcx), %ecx
addl 0x1d0(%rax), %ecx
movl %ecx, 0x1d0(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xf38b
movq -0x28(%rbp), %rax
movl 0x1cc(%rax), %ecx
addl 0x1d0(%rax), %ecx
movl %ecx, 0x1c8(%rax)
cmpl $0x0, 0x1c8(%rax)
je 0xf43f
movq -0x28(%rbp), %rcx
movq 0x210(%rcx), %rax
movl 0x118(%rax), %eax
xorl %edx, %edx
divl 0x1c8(%rcx)
movq -0x28(%rbp), %rax
movl %edx, 0x1d4(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::MFMFixup()
void CCapsImageStd::MFMFixup()
{
	// process all blocks
	for (int blk=0; blk < di.blockcount; blk++) {
		PIMAGEBLOCKINFO pi=di.block+blk;

		// don't fix if not MFM
		if (pi->fdenc != ibieMFM)
			continue;

		// get bit before the first data bit written
		uint32_t lbp=(pi->fdbitpos ? pi->fdbitpos : di.trackbc)-1;
		int lv = trackbuf.ReadBit(lbp);

		// mfm encoding assumed the last bit to be 0; fix if it is 1
		if (lv)
			trackbuf.ClearBit(pi->fdbitpos, 1);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0xc(%rbp)
movq -0x28(%rbp), %rcx
movl -0xc(%rbp), %eax
cmpl 0x204(%rcx), %eax
jge 0xfd28
movq -0x28(%rbp), %rax
movq 0x1f8(%rax), %rax
movslq -0xc(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x2, 0x20(%rax)
je 0xfcb4
jmp 0xfd1a
movq -0x18(%rbp), %rax
cmpl $0x0, 0x24(%rax)
je 0xfcca
movq -0x18(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0xfcd7
movq -0x28(%rbp), %rax
movl 0x1c0(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
movl -0x2c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
addq $0xb8, %rdi
movl -0x1c(%rbp), %esi
callq 0x13ad0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0xfd18
movq -0x28(%rbp), %rdi
addq $0xb8, %rdi
movq -0x18(%rbp), %rax
movl 0x24(%rax), %esi
movl $0x1, %edx
callq 0x13b30
jmp 0xfd1a
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xfc7b
addq $0x30, %rsp
popq %rbp
retq
nop
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GenerateNoiseTrack(DiskTrackInfo*)
int CCapsImageStd::GenerateNoiseTrack(PDISKTRACKINFO pti)
{
	UDWORD val=CIMG_MFMNOISE;

	for (int pos=0; pos < pti->tracklen; pos++) {
		pti->trackbuf[pos]=(UBYTE)val;
		val=val<<8|val>>24;
	}

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x10030f01, -0x14(%rbp) # imm = 0x10030F01
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x50(%rcx), %eax
jge 0xfd86
movl -0x14(%rbp), %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x18(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x14(%rbp), %eax
shll $0x8, %eax
movl -0x14(%rbp), %ecx
shrl $0x18, %ecx
orl %ecx, %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xfd4a
xorl %eax, %eax
popq %rbp
retq
nopw (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GenerateNoiseDensity(DiskTrackInfo*)
int CCapsImageStd::GenerateNoiseDensity(PDISKTRACKINFO pti)
{
	// same size with track data
	if (pti->tracklen && pti->trackcnt)
		pti->timecnt=pti->tracklen/pti->trackcnt;
	else
		if (!(pti->timecnt=pti->ci.trksize))
			pti->timecnt=12500;

	pti->timebuf=new UDWORD[pti->timecnt+1];

	int pos;
	for (pos=0; pos < pti->timecnt; pos++) {
		UDWORD val=1000;

		if (pos & 512)
			val+=(pos % 99)+(pos&31);
		else
			val-=(pos % 121)-(pos&31);

		pti->timebuf[pos]=val;
	}

	pti->timebuf[pos]=0;

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0xffa1
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0xffa1
movq -0x10(%rbp), %rax
movl 0x50(%rax), %eax
movq -0x10(%rbp), %rcx
cltd
idivl 0x28(%rcx)
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xa8(%rax)
jmp 0xffca
movq -0x10(%rbp), %rax
movl 0x110(%rax), %eax
movq -0x10(%rbp), %rcx
movl %eax, 0xa8(%rcx)
cmpl $0x0, %eax
jne 0xffc8
movq -0x10(%rbp), %rax
movl $0x30d4, 0xa8(%rax)     # imm = 0x30D4
jmp 0xffca
movq -0x10(%rbp), %rax
movl 0xa8(%rax), %eax
addl $0x1, %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4040
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xb0(%rax)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xa8(%rcx), %eax
jge 0x1008a
movl $0x3e8, -0x18(%rbp)     # imm = 0x3E8
movl -0x14(%rbp), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x1004f
movl -0x14(%rbp), %eax
movl $0x63, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl -0x14(%rbp), %ecx
andl $0x1f, %ecx
addl %ecx, %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0x1006a
movl -0x14(%rbp), %eax
movl $0x79, %ecx
cltd
idivl %ecx
movl -0x14(%rbp), %eax
andl $0x1f, %eax
subl %eax, %edx
movl -0x18(%rbp), %eax
subl %edx, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1000f
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movslq -0x14(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
xorl %eax, %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GenerateAutoDensity(DiskTrackInfo*)
int CCapsImageStd::GenerateAutoDensity(PDISKTRACKINFO pti)
{
	// same size with track data
	if (pti->tracklen && pti->trackcnt)
		pti->timecnt=pti->tracklen/pti->trackcnt;
	else
		if (!(pti->timecnt=pti->ci.trksize))
			pti->timecnt=12500;

	pti->timebuf=new UDWORD[pti->timecnt+1];

	int pos;
	for (pos=0; pos < pti->timecnt; pos++) {
		pti->timebuf[pos]=1000;
	}

	pti->timebuf[pos]=0;

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x100f1
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x100f1
movq -0x10(%rbp), %rax
movl 0x50(%rax), %eax
movq -0x10(%rbp), %rcx
cltd
idivl 0x28(%rcx)
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xa8(%rax)
jmp 0x1011a
movq -0x10(%rbp), %rax
movl 0x110(%rax), %eax
movq -0x10(%rbp), %rcx
movl %eax, 0xa8(%rcx)
cmpl $0x0, %eax
jne 0x10118
movq -0x10(%rbp), %rax
movl $0x30d4, 0xa8(%rax)     # imm = 0x30D4
jmp 0x1011a
movq -0x10(%rbp), %rax
movl 0xa8(%rax), %eax
addl $0x1, %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4040
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xb0(%rax)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xa8(%rcx), %eax
jge 0x1018f
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movslq -0x14(%rbp), %rcx
movl $0x3e8, (%rax,%rcx,4)   # imm = 0x3E8
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1015f
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movslq -0x14(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
xorl %eax, %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GenerateCLST(DiskTrackInfo*, unsigned char*)
int CCapsImageStd::GenerateCLST(PDISKTRACKINFO pti, PUBYTE buf)
{
	// set auto density
	GenerateAutoDensity(pti);

	// iterate block positions
	int pos=pti->sdpos, cp;

	for (unsigned blk=0; blk < pti->ci.blkcnt; blk++) {
		int bs = trackbuf.CalculateByteSize(di.block[blk].blockbits);
		int gs = trackbuf.CalculateByteSize(di.block[blk].gapbits);
		int xs=bs+gs;

		switch (blk) {
			case 5:
				for (cp=0; cp < bs; cp++) {
					pti->timebuf[pos+cp]+=50;
				}
				break;
		}

		pos+=xs;
		if (pos >= pti->timecnt)
			pos-=pti->timecnt;
	}

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x38(%rbp)
movq -0x10(%rbp), %rsi
callq 0x100b0
movq -0x10(%rbp), %rax
movl 0xc0(%rax), %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x128(%rcx), %eax
jae 0x10671
movq -0x38(%rbp), %rax
movq 0x1f8(%rax), %rax
movl -0x24(%rbp), %ecx
leaq (%rcx,%rcx,4), %rcx
movl (%rax,%rcx,8), %edi
callq 0x5510
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, -0x28(%rbp)
movq 0x1f8(%rax), %rax
movl -0x24(%rbp), %ecx
leaq (%rcx,%rcx,4), %rcx
movl 0x4(%rax,%rcx,8), %edi
callq 0x5510
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
movl -0x2c(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x30(%rbp)
movl -0x24(%rbp), %eax
subl $0x5, %eax
jne 0x10637
jmp 0x105fe
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x10635
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movl -0x1c(%rbp), %ecx
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
addl $0x32, %edx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x10605
jmp 0x10637
movl -0x30(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xa8(%rcx), %eax
jl 0x10661
movq -0x10(%rbp), %rax
movl 0xa8(%rax), %ecx
movl -0x1c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x1c(%rbp)
jmp 0x10663
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x10599
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GenerateSLA(DiskTrackInfo*, unsigned char*)
int CCapsImageStd::GenerateSLA(PDISKTRACKINFO pti, PUBYTE buf)
{
	// set auto density
	GenerateAutoDensity(pti);

	// iterate block positions
	int pos=pti->sdpos, cp;

	for (unsigned blk=0; blk < pti->ci.blkcnt; blk++) {
		int bs = trackbuf.CalculateByteSize(di.block[blk].blockbits);
		int gs = trackbuf.CalculateByteSize(di.block[blk].gapbits);
		int xs=bs+gs;

		switch (blk) {
			case 1:
				for (cp=0; cp < bs; cp++) {
					pti->timebuf[pos+cp]+=100;
				}
				break;

			case 2:
				for (cp=0; cp < bs; cp++) {
					pti->timebuf[pos+cp]-=100;
				}
				break;
		}

		pos+=xs;
		if (pos >= pti->timecnt)
			pos-=pti->timecnt;
	}

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x38(%rbp)
movq -0x10(%rbp), %rsi
callq 0x100b0
movq -0x10(%rbp), %rax
movl 0xc0(%rax), %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x128(%rcx), %eax
jae 0x107d7
movq -0x38(%rbp), %rax
movq 0x1f8(%rax), %rax
movl -0x24(%rbp), %ecx
leaq (%rcx,%rcx,4), %rcx
movl (%rax,%rcx,8), %edi
callq 0x5510
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, -0x28(%rbp)
movq 0x1f8(%rax), %rax
movl -0x24(%rbp), %ecx
leaq (%rcx,%rcx,4), %rcx
movl 0x4(%rax,%rcx,8), %edi
callq 0x5510
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
movl -0x2c(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x30(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x3c(%rbp)
subl $0x1, %eax
je 0x1072b
jmp 0x10721
movl -0x3c(%rbp), %eax
subl $0x2, %eax
je 0x10764
jmp 0x1079d
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x10762
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movl -0x1c(%rbp), %ecx
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
addl $0x64, %edx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x10732
jmp 0x1079d
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x1079b
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movl -0x1c(%rbp), %ecx
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
subl $0x64, %edx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1076b
jmp 0x1079d
movl -0x30(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xa8(%rcx), %eax
jl 0x107c7
movq -0x10(%rbp), %rax
movl 0xa8(%rax), %ecx
movl -0x1c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x1c(%rbp)
jmp 0x107c9
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x106b9
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
nop
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GenerateABA2(DiskTrackInfo*, unsigned char*)
int CCapsImageStd::GenerateABA2(PDISKTRACKINFO pti, PUBYTE buf)
{
	// set auto density
	GenerateAutoDensity(pti);

	// iterate block positions
	int pos=pti->sdpos, cp;
	UDWORD key=0;
	UDWORD mask=1;

	for (unsigned blk=0; blk < pti->ci.blkcnt; blk++) {
		int bs = trackbuf.CalculateByteSize(di.block[blk].blockbits);
		int gs = trackbuf.CalculateByteSize(di.block[blk].gapbits);
		int xs=bs+gs;

		if (!blk) {
			key=ReadValue(buf+blk*sizeof(CapsBlock)+offsetof(CapsBlock, gapvalue), sizeof(UDWORD));
		} else {
			int dns=(key & mask) ? -50 : 50;
			mask<<=1;

			for (cp=0; cp < bs; cp++) {
				int val=pti->timebuf[pos+cp];
				val+=dns;
				pti->timebuf[pos+cp]=val;
			}
		}

		pos+=xs;
		if (pos >= pti->timecnt)
			pos-=pti->timecnt;
	}

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x48(%rbp)
movq -0x10(%rbp), %rsi
callq 0x100b0
movq -0x10(%rbp), %rax
movl 0xc0(%rax), %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x1, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x128(%rcx), %eax
jae 0x10caf
movq -0x48(%rbp), %rax
movq 0x1f8(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edi
callq 0x5510
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, -0x30(%rbp)
movq 0x1f8(%rax), %rax
movl -0x2c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %edi
callq 0x5510
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x10bfb
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %eax
shlq $0x5, %rax
addq %rax, %rdi
addq $0x18, %rdi
movl $0x4, %esi
callq 0x18bf0
movl %eax, -0x24(%rbp)
jmp 0x10c75
movl -0x24(%rbp), %edx
andl -0x28(%rbp), %edx
movl $0x32, %eax
movl $0xffffffce, %ecx       # imm = 0xFFFFFFCE
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x28(%rbp), %eax
shll %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x10c73
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movl -0x1c(%rbp), %ecx
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movl -0x1c(%rbp), %ecx
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x10c23
jmp 0x10c75
movl -0x38(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xa8(%rcx), %eax
jl 0x10c9f
movq -0x10(%rbp), %rax
movl 0xa8(%rax), %ecx
movl -0x1c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x1c(%rbp)
jmp 0x10ca1
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x10b77
xorl %eax, %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::ConvertDensity(DiskTrackInfo*)
int CCapsImageStd::ConvertDensity(PDISKTRACKINFO pti)
{
	// cancel if buffer not available
	if (!pti->timebuf || !pti->timecnt)
		return imgeOk;

	// sum fractions
	UDWORD sum=0;
	for (int pos=0; pos < pti->timecnt; pos++) {
		sum+=pti->timebuf[pos];
		pti->timebuf[pos]=sum;
	}

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0xb0(%rax)
je 0x10ce7
movq -0x18(%rbp), %rax
cmpl $0x0, 0xa8(%rax)
jne 0x10cf0
movl $0x0, -0x4(%rbp)
jmp 0x10d4c
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0xa8(%rcx), %eax
jge 0x10d45
movq -0x18(%rbp), %rax
movq 0xb0(%rax), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %edx
movq -0x18(%rbp), %rax
movq 0xb0(%rax), %rax
movslq -0x20(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x10cfe
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::FreeDiskData()
void CCapsImageStd::FreeDiskData()
{
	di.datacount=0;
	di.datasize=0;

	delete [] di.data;
	di.data=NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x0, 0x1f4(%rax)
movl $0x0, 0x1f0(%rax)
movq 0x1e8(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
je 0x10da2
movq -0x10(%rbp), %rdi
callq 0x42e0
movq -0x18(%rbp), %rax
movq $0x0, 0x1e8(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::AllocImageBlock(int)
void CCapsImageStd::AllocImageBlock(int maxsize)
{
	if (di.blocksize < maxsize) {
		FreeImageBlock();

		di.block=new ImageBlockInfo[maxsize];
		di.blocksize=maxsize;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movl 0x200(%rax), %eax
cmpl -0xc(%rbp), %eax
jge 0x10e27
movq -0x18(%rbp), %rdi
callq 0x10e30
movslq -0xc(%rbp), %rax
movl $0x28, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4040
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x1f8(%rax)
movl -0xc(%rbp), %ecx
movl %ecx, 0x200(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::FreeImageBlock()
void CCapsImageStd::FreeImageBlock()
{
	di.blockcount=0;
	di.blocksize=0;

	delete [] di.block;
	di.block=NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x0, 0x204(%rax)
movl $0x0, 0x200(%rax)
movq 0x1f8(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
je 0x10e72
movq -0x10(%rbp), %rdi
callq 0x42e0
movq -0x18(%rbp), %rax
movq $0x0, 0x1f8(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GetBlock(ImageBlockInfo*, int)
int CCapsImageStd::GetBlock(PIMAGEBLOCKINFO pi, int blk)
{
	// check errors
	if (!pi)
		return imgeGeneric;

	// get ipf block descriptor, stop on any error
	CapsBlock cb;
	int res=GetBlock(&cb, blk);
	if (res != imgeOk)
		return res;

	// set image descriptor
	pi->blockbits=cb.blockbits;
	pi->gapbits=cb.gapbits;
	pi->enctype=cb.enctype;
	pi->flag=cb.flag;
	pi->gapvalue=cb.gapvalue;
	pi->dataoffset=cb.dataoffset;

	// CAPS encoder support: no gap streams, no flags, 2us cells
	if (dii.ci.encoder == CAPS_ENCODER) {
		pi->gapoffset=0;
		pi->celltype=cpbct2us;
		pi->flag=0;
	} else {
		pi->gapoffset=cb.bt.sps.gapoffset;
		pi->celltype=cb.bt.sps.celltype;
	}

	// reset encoding information
	pi->fdenc=ibieNA;
	pi->fdbitpos=0;

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x10ebe
movl $0x2, -0x4(%rbp)
jmp 0x10f7b
movq -0x48(%rbp), %rdi
movl -0x1c(%rbp), %edx
leaq -0x3c(%rbp), %rsi
callq 0x10f90
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0x10ee2
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x10f7b
movq -0x48(%rbp), %rax
movl -0x3c(%rbp), %edx
movq -0x18(%rbp), %rcx
movl %edx, (%rcx)
movl -0x38(%rbp), %edx
movq -0x18(%rbp), %rcx
movl %edx, 0x4(%rcx)
movl -0x2c(%rbp), %edx
movq -0x18(%rbp), %rcx
movl %edx, 0x10(%rcx)
movl -0x28(%rbp), %edx
movq -0x18(%rbp), %rcx
movl %edx, 0x14(%rcx)
movl -0x24(%rbp), %edx
movq -0x18(%rbp), %rcx
movl %edx, 0x18(%rcx)
movl -0x20(%rbp), %edx
movq -0x18(%rbp), %rcx
movl %edx, 0x1c(%rcx)
cmpl $0x1, 0x50(%rax)
jne 0x10f4a
movq -0x18(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x18(%rbp), %rax
movl $0x1, 0xc(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x14(%rax)
jmp 0x10f5e
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x30(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x20(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x24(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GetBlock(CapsBlock*, int)
int CCapsImageStd::GetBlock(PCAPSBLOCK pb, int blk)
{
	// check errors
	if (!di.data || !pb || blk<0 || blk>=di.blockcount)
		return imgeGeneric;

	// check buffer overrun
	if (int((blk+1)*sizeof(CapsBlock)) > di.pdt->datasize)
		return imgeShort;

	// read block descriptor and convert it to host native endiannes
	memcpy(pb, di.data+blk*sizeof(CapsBlock), sizeof(CapsBlock));
	CCapsLoader::Swap((PUDWORD)pb, sizeof(CapsBlock));

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, 0x1e8(%rax)
je 0x10fd1
cmpq $0x0, -0x18(%rbp)
je 0x10fd1
cmpl $0x0, -0x1c(%rbp)
jl 0x10fd1
movq -0x28(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl 0x204(%rcx), %eax
jl 0x10fda
movl $0x2, -0x4(%rbp)
jmp 0x1104d
movq -0x28(%rbp), %rcx
movl -0x1c(%rbp), %eax
addl $0x1, %eax
cltq
shlq $0x5, %rax
movq 0x210(%rcx), %rcx
cmpl 0x24(%rcx), %eax
jle 0x10fff
movl $0x7, -0x4(%rbp)
jmp 0x1104d
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x1e8(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
shlq $0x5, %rdx
movq (%rcx,%rdx), %rsi
movq %rsi, (%rax)
movq 0x8(%rcx,%rdx), %rsi
movq %rsi, 0x8(%rax)
movq 0x10(%rcx,%rdx), %rsi
movq %rsi, 0x10(%rax)
movq 0x18(%rcx,%rdx), %rcx
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rdi
movl $0x20, %esi
callq 0x15710
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::InitStream(ImageStreamInfo*, int, int)
int CCapsImageStd::InitStream(PIMAGESTREAMINFO pstr, int strtype, int blk)
{
	// check errors
	if (!pstr || blk<0 || blk>=di.blockcount)
		return imgeGeneric;

	// set parameters so all data is available in the stream descriptor
	pstr->strtype=strtype;
	pstr->actblock=blk;
	pstr->enctype=di.block[blk].enctype;

	// active encoding is set by the block descriptor, but can be changed later
	pstr->actenctype=pstr->enctype;

	int res;

	switch (strtype) {
		case isitData:
			res=InitDataStream(pstr);
			break;

		case isitGap0:
		case isitGap1:
			res=InitGapStream(pstr);
			break;

		default:
			res=imgeGeneric;
			break;
	}

	// stop if stream could not be initialized
	if (res != imgeOk)
		return res;

	// stop if stream is unreadable
	res=ResetStream(pstr);

	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1109a
cmpl $0x0, -0x20(%rbp)
jl 0x1109a
movq -0x30(%rbp), %rcx
movl -0x20(%rbp), %eax
cmpl 0x204(%rcx), %eax
jl 0x110a6
movl $0x2, -0x4(%rbp)
jmp 0x11148
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %edx
movq -0x18(%rbp), %rcx
movl %edx, (%rcx)
movl -0x20(%rbp), %edx
movq -0x18(%rbp), %rcx
movl %edx, 0x4(%rcx)
movq 0x1f8(%rax), %rax
movslq -0x20(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
movl 0x10(%rax,%rcx,8), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movl %ecx, 0xc(%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x34(%rbp)
testl %eax, %eax
je 0x110f9
jmp 0x110ed
movl -0x34(%rbp), %eax
decl %eax
subl $0x2, %eax
jb 0x1110b
jmp 0x1111d
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x11160
movl %eax, -0x24(%rbp)
jmp 0x11124
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x11280
movl %eax, -0x24(%rbp)
jmp 0x11124
movl $0x2, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x11132
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x11148
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x11570
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::InitDataStream(ImageStreamInfo*)
int CCapsImageStd::InitDataStream(PIMAGESTREAMINFO pstr)
{
	// sample looping on zero data count is not allowed
	pstr->allowloop=0;

	PIMAGEBLOCKINFO pi=di.block+pstr->actblock;

	// set data size mode to bits or bytes according to the encoder flag
	pstr->sizemodebit=(pi->flag & CAPS_BF_DMB) ? 1 : 0;

	// stream start from block descriptor
	pstr->strstart=pi->dataoffset;

	// check buffer overrun for file limit
	if (pstr->strstart >= (uint32_t)di.pdt->datasize)
		return imgeShort;

	// stream ends at the file limit for the current chunk for last block, or at the start of the next block stream
	if (pstr->actblock == di.blockcount-1)
		pstr->strend=di.pdt->datasize;
	else
		pstr->strend=pi[1].dataoffset;

	// check buffer overrun for stream limit
	if (pstr->strstart >= pstr->strend)
		return imgeShort;

	// set stream pointer and maximum size
	pstr->strbase=di.data+pstr->strstart;
	pstr->strsize=pstr->strend-pstr->strstart;

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, 0x44(%rax)
movq 0x1f8(%rcx), %rax
movq -0x18(%rbp), %rdx
movslq 0x4(%rdx), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %esi
andq $0x4, %rsi
xorl %edx, %edx
movl $0x1, %eax
cmpq $0x0, %rsi
cmovnel %eax, %edx
movq -0x18(%rbp), %rax
movl %edx, 0x10(%rax)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %edx
movq -0x18(%rbp), %rax
movl %edx, 0x14(%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movq 0x210(%rcx), %rcx
cmpl 0x24(%rcx), %eax
jb 0x111e8
movl $0x7, -0x4(%rbp)
jmp 0x11277
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl 0x204(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x11217
movq -0x28(%rbp), %rax
movq 0x210(%rax), %rax
movl 0x24(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
jmp 0x11225
movq -0x20(%rbp), %rax
movl 0x44(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jb 0x1123e
movl $0x7, -0x4(%rbp)
jmp 0x11277
movq -0x28(%rbp), %rax
movq 0x1e8(%rax), %rcx
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x18(%rbp), %rax
subl 0x14(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x20(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::ResetStream(ImageStreamInfo*)
int CCapsImageStd::ResetStream(PIMAGESTREAMINFO pstr)
{
	// set first stream data element
	pstr->strofs=0;

	// no stream errors
	pstr->readresult=imgeOk;
	pstr->readend=0;
	pstr->readvalue=0;

	// reset sample and data element streaming
	pstr->setencmode=isiemRaw;
	pstr->streambc=0;
	pstr->samplebc=0;
	pstr->remstreambc=0;
	pstr->remsamplebc=0;
	pstr->sampleofs=0;
	pstr->samplemask=0;
	pstr->samplebase=0;

	pstr->prcbitpos=0;
	pstr->prcrembc=0;
	pstr->prcskipbc=0;
	pstr->prcencstate=1;
	pstr->prcwritebc=0;

	pstr->loopofs=0;
	pstr->loopsize=0;
	pstr->looptype=isiltNone;

	pstr->esfixbc=0;
	pstr->esloopbc=0;

	pstr->scenable=0;
	pstr->scofs=0;
	pstr->scmul=0;

	// stop if stream is disabled
	if (!pstr->strsize) {
		pstr->readend=1;
		return imgeOk;
	}

	// decode the first stream sample data, set correct encoding mode
	int res=GetSample(pstr);

	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x38(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x3c(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x48(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x4c(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x50(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x54(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x58(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x5c(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x60(%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x68(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x70(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x74(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x78(%rax)
movq -0x18(%rbp), %rax
movl $0x1, 0x7c(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x80(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x84(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x88(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x8c(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x90(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x94(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x98(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x9c(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0xa0(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jne 0x116d5
movq -0x18(%rbp), %rax
movl $0x1, 0x3c(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x116eb
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x118b0
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GetSample(ImageStreamInfo*)
int CCapsImageStd::GetSample(PIMAGESTREAMINFO pstr)
{
	// reset reading the actual sample data part
	pstr->sampleofs=0;
	pstr->samplemask=0x80;

	// undefined bitcount
	pstr->streambc=0;
	pstr->remstreambc=0;

	int res;

	// stream encoding specific ipf stream processing
	switch (pstr->actenctype) {
		// physical encodings supported
		case cpencMFM:
			// default to encoded stream
			pstr->setencmode=isiemType;

			if (pstr->strtype == isitData)
				res=GetSampleData(pstr);
			else
				res=GetSampleGap(pstr);
			break;

		// raw should only be used for testing track data, not a supported release type
		case cpencRaw:
			// default to unencoded stream
			pstr->setencmode=isiemRaw;

			if (pstr->strtype == isitData)
				res=GetSampleRaw(pstr);
			else
				res=GetSampleGap(pstr);
			break;

		default:
			res=imgeIncompatible;
			break;
	}

	// set loop point, stop streaming on any error encountered
	if (res == imgeOk)
		GetLoop(pstr);
	else {
		pstr->readresult=res;
		pstr->readend=1;
	}

	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0x5c(%rax)
movq -0x10(%rbp), %rax
movl $0x80, 0x60(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x4c(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x54(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x18(%rbp)
subl $0x1, %eax
je 0x1190f
jmp 0x11905
movl -0x18(%rbp), %eax
subl $0x2, %eax
je 0x11947
jmp 0x1197f
movq -0x10(%rbp), %rax
movl $0x1, 0x48(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x11935
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x11c60
movl %eax, -0x14(%rbp)
jmp 0x11945
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x11e90
movl %eax, -0x14(%rbp)
jmp 0x11986
movq -0x10(%rbp), %rax
movl $0x0, 0x48(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x1196d
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x12060
movl %eax, -0x14(%rbp)
jmp 0x1197d
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x11e90
movl %eax, -0x14(%rbp)
jmp 0x11986
movl $0xe, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x1199b
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x121e0
jmp 0x119b0
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x3c(%rax)
movl -0x14(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::ReadSampleInit(ImageStreamInfo*)
int CCapsImageStd::ReadSampleInit(PIMAGESTREAMINFO pstr)
{
	// signal on stream end
	if (pstr->readend)
		return 1;

	// support sample looping if looping is allowed and last sample size is undefined
	if (pstr->allowloop && !pstr->streambc) {
		// set countdown values same as the original sample size
		pstr->remstreambc=pstr->samplebc;
		pstr->remsamplebc=pstr->samplebc;

		// reset reading the actual sample data part
		pstr->sampleofs=0;
		pstr->samplemask=0x80;
	} else {
		// get current encoding mode
		int setencmode=pstr->setencmode;
		int actenctype=pstr->actenctype;

		// get next sample, signal on error
		if (GetSample(pstr) != imgeOk)
			return 1;

		// signal on stream end
		if (pstr->readend)
			return 1;

		// signal on any encoding change
		if (pstr->setencmode != setencmode)
			return 1;

		if (pstr->actenctype != actenctype)
			return 1;
	}

	// no processing change required
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
je 0x119ee
movl $0x1, -0x4(%rbp)
jmp 0x11aab
movq -0x18(%rbp), %rax
cmpl $0x0, 0x44(%rax)
je 0x11a36
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
jne 0x11a36
movq -0x18(%rbp), %rax
movl 0x50(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x18(%rbp), %rax
movl 0x50(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x5c(%rax)
movq -0x18(%rbp), %rax
movl $0x80, 0x60(%rax)
jmp 0x11aa4
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rsi
callq 0x118b0
cmpl $0x0, %eax
je 0x11a65
movl $0x1, -0x4(%rbp)
jmp 0x11aab
movq -0x18(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
je 0x11a78
movl $0x1, -0x4(%rbp)
jmp 0x11aab
movq -0x18(%rbp), %rax
movl 0x48(%rax), %eax
cmpl -0x1c(%rbp), %eax
je 0x11a8d
movl $0x1, -0x4(%rbp)
jmp 0x11aab
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x20(%rbp), %eax
je 0x11aa2
movl $0x1, -0x4(%rbp)
jmp 0x11aab
jmp 0x11aa4
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GetLoop(ImageStreamInfo*)
void CCapsImageStd::GetLoop(PIMAGESTREAMINFO pg)
{
	// stop, if not enabled
	if (!pg->scenable)
		return;

	// stop if not a loop point
	if (pg->strofs != pg->scofs)
		return;

	// add new samples
	pg->remstreambc+=pg->scmul*pg->samplebc;

	// make the sample size fixed
	pg->streambc=pg->remstreambc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x98(%rax)
jne 0x121fb
jmp 0x1223a
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x9c(%rcx), %eax
je 0x12210
jmp 0x1223a
movq -0x10(%rbp), %rax
movl 0xa0(%rax), %ecx
movq -0x10(%rbp), %rax
imull 0x50(%rax), %ecx
movq -0x10(%rbp), %rax
addl 0x54(%rax), %ecx
movl %ecx, 0x54(%rax)
movq -0x10(%rbp), %rax
movl 0x54(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4c(%rax)
popq %rbp
retq
nopl (%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::ProcessStream(ImageStreamInfo*, unsigned int, int, int, int)
int CCapsImageStd::ProcessStream(PIMAGESTREAMINFO pstr, uint32_t bitpos, int maxbc, int skipbc, int encnew)
{
	// set stream process state
	pstr->prcbitpos=bitpos;
	pstr->prcrembc=maxbc;
	pstr->prcskipbc=skipbc;
	pstr->prcencstate=encnew;
	pstr->prcwritebc=0;

	// process remaining bits
	while (pstr->prcrembc > 0) {
		// stop if ipf stream is over
		if (pstr->readend)
			break;

		// process by currently selected encoding mode
		switch (pstr->setencmode) {
			// raw, no encoding
			case isiemRaw:
				ProcessStreamRaw(pstr);
				break;

			// encoding specified by the data encoding type selected
			case isiemType:
				switch (pstr->actenctype) {
					// generic MFM
					case cpencMFM:
						ProcessStreamMFM(pstr);
						break;

					// raw data
					case cpencRaw:
						ProcessStreamRaw(pstr);
						break;

					default:
						return imgeIncompatible;
				}
				break;

			// weak bits
			case isiemWeak:
				ProcessStreamWeak(pstr);
				break;

			default:
				return imgeGeneric;
		}
	}

	return pstr->readresult;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x70(%rax)
movl -0x20(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x74(%rax)
movl -0x24(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x78(%rax)
movl -0x28(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x7c(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x80(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x74(%rax)
jle 0x1234d
movq -0x18(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
je 0x122b9
jmp 0x1234d
movq -0x18(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, -0x34(%rbp)
testl %eax, %eax
je 0x122dd
jmp 0x122c9
movl -0x34(%rbp), %eax
subl $0x1, %eax
je 0x122ec
jmp 0x122d3
movl -0x34(%rbp), %eax
subl $0x2, %eax
je 0x12330
jmp 0x1233f
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12360
jmp 0x12348
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x38(%rbp)
subl $0x1, %eax
je 0x12307
jmp 0x122fd
movl -0x38(%rbp), %eax
subl $0x2, %eax
je 0x12316
jmp 0x12325
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12510
jmp 0x1232e
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12360
jmp 0x1232e
movl $0xe, -0x4(%rbp)
jmp 0x12357
jmp 0x12348
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12790
jmp 0x12348
movl $0x2, -0x4(%rbp)
jmp 0x12357
jmp 0x1229c
movq -0x18(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::CalculateStreamSize(ImageStreamInfo*)
int CCapsImageStd::CalculateStreamSize(PIMAGESTREAMINFO pstr)
{
	// find loop point and loop type
	int res=FindLoopPoint(pstr);
	if (res != imgeOk)
		return res;

	// use a copy of the stream to parse data
	ImageStreamInfo isi=*pstr;

	// allbc: size without looping
	// fixbc: fixed bits
	// loopbc: loop bits
	int fixbc=0, loopbc=0;

	// sum all bit counts
	while (!isi.readend) {
		switch (isi.looptype) {
			// no loop
			case isiltNone:
				fixbc+=GetEncodedSize(&isi, isi.remstreambc);
				break;

			// auto-generated or stream loop
			case isiltAuto:
			case isiltStream:
				fixbc+=GetEncodedSize(&isi, isi.remstreambc);
				if (isi.strofs == isi.loopofs)
					loopbc+=GetEncodedSize(&isi, isi.samplebc);
				break;

			default:
				return imgeGeneric;
		}

		// get next sample
		if (GetSample(&isi) != imgeOk)
			return imgeGeneric;
	}

	// save results
	pstr->esfixbc=fixbc;
	pstr->esloopbc=loopbc;

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
movq -0x18(%rbp), %rsi
callq 0x12ab0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x1297b
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x12aa2
movq -0x18(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
movl $0xa8, %edx
callq 0x41a0
movl $0x0, -0xcc(%rbp)
movl $0x0, -0xd0(%rbp)
cmpl $0x0, -0x8c(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x129b9
jmp 0x12a7b
movl -0x3c(%rbp), %eax
movl %eax, -0xdc(%rbp)
testl %eax, %eax
je 0x129d7
jmp 0x129c8
movl -0xdc(%rbp), %eax
decl %eax
subl $0x2, %eax
jb 0x129fb
jmp 0x12a4c
movq -0xd8(%rbp), %rdi
movl -0x74(%rbp), %edx
leaq -0xc8(%rbp), %rsi
callq 0x12cd0
addl -0xcc(%rbp), %eax
movl %eax, -0xcc(%rbp)
jmp 0x12a55
movq -0xd8(%rbp), %rdi
movl -0x74(%rbp), %edx
leaq -0xc8(%rbp), %rsi
callq 0x12cd0
addl -0xcc(%rbp), %eax
movl %eax, -0xcc(%rbp)
movl -0xac(%rbp), %eax
cmpl -0x44(%rbp), %eax
jne 0x12a4a
movq -0xd8(%rbp), %rdi
movl -0x78(%rbp), %edx
leaq -0xc8(%rbp), %rsi
callq 0x12cd0
addl -0xd0(%rbp), %eax
movl %eax, -0xd0(%rbp)
jmp 0x12a55
movl $0x2, -0x4(%rbp)
jmp 0x12aa2
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x118b0
cmpl $0x0, %eax
je 0x12a76
movl $0x2, -0x4(%rbp)
jmp 0x12aa2
jmp 0x129a4
movl -0xcc(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x90(%rax)
movl -0xd0(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x94(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nop
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GetEncodedSize(ImageStreamInfo*, int)
int CCapsImageStd::GetEncodedSize(PIMAGESTREAMINFO pstr, int bitcnt)
{
	// process by currently selected and active encoding mode
	switch (pstr->setencmode) {
		case isiemType:
		case isiemWeak:
			switch (pstr->actenctype) {
				case cpencMFM:
					bitcnt <<= 1;
					break;
			}
			break;
	}

	return bitcnt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x48(%rax), %eax
decl %eax
subl $0x1, %eax
ja 0x12d07
jmp 0x12cef
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
subl $0x1, %eax
jne 0x12d05
jmp 0x12cfd
movl -0x14(%rbp), %eax
shll %eax
movl %eax, -0x14(%rbp)
jmp 0x12d07
movl -0x14(%rbp), %eax
popq %rbp
retq
nopl (%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::ProcessBlockData(int, int)
int CCapsImageStd::ProcessBlockData(int blk, int datasize)
{
	// stop if no data area
	if (!datasize)
		return imgeOk;

	int res;
	ImageStreamInfo dsi;

	// initialize the data stream
	res=InitStream(&dsi, isitData, blk);
	if (res != imgeOk)
		return res;

	// encode block data
	res=ProcessStream(&dsi, di.encbitpos, datasize, 0, !di.encwritebc);
	if (res != imgeOk)
		return res;

	// error if the requested data size was not filled
	if (dsi.prcwritebc != datasize)
		return imgeGeneric;

	// update bit position and bits written
	di.encbitpos=dsi.prcbitpos;
	di.encwritebc+=dsi.prcwritebc;

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x12d42
movl $0x0, -0x4(%rbp)
jmp 0x12de4
movq -0xd0(%rbp), %rdi
movl -0x14(%rbp), %ecx
leaq -0xc8(%rbp), %rsi
xorl %edx, %edx
callq 0x11060
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x12d6b
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x12de4
movq -0xd0(%rbp), %rdi
movl 0x1d8(%rdi), %edx
movl -0x18(%rbp), %ecx
cmpl $0x0, 0x1dc(%rdi)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %r9d
leaq -0xc8(%rbp), %rsi
xorl %r8d, %r8d
callq 0x12240
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x12dad
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x12de4
movl -0x48(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0x12dbe
movl $0x2, -0x4(%rbp)
jmp 0x12de4
movq -0xd0(%rbp), %rax
movl -0x58(%rbp), %ecx
movl %ecx, 0x1d8(%rax)
movl -0x48(%rbp), %ecx
addl 0x1dc(%rax), %ecx
movl %ecx, 0x1dc(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::ProcessBlockGap(ImageStreamInfo*, ImageStreamInfo*, int, int)
int CCapsImageStd::ProcessBlockGap(PIMAGESTREAMINFO pg0, PIMAGESTREAMINFO pg1, int gapsize, int loopsel)
{
	int gs0=pg0->esfixbc;
	int gs1=pg1->esfixbc;

	// fixed size stream uses its own size, the stream with the loop fills the remainder
	if (loopsel) {
		// 0: fix, 1: loop
		if (gs0 > gapsize)
			gs0=gapsize;

		gs1=gapsize-gs0;
	} else {
		// 0: loop, 1: fix
		if (gs1 > gapsize)
			gs1=gapsize;

		gs0=gapsize-gs1;
	}

	// encode forward stream
	int res=ProcessBlockGap(pg0, gs0);
	if (res != imgeOk)
		return res;

	// set gap split position
	di.encgsvalid=1;
	di.encgapsplit=di.encbitpos;

	// encode backwards stream
	ProcessBlockGap(pg1, gs1);
	if (res != imgeOk)
		return res;

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl 0x90(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movl 0x90(%rax), %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x133cc
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x133c1
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
subl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x133e3
movl -0x30(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x133da
movl -0x24(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x24(%rbp), %eax
subl -0x30(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x13190
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x13404
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1343f
movq -0x40(%rbp), %rdi
movl $0x1, 0x1e0(%rdi)
movl 0x1d8(%rdi), %eax
movl %eax, 0x1e4(%rdi)
movq -0x20(%rbp), %rsi
movl -0x30(%rbp), %edx
callq 0x13190
cmpl $0x0, -0x34(%rbp)
je 0x13438
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1343f
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)