LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcUpdateTrack(CapsFdc*, int)
void FdcUpdateTrack(PCAPSFDC pc, int drive)
{
	// must be valid drive
	if (drive < 0)
		return;

	// get selected drive
	PCAPSDRIVE pd=pc->drive+drive;

	// no disk inserted, no input
	if (!(pd->diskattr & CAPSDRIVE_DA_IN))
		return;

	// get base track length in bits
	if (!pd->trackbuf || !pd->tracklen) {
		// generate different track size on track updates
		PSDWORD ns=fdcddnoise;
		pd->trackbits=ns[pd->nact++]<<3;
		if (ns[pd->nact] < 0)
			pd->nact=0;
		pd->overlap=0;
	} else
		pd->trackbits=pd->tracklen<<3;

	// if overlap position exists
	int rb;
	if (pd->overlap >= 0) {
		// rob bit count, updated on track updates
		rb=fdcrobbit[pd->ovlact++];
		if (fdcrobbit[pd->ovlact] < 0)
			pd->ovlact=0;
	} else
		rb=0;

	pd->ovlcnt=rb;

	// set bits to remove and their start if any
	if (rb) {
		pd->ovlmin=((pd->overlap+1)<<3)-rb;
		pd->ovlmax=pd->ovlmin+rb-1;
	} else {
		pd->ovlmin=-1;
		pd->ovlmax=-1;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jge 0xb616
jmp 0xb769
movq -0x8(%rbp), %rax
movq 0x108(%rax), %rax
movslq -0xc(%rbp), %rcx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0xb646
jmp 0xb769
movq -0x18(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0xb65b
movq -0x18(%rbp), %rax
cmpl $0x0, 0x48(%rax)
jne 0xb6b3
leaq 0x1bc3e(%rip), %rax     # 0x272a0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rdx
movl 0x64(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x64(%rdx)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
shll $0x3, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq 0x64(%rcx), %rcx
cmpl $0x0, (%rax,%rcx,4)
jge 0xb6a6
movq -0x18(%rbp), %rax
movl $0x0, 0x64(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x4c(%rax)
jmp 0xb6c4
movq -0x18(%rbp), %rax
movl 0x48(%rax), %ecx
shll $0x3, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
jl 0xb70f
movq -0x18(%rbp), %rcx
movl 0x60(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x60(%rcx)
movslq %eax, %rcx
leaq 0x1bb99(%rip), %rax     # 0x27280
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movslq 0x60(%rax), %rcx
leaq 0x1bb84(%rip), %rax     # 0x27280
cmpl $0x0, (%rax,%rcx,4)
jge 0xb70d
movq -0x18(%rbp), %rax
movl $0x0, 0x60(%rax)
jmp 0xb716
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x5c(%rax)
cmpl $0x0, -0x24(%rbp)
je 0xb753
movq -0x18(%rbp), %rax
movl 0x4c(%rax), %ecx
addl $0x1, %ecx
shll $0x3, %ecx
subl -0x24(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x18(%rbp), %rax
movl 0x54(%rax), %ecx
addl -0x24(%rbp), %ecx
subl $0x1, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x58(%rax)
jmp 0xb769
movq -0x18(%rbp), %rax
movl $0xffffffff, 0x54(%rax) # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
movl $0xffffffff, 0x58(%rax) # imm = 0xFFFFFFFF
popq %rbp
retq
nopl (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcLockTime(CapsFdc*)
void FdcLockTime(PCAPSFDC pc)
{
	PCAPSDRIVE pd=pc->driveprc;
	int lo=0;
	int hi=pd->tracklen-1;
	UDWORD sum=pd->timebuf[hi];

	// binary search for the nearest item to the actual clock distance
	while (lo <= hi) {
		int mid=(lo+hi)/2;
		UDWORD atm=UDWORD(((UQUAD)pd->timebuf[mid]*pd->clockrev)/sum);

		if (atm <= pd->idistance)
			lo=mid+1;
		else
			hi=mid-1;
	}

	// safety check can only happen if distance was >= clockrev
	if ((unsigned)lo >= pd->tracklen)
		lo=pd->tracklen-1;

	UDWORD base=lo ? pd->timebuf[lo-1] : 0;
	UDWORD diff=pd->timebuf[lo]-base;

	// linear search for nearest distance
	for (hi=1; hi < 8; hi++) {
		UDWORD atm=UDWORD(((UQUAD)(base+(hi*diff)/8)*pd->clockrev)/sum);
		if (pd->idistance < atm)
			break;
	}

	pc->datalock=lo*8+hi-1;
	pc->datacycle=base;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rax
movq %rax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x48(%rax), %eax
subl $0x1, %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x1c(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
jg 0xb80d
movl -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movl 0x28(%rcx), %ecx
imulq %rcx, %rax
movl -0x1c(%rbp), %ecx
xorl %edx, %edx
divq %rcx
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x24(%rcx), %eax
ja 0xb802
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xb80b
movl -0x20(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xb7ad
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x48(%rcx), %eax
jb 0xb826
movq -0x10(%rbp), %rax
movl 0x48(%rax), %eax
subl $0x1, %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0xb845
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
jmp 0xb84c
xorl %eax, %eax
movl %eax, -0x34(%rbp)
jmp 0xb84c
movl -0x34(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
subl -0x28(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl $0x1, -0x18(%rbp)
cmpl $0x8, -0x18(%rbp)
jge 0xb8b6
movl -0x28(%rbp), %eax
movl -0x18(%rbp), %ecx
imull -0x2c(%rbp), %ecx
shrl $0x3, %ecx
addl %ecx, %eax
movl %eax, %eax
movq -0x10(%rbp), %rcx
movl 0x28(%rcx), %ecx
imulq %rcx, %rax
movl -0x1c(%rbp), %ecx
xorl %edx, %edx
divq %rcx
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x24(%rax), %eax
cmpl -0x30(%rbp), %eax
jae 0xb8a9
jmp 0xb8b6
jmp 0xb8ab
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xb86e
movl -0x14(%rbp), %ecx
shll $0x3, %ecx
addl -0x18(%rbp), %ecx
subl $0x1, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x80(%rax)
movl -0x28(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x88(%rax)
popq %rbp
retq
nopl (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComReadNoline(CapsFdc*)
int FdcComReadNoline(PCAPSFDC pc)
{
	// clear dsr signals
	pc->aminfo&=~(CAPSFDC_AI_DSRREADY|CAPSFDC_AI_DSRAM|CAPSFDC_AI_DSRMA1);

	// clock cycles to complete
	UDWORD cmax=pc->clockreq-pc->clockact;

	// set byte read time if expired
	if (!pc->datacycle)
		pc->datacycle=pc->datalock;

	// if byte can be read in this round
	if (cmax >= pc->datacycle) {
		// spend remaining time
		pc->clockact+=pc->datacycle;
		pc->datacycle=0;
		pc->dsr=0;
		return 1;
	}

	// takes more time to complete than what is available
	pc->datacycle-=cmax;
	pc->clockact=pc->clockreq;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x60(%rax), %ecx
andq $-0x701, %rcx           # imm = 0xF8FF
movl %ecx, 0x60(%rax)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0xc(%rcx), %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x88(%rax)
jne 0xb92b
movq -0x10(%rbp), %rax
movl 0x80(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x88(%rax)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x88(%rcx), %eax
jb 0xb970
movq -0x10(%rbp), %rax
movl 0x88(%rax), %ecx
movq -0x10(%rbp), %rax
addl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x88(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x78(%rax)
movl $0x1, -0x4(%rbp)
jmp 0xb99a
movl -0x14(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x88(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x88(%rax)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nop
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcReadBit(CapsFdc*)
int FdcReadBit(PCAPSFDC pc)
{
	// get selected drive
	PCAPSDRIVE pd=pc->driveprc;

	// get current position
	int lock=pc->datalock;

	// bit position in track buffer
	PUBYTE trk=pd->trackbuf+(lock>>3);
	UBYTE msk=1<<((lock&7)^7);

	return *trk & msk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x80(%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movl -0x14(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl -0x14(%rbp), %ecx
andl $0x7, %ecx
xorl $0x7, %ecx
movl $0x1, %eax
shll %cl, %eax
movb %al, -0x21(%rbp)
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
movzbl -0x21(%rbp), %ecx
andl %ecx, %eax
popq %rbp
retq
nop
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcReadBitNoise(CapsFdc*)
int FdcReadBitNoise(PCAPSFDC pc)
{
	// get selected drive
	PCAPSDRIVE pd=pc->driveprc;

	// bit position
	UDWORD msk=1<<((pc->datalock&7)^7);

	// random data
	UDWORD seed=pd->nseed;

	// accessing the first bit in the stream triggers new data
	if (msk == 0x80) {
		seed<<=1;
		if ((seed>>22 ^ seed) & DF_1)
			seed++;
		pd->nseed=seed;
	}

	return seed & msk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x80(%rax), %ecx
andl $0x7, %ecx
xorl $0x7, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x68(%rax), %eax
movl %eax, -0x18(%rbp)
cmpl $0x80, -0x14(%rbp)
jne 0xc444
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
shrl $0x16, %eax
xorl -0x18(%rbp), %eax
movl %eax, %eax
andq $0x2, %rax
cmpq $0x0, %rax
je 0xc43a
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x68(%rax)
movl -0x18(%rbp), %eax
andl -0x14(%rbp), %eax
popq %rbp
retq
nopl (%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFile.cpp
// Function: CCapsFile::Close()
int CCapsFile::Close()
{
	int res=0;

	if (file) {
		res = file->Close();
		delete file;
		file = NULL;
	}

	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0xc(%rbp)
cmpq $0x0, 0x8(%rax)
je 0xc50d
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, -0xc(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0xc501
movq -0x20(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x8(%rax)
movl -0xc(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFile.cpp
// Function: CCapsFile::Open(CapsFile*)
int CCapsFile::Open(PCAPSFILE pcf)
{
	int res=true;

	Close();

	if (!pcf)
		return res;

	if (pcf->flag & CFF_MEMMAP) {
		PCMEMORYFILE f = new CMemoryFile();
		file = f;
		int mode = (pcf->flag & CFF_MEMREF) ? 0 : BFFLAG_CREATE;
		res=f->Open(pcf->memmap, pcf->size, mode);
	}	else {
		PCDISKFILE f = new CDiskFile();
		file = f;
		int fm = (pcf->flag & CFF_WRITE) ? BFFLAG_WRITE : 0;
		if (pcf->flag & CFF_CREATE)
			fm |= BFFLAG_CREATE;
		res = f->Open(pcf->name, fm);
	}

	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x50(%rbp)
movl $0x1, -0x1c(%rbp)
callq 0xc4b0
cmpq $0x0, -0x18(%rbp)
jne 0xc586
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xc6cc
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andq $0x2, %rax
cmpq $0x0, %rax
je 0xc62b
movl $0x48, %edi
callq 0x4240
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x58(%rbp)
callq 0x19700
jmp 0xc5b6
movq -0x50(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, -0x28(%rbp)
movq -0x28(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
andq $0x4, %rdx
movl $0x2, %eax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rax
movslq 0x14(%rax), %rdx
movl -0x38(%rbp), %ecx
callq 0x19870
movl %eax, -0x1c(%rbp)
jmp 0xc6c6
movq -0x58(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x48, %esi
callq 0x4250
jmp 0xc6d5
movl $0x228, %edi            # imm = 0x228
callq 0x4240
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x60(%rbp)
callq 0x16ee0
jmp 0xc646
movq -0x50(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
andq $0x1, %rdx
xorl %eax, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
andq $0x8, %rax
cmpq $0x0, %rax
je 0xc6b0
movl -0x44(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x44(%rbp)
jmp 0xc6b0
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x228, %esi            # imm = 0x228
callq 0x4250
jmp 0xc6d5
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movl -0x44(%rbp), %edx
callq 0x16f90
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x4420
nop
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFile.cpp
// Function: CCapsFile::Seek(int, int)
int CCapsFile::Seek(int pos, int mode)
{
	if (!mode)
		mode = CBaseFile::Current;
	else
		mode = CBaseFile::Position;

	return file->Seek(pos, mode);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0xc769
movl $0x2, -0x10(%rbp)
jmp 0xc770
movl $0x1, -0x10(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movslq -0xc(%rbp), %rsi
movl -0x10(%rbp), %edx
movq (%rdi), %rax
callq *0x28(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFormatMFM.cpp
// Function: CAPSFormatDataToMFM(void*, unsigned int)
SDWORD __cdecl CAPSFormatDataToMFM(PVOID pformattrack, UDWORD flag)
{
	if (!pformattrack)
		return imgeGeneric;

	// structure revision is zero, unless newer one requested
	unsigned rev=0;
	if (flag & DI_LOCK_TYPE)
		rev=*(PUDWORD)pformattrack;

	// if unsupported type set the highest supported version
	if (rev > 0) {
		*(PUDWORD)pformattrack=0;
		return imgeUnsupportedType;
	}

	PCAPSFORMATTRACK pf=(PCAPSFORMATTRACK)pformattrack;

	// if buffer not set, return the required buffer size
	if (!pf->trackbuf || !pf->tracklen || !pf->buflen)
		return FmfmGetSize(pf);

	// track buffer should not exceed allocated memory
	if (pf->tracklen > pf->buflen)
		return imgeBufferShort;

	// calculate track size and check descriptors
	int res=FmfmGetSize(pf);

	// cancel if track definition error
	if (res != imgeOk)
		return res;

	// cancel if track size too short
	if (pf->tracklen < pf->bufreq)
		return imgeBufferShort;

	// error if data start position is invalid
	if (pf->startpos >= pf->tracklen)
		return imgeBadDataStart;

	// convert the data
	return FmfmConvert(pf);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xc832
movl $0x2, -0x4(%rbp)
jmp 0xc913
movl $0x0, -0x18(%rbp)
movl -0x14(%rbp), %eax
andq $0x200, %rax            # imm = 0x200
cmpq $0x0, %rax
je 0xc851
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jbe 0xc86d
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movl $0xf, -0x4(%rbp)
jmp 0xc913
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0xc894
movq -0x20(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0xc894
movq -0x20(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0xc8a2
movq -0x20(%rbp), %rdi
callq 0xc920
movl %eax, -0x4(%rbp)
jmp 0xc913
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jbe 0xc8bb
movl $0x13, -0x4(%rbp)
jmp 0xc913
movq -0x20(%rbp), %rdi
callq 0xc920
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xc8d5
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xc913
movq -0x20(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jae 0xc8ee
movl $0x13, -0x4(%rbp)
jmp 0xc913
movq -0x20(%rbp), %rax
movl 0x24(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jb 0xc907
movl $0x12, -0x4(%rbp)
jmp 0xc913
movq -0x20(%rbp), %rdi
callq 0xca80
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFormatMFM.cpp
// Function: FmfmGetSize(CapsFormatTrack*)
int FmfmGetSize(PCAPSFORMATTRACK pf)
{
	// reset track size
	UDWORD len=0;
	pf->bufreq=0;

	// first gap size
	len+=pf->gapacnt;

	// cancel if invalid blocks
	if (pf->blockcnt && !pf->block)
		return imgeGeneric;

	// add length for each block
	for (int blk=0; blk < pf->blockcnt; blk++) {
		// get block
		PCAPSFORMATBLOCK pb=pf->block+blk;

		// add gap sizes
		len+=pb->gapacnt;
		len+=pb->gapbcnt;
		len+=pb->gapccnt;
		len+=pb->gapdcnt;

		// sum block data
		int sv=false;
		switch (pb->blocktype) {
			// index block; 3am, fc
			case cfrmbtIndex:
				len+=4;
				break;

			// data block; 3am, fe, 4hdr, 2crc, 3am, fb, data, 2crc
			case cfrmbtData:
				len+=16;
				len+=pb->sectorlen;
				sv=true;
				break;

			default:
				return imgeBadBlockType;
		}

		// if sector length used check its validity
		if (sv && FmfmSectorLength(pb->sectorlen)<0)
			return imgeBadBlockSize;
	}

	// set requested size in mfm
	pf->bufreq=len*2;

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0x20(%rax)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0xc96c
movq -0x10(%rbp), %rax
cmpq $0x0, 0x2c(%rax)
jne 0xc96c
movl $0x2, -0x4(%rbp)
jmp 0xca6d
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0xca5a
movq -0x10(%rbp), %rax
movq 0x2c(%rax), %rax
movslq -0x18(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %ecx
movl -0x14(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
movl -0x14(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rax
movl 0x10(%rax), %ecx
movl -0x14(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rax
movl 0x18(%rax), %ecx
movl -0x14(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x20(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x28(%rbp)
subl $0x1, %eax
je 0xc9f7
jmp 0xc9ed
movl -0x28(%rbp), %eax
subl $0x2, %eax
je 0xca02
jmp 0xca21
movl -0x14(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x14(%rbp)
jmp 0xca2a
movl -0x14(%rbp), %eax
addl $0x10, %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rax
movl 0x30(%rax), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl $0x1, -0x24(%rbp)
jmp 0xca2a
movl $0x10, -0x4(%rbp)
jmp 0xca6d
cmpl $0x0, -0x24(%rbp)
je 0xca4a
movq -0x20(%rbp), %rax
movl 0x30(%rax), %edi
callq 0xcb70
cmpl $0x0, %eax
jge 0xca4a
movl $0x11, -0x4(%rbp)
jmp 0xca6d
jmp 0xca4c
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc973
movl -0x14(%rbp), %ecx
shll %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
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/CapsFormatMFM.cpp
// Function: FmfmConvert(CapsFormatTrack*)
int FmfmConvert(PCAPSFORMATTRACK pf)
{
	// reset size
	pf->size=0;

	// reset size counter and mfm state
	UDWORD state=(0)<<15 ^ 0xffff;

	// write index gap
	state=FmfmWriteDataByte(pf, state, pf->gapavalue, pf->gapacnt);

	// process all blocks
	for (int blk=0; blk < pf->blockcnt; blk++) {
		// get block
		PCAPSFORMATBLOCK pb=pf->block+blk;

		// write block data
		switch (pb->blocktype) {
			// index block; 3am, fc,gap
			case cfrmbtIndex:
				state=FmfmWriteBlockIndex(pf, state, pb);
				break;

			// data block; 3am, fe, 4hdr, 2crc, 3am, fb, data, 2crc
			case cfrmbtData:
				state=FmfmWriteBlockData(pf, state, pb);
				break;
		}
	}

	// write gap size before index
	int gapbcnt=(pf->tracklen-pf->size)/2;
	if (gapbcnt > 0)
		state=FmfmWriteDataByte(pf, state, pf->gapbvalue, gapbcnt);

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl $0x0, 0x34(%rax)
movl $0xffff, -0xc(%rbp)     # imm = 0xFFFF
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x8(%rbp), %rax
movl 0x4(%rax), %ecx
callq 0xcbe0
movl %eax, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0xcb35
movq -0x8(%rbp), %rax
movq 0x2c(%rax), %rax
movslq -0x10(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x20(%rbp)
subl $0x1, %eax
je 0xcb00
jmp 0xcaf6
movl -0x20(%rbp), %eax
subl $0x2, %eax
je 0xcb15
jmp 0xcb28
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movq -0x18(%rbp), %rdx
callq 0xccd0
movl %eax, -0xc(%rbp)
jmp 0xcb28
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movq -0x18(%rbp), %rdx
callq 0xcd60
movl %eax, -0xc(%rbp)
jmp 0xcb2a
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xcac2
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x8(%rbp), %rcx
subl 0x34(%rcx), %eax
shrl %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0xcb67
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movq -0x8(%rbp), %rax
movl 0xc(%rax), %edx
movl -0x1c(%rbp), %ecx
callq 0xcbe0
movl %eax, -0xc(%rbp)
xorl %eax, %eax
addq $0x20, %rsp
popq %rbp
retq
nop
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFormatMFM.cpp
// Function: FmfmSectorLength(int)
int FmfmSectorLength(int value)
{
	switch (value) {
		case 128:
			return 0;

		case 256:
			return 1;

		case 512:
			return 2;

		case 1024:
			return 3;
	}

	return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %edi, -0x8(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0xc(%rbp)
subl $0x80, %eax
je 0xcbaa
jmp 0xcb86
movl -0xc(%rbp), %eax
subl $0x100, %eax            # imm = 0x100
je 0xcbb3
jmp 0xcb92
movl -0xc(%rbp), %eax
subl $0x200, %eax            # imm = 0x200
je 0xcbbc
jmp 0xcb9e
movl -0xc(%rbp), %eax
subl $0x400, %eax            # imm = 0x400
je 0xcbc5
jmp 0xcbce
movl $0x0, -0x4(%rbp)
jmp 0xcbd5
movl $0x1, -0x4(%rbp)
jmp 0xcbd5
movl $0x2, -0x4(%rbp)
jmp 0xcbd5
movl $0x3, -0x4(%rbp)
jmp 0xcbd5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFormatMFM.cpp
// Function: FmfmWriteDataByte(CapsFormatTrack*, unsigned int, unsigned int, int)
UDWORD FmfmWriteDataByte(PCAPSFORMATTRACK pf, UDWORD state, UDWORD value, int count)
{
	pf->size+=count*2;
	UDWORD pos=pf->startpos;

	// write mfm bytes
	while (count--) {
		UDWORD val=CDiskEncoding::mfmcode[value & 0xff] & state;
		state=(val & 1)<<15 ^ 0xffff;

		pf->trackbuf[pos++]=UBYTE(val>>8);
		if (pos >= pf->tracklen)
			pos=0;

		pf->trackbuf[pos++]=(UBYTE)val;
		if (pos >= pf->tracklen)
			pos=0;
	}

	pf->startpos=pos;

	return state;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl -0x14(%rbp), %ecx
shll %ecx
movq -0x8(%rbp), %rax
addl 0x34(%rax), %ecx
movl %ecx, 0x34(%rax)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x14(%rbp)
cmpl $0x0, %eax
je 0xccb5
leaq 0x1c993(%rip), %rax     # 0x295b8
movq (%rax), %rax
movl -0x10(%rbp), %ecx
andl $0xff, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
andl -0xc(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
andl $0x1, %eax
shll $0xf, %eax
xorl $0xffff, %eax           # imm = 0xFFFF
movl %eax, -0xc(%rbp)
movl -0x1c(%rbp), %eax
shrl $0x8, %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x18(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x18(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jb 0xcc80
movl $0x0, -0x18(%rbp)
movl -0x1c(%rbp), %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x18(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x18(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jb 0xccb0
movl $0x0, -0x18(%rbp)
jmp 0xcc0a
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x24(%rax)
movl -0xc(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFormatMFM.cpp
// Function: FmfmWriteBlockIndex(CapsFormatTrack*, unsigned int, CapsFormatBlock*)
UDWORD FmfmWriteBlockIndex(PCAPSFORMATTRACK pf, UDWORD state, PCAPSFORMATBLOCK pb)
{
	// gap before first am
	state=FmfmWriteDataByte(pf, state, pb->gapavalue, pb->gapacnt);

	// 3 am c2/5224
	state=FmfmWriteMarkByte(pf, state, 0x5224, 3);

	// fc
	state=FmfmWriteDataByte(pf, state, 0xfc, 1);

	// gap after first am
	state=FmfmWriteDataByte(pf, state, pb->gapbvalue, pb->gapbcnt);

	return state;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x18(%rbp), %rax
movl (%rax), %ecx
callq 0xcbe0
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl $0x5224, %edx           # imm = 0x5224
movl $0x3, %ecx
callq 0xd090
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl $0xfc, %edx
movl $0x1, %ecx
callq 0xcbe0
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movq -0x18(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
callq 0xcbe0
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFormatMFM.cpp
// Function: FmfmWriteMarkByte(CapsFormatTrack*, unsigned int, unsigned int, int)
UDWORD FmfmWriteMarkByte(PCAPSFORMATTRACK pf, UDWORD state, UDWORD value, int count)
{
	pf->size+=count*2;
	UDWORD pos=pf->startpos;
	UDWORD val=value & 0xffff;
	state=(val & 1)<<15 ^ 0xffff;

	// write mfm bytes
	while (count--) {
		pf->trackbuf[pos++]=UBYTE(val>>8);
		if (pos >= pf->tracklen)
			pos=0;

		pf->trackbuf[pos++]=(UBYTE)val;
		if (pos >= pf->tracklen)
			pos=0;
	}

	pf->startpos=pos;

	return state;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl -0x14(%rbp), %ecx
shll %ecx
movq -0x8(%rbp), %rax
addl 0x34(%rax), %ecx
movl %ecx, 0x34(%rax)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
andl $0x1, %eax
shll $0xf, %eax
xorl $0xffff, %eax           # imm = 0xFFFF
movl %eax, -0xc(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x14(%rbp)
cmpl $0x0, %eax
je 0xd14b
movl -0x1c(%rbp), %eax
shrl $0x8, %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x18(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x18(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jb 0xd119
movl $0x0, -0x18(%rbp)
movl -0x1c(%rbp), %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x18(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x18(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jb 0xd149
movl $0x0, -0x18(%rbp)
jmp 0xd0d6
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x24(%rax)
movl -0xc(%rbp), %eax
popq %rbp
retq
nopw (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFormatMFM.cpp
// Function: FmfmCrc(unsigned short, unsigned int, int)
UWORD FmfmCrc(UWORD crc, UDWORD value, int count)
{
	value&=0xff;

	while (count--)
		crc=crctab_ccitt[value^(crc>>8)] ^ (crc << 8);

	return crc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movw %di, %ax
movw %ax, -0x2(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl -0x8(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x8(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0xc(%rbp)
cmpl $0x0, %eax
je 0xd1b6
movl -0x8(%rbp), %eax
movzwl -0x2(%rbp), %ecx
sarl $0x8, %ecx
xorl %ecx, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x1af8d(%rip), %rax     # 0x28130
movzwl (%rax,%rcx,2), %eax
movzwl -0x2(%rbp), %ecx
shll $0x8, %ecx
xorl %ecx, %eax
movw %ax, -0x2(%rbp)
jmp 0xd17c
movw -0x2(%rbp), %ax
popq %rbp
retq
nopl (%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImage.cpp
// Function: CCapsImage::CompareImage()
int CCapsImage::CompareImage()
{
	PDISKTRACKINFO pti=di.pdt;

	int res=imgeOk;

	// default track size
	pti->tracklen=pti->ci.trksize;

	// generate 1 revolution
	pti->trackcnt=1;

	// unformatted track ignored
	if (pti->ci.dentype == cpdenNoise)
		pti->trackcnt=0;

	pti->tracklen*=pti->trackcnt;

	// allocate and set buffer
	if (pti->tracklen) {
		pti->trackbuf=new UBYTE[pti->tracklen];
		memset(pti->trackbuf, 0, pti->tracklen);
	}

	// set track size and pointer
	pti->trackdata[0]=pti->trackbuf;
	pti->tracksize[0]=0;
	pti->trackstart[0]=0;

	// decoder start position is always 0
	pti->comppos=0;
	pti->sdpos=0;

	// decode blocks
	if (pti->trackcnt) {
		int eblk=pti->compeblk;
		if (eblk < 0)
			eblk=pti->ci.blkcnt;
		else
			eblk++;

		for (int blk=pti->compsblk; blk < eblk; blk++)
			if ((res=CompareBlock(blk)) != imgeOk)
				return res;
	}

	pti->tracksize[0]=pti->comppos;
	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq 0x210(%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl 0x110(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x18(%rbp), %rax
movl $0x1, 0x28(%rax)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x108(%rax)
jne 0xd21a
movq -0x18(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x18(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0x18(%rbp), %rax
imull 0x50(%rax), %ecx
movl %ecx, 0x50(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0xd265
movq -0x18(%rbp), %rax
movslq 0x50(%rax), %rdi
callq 0x4040
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x18(%rbp), %rax
movslq 0x50(%rax), %rdx
xorl %esi, %esi
callq 0x4140
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x80(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x94(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0xbc(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0xc0(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0xd322
movq -0x18(%rbp), %rax
movl 0xcc(%rax), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0xd2d9
movq -0x18(%rbp), %rax
movl 0x128(%rax), %eax
movl %eax, -0x20(%rbp)
jmp 0xd2e2
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0xc8(%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xd320
movq -0x30(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0xd350
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
je 0xd313
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xd33c
jmp 0xd315
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xd2ef
jmp 0xd322
movq -0x18(%rbp), %rax
movl 0xbc(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x80(%rax)
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/CapsImage.cpp
// Function: CCapsImage::DecompressDump()
int CCapsImage::DecompressDump()
{
	// raw images can't be: compared, 16 bit aligned
	if (di.flag & (DI_LOCK_COMP | DI_LOCK_ALIGN))
		return imgeUnsupported;

	PDISKTRACKINFO pti = di.pdt;
	uint8_t *buf=di.data;

	CCTRawCodec ctr;

	// decompress data
	int res=ctr.DecompressDump(buf, pti->datasize);
	if (res == imgeOk) {
		ConvertDumpInfo(ctr.GetInfo());
	} else
		pti->type=dtitError;

	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x100(%rbp)
movl 0x208(%rax), %eax
movabsq $0x80000002, %rcx       # imm = 0x80000002
andq %rcx, %rax
cmpq $0x0, %rax
je 0xd7af
movl $0x1, -0x4(%rbp)
jmp 0xd87e
movq -0x100(%rbp), %rax
movq 0x210(%rax), %rcx
movq %rcx, -0x18(%rbp)
movq 0x1e8(%rax), %rax
movq %rax, -0x20(%rbp)
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x5aa0
movq -0x110(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x24(%rax), %edx
callq 0x5de0
movl %eax, -0x104(%rbp)
jmp 0xd7fe
movl -0x104(%rbp), %eax
movl %eax, -0xe4(%rbp)
cmpl $0x0, -0xe4(%rbp)
jne 0xd85f
leaq -0xe0(%rbp), %rdi
callq 0xe0a0
movq %rax, -0x118(%rbp)
jmp 0xd828
movq -0x118(%rbp), %rsi
movq -0x100(%rbp), %rdi
callq 0xd8a0
jmp 0xd83d
jmp 0xd869
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x5b00
jmp 0xd88a
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movl -0xe4(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x5b00
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0xf0(%rbp), %rdi
callq 0x4420
nopw %cs:(%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImage.cpp
// Function: CCapsImage::InitFirstBitTables()
void CCapsImage::InitFirstBitTables()
{
	// stop if already initialized
	if (fb_init)
		return;

	// initialize only once
	fb_init = 1;

	// process all positions
	for (int startbit = 0; startbit < 8; startbit++) {
		// position#0 is bit#7...position#7 is bit#0
		int bitmask = 1 << (7-startbit);

		// process all values
		for (int value = 0; value < 256; value++) {

			// find the first 0 bit starting with the current position
			int bitpos = startbit;
			for (int bm = bitmask; bm; bm >>= 1, bitpos++) {
				if (!(value & bm))
					break;
			}

			// store the position; 8 means not found
			f0b_table[startbit][value] = bitpos;

			// find the first 1 bit starting with the current position
			bitpos = startbit;
			for (int bm = bitmask; bm; bm >>= 1, bitpos++) {
				if (value & bm)
					break;
			}

			// store the position; 8 means not found
			f1b_table[startbit][value] = bitpos;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
cmpl $0x0, 0x1a9a5(%rip)     # 0x28584
je 0xdbe6
jmp 0xdce9
movl $0x1, 0x1a994(%rip)     # 0x28584
movl $0x0, -0xc(%rbp)
cmpl $0x8, -0xc(%rbp)
jge 0xdce9
movl $0x7, %ecx
subl -0xc(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x100, -0x14(%rbp)     # imm = 0x100
jge 0xdcd9
movl -0xc(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0xdc5b
movl -0x14(%rbp), %eax
andl -0x1c(%rbp), %eax
cmpl $0x0, %eax
jne 0xdc46
jmp 0xdc5b
jmp 0xdc48
movl -0x1c(%rbp), %eax
sarl %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xdc33
movl -0x18(%rbp), %eax
movb %al, %dl
movslq -0xc(%rbp), %rcx
leaq 0x1a925(%rip), %rax     # 0x28590
shlq $0x8, %rcx
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0xc(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0xdcad
movl -0x14(%rbp), %eax
andl -0x20(%rbp), %eax
cmpl $0x0, %eax
je 0xdc98
jmp 0xdcad
jmp 0xdc9a
movl -0x20(%rbp), %eax
sarl %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xdc85
movl -0x18(%rbp), %eax
movb %al, %dl
movslq -0xc(%rbp), %rcx
leaq 0x1b0d3(%rip), %rax     # 0x28d90
shlq $0x8, %rcx
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xdc1a
jmp 0xdcdb
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xdbf7
popq %rbp
retq
nopl (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImage.cpp
// Function: CCapsImage::AddWeakBitArea(int, int, int)
void CCapsImage::AddWeakBitArea(int group, int bitpos, int size)
{
	DiskDataMark ddm;
	ddm.group = group;
	ddm.position = bitpos;
	ddm.size = size;
	AddFD(di.pdt, &ddm, 1, (CAPS_MTRS * DEF_CTRAW_FDALLOC));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
movl %ecx, -0x20(%rbp)
movl -0x10(%rbp), %ecx
movl %ecx, -0x1c(%rbp)
movl -0x14(%rbp), %ecx
movl %ecx, -0x18(%rbp)
movq 0x210(%rax), %rdi
leaq -0x20(%rbp), %rsi
movl $0x1, %edx
movl $0x140, %ecx            # imm = 0x140
callq 0x18c40
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::InitSystem()
void CCapsImageStd::InitSystem()
{
	// set bitfield write length supported
	maxwritelen = MAX_BITBUFFER_LEN;

	// keep number of bits to read at maximum supported by streaming for raw encoding
	rawreadlen=MAX_STREAMBIT;

	// initialize mfm encoding tables
	CDiskEncoding::InitMFM(0x10000);

	// keep number of bits to read at maximum supported by mfm encoding
	mfmreadlen=CDiskEncoding::mfmcodebit;

	// mfm encoding table index mask
	mfmindexmask=(1 << mfmreadlen)-1;

	// the mfm encoding table assumes the last bit to be 0, correct encoding if it's 1
	// 1: 1-01 -> 1-01 unchanged after AND, msb already 0
	// 0: 1-10 -> 1-00 AND clears msb
	mfmmsbclear=(1 << ((mfmreadlen*2)-1))-1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movl $0x20, 0x218(%rax)
movl $0x20, 0x21c(%rax)
movl $0x10000, %edi          # imm = 0x10000
callq 0x16070
movq -0x10(%rbp), %rax
leaq 0x1b367(%rip), %rcx     # 0x295b4
movl (%rcx), %ecx
movl %ecx, 0x220(%rax)
movl 0x220(%rax), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
subl $0x1, %ecx
movl %ecx, 0x224(%rax)
movl 0x220(%rax), %ecx
shll %ecx
subl $0x1, %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
subl $0x1, %ecx
movl %ecx, 0x228(%rax)
addq $0x10, %rsp
popq %rbp
retq
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::Clear()
void CCapsImageStd::Clear()
{
	di.pdt=NULL;
	di.data=NULL;
	di.block=NULL;
	di.flag=0;
	di.track=NULL;
	di.trackbc=0;
	di.singletrackbc=0;
	di.dsctrackbc=0;
	di.dscdatabc=0;
	di.dscgapbc=0;
	di.dscstartbit=0;
	di.encbitpos=0;
	di.encwritebc=0;
	di.encgsvalid=0;
	di.encgapsplit=0;

	trackbuf.InitBitSize(di.track, di.trackbc);
	FreeDecoder();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq $0x0, 0x210(%rax)
movq $0x0, 0x1e8(%rax)
movq $0x0, 0x1f8(%rax)
movl $0x0, 0x208(%rax)
movq $0x0, 0x1b8(%rax)
movl $0x0, 0x1c0(%rax)
movl $0x0, 0x1c4(%rax)
movl $0x0, 0x1c8(%rax)
movl $0x0, 0x1cc(%rax)
movl $0x0, 0x1d0(%rax)
movl $0x0, 0x1d4(%rax)
movl $0x0, 0x1d8(%rax)
movl $0x0, 0x1dc(%rax)
movl $0x0, 0x1e0(%rax)
movl $0x0, 0x1e4(%rax)
movq %rax, %rdi
addq $0xb8, %rdi
movq 0x1b8(%rax), %rsi
movl 0x1c0(%rax), %edx
callq 0x4ce0
movq -0x10(%rbp), %rdi
callq 0xe3d0
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::Lock(CapsFile*)
int CCapsImageStd::Lock(PCAPSFILE pcf)
{
	// release image data
	Unlock();

	// try to lock
	switch (loader.Lock(pcf)) {
		// file open error
		case CCapsLoader::ccidErrFile:
			return imgeOpen;

		// not a caps file
		case CCapsLoader::ccidErrType:
			return imgeType;

		// yes, caps file
		case CCapsLoader::ccidCaps:
			break;

		// unknown problem
		default:
			return imgeGeneric;
	}

	// store open mode
	dii.readonly=(pcf->flag & CFF_WRITE) ? 0 : 1;

	// scan whole file for information
	int res=ScanImage();
	if (res != imgeOk)
		return res;

	return CheckEncoder(dii.ci.encoder, dii.ci.encrev);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x28(%rbp)
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
movq -0x28(%rbp), %rdi
addq $0xd0, %rdi
movq -0x18(%rbp), %rsi
callq 0x152d0
movl %eax, %ecx
movl %ecx, -0x20(%rbp)
testl %eax, %eax
je 0xe496
jmp 0xe470
movl -0x20(%rbp), %eax
subl $0x1, %eax
je 0xe484
jmp 0xe47a
movl -0x20(%rbp), %eax
subl $0x2, %eax
je 0xe48d
jmp 0xe498
movl $0x5, -0x4(%rbp)
jmp 0xe4eb
movl $0x6, -0x4(%rbp)
jmp 0xe4eb
jmp 0xe4a1
movl $0x2, -0x4(%rbp)
jmp 0xe4eb
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
andq $0x1, %rdx
movl $0x1, %eax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, 0x14(%rdi)
callq 0xe500
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0xe4d9
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xe4eb
movq -0x28(%rbp), %rdi
movl 0x50(%rdi), %esi
movl 0x54(%rdi), %edx
callq 0xebb0
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::CheckEncoder(int, int)
int CCapsImageStd::CheckEncoder(int encoder, int revision)
{
	if (!dii.civalid)
		return imgeOk;

	int err=0;

	switch (encoder) {
		case CAPS_ENCODER:
			if (revision < 1 || revision > CAPS_ENCODER_REV)
				err=1;
			break;

		case SPS_ENCODER:
			if (revision < 1 || revision > SPS_ENCODER_REV)
				err=1;
			break;

		default:
			err=1;
			break;
	}

	return err ? imgeIncompatible : imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x48(%rax)
jne 0xebd1
movl $0x0, -0x4(%rbp)
jmp 0xec33
movl $0x0, -0x1c(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x20(%rbp)
subl $0x1, %eax
je 0xebef
jmp 0xebe5
movl -0x20(%rbp), %eax
subl $0x2, %eax
je 0xec04
jmp 0xec19
cmpl $0x1, -0x18(%rbp)
jl 0xebfb
cmpl $0x1, -0x18(%rbp)
jle 0xec02
movl $0x1, -0x1c(%rbp)
jmp 0xec20
cmpl $0x1, -0x18(%rbp)
jl 0xec10
cmpl $0x1, -0x18(%rbp)
jle 0xec17
movl $0x1, -0x1c(%rbp)
jmp 0xec20
movl $0x1, -0x1c(%rbp)
movl -0x1c(%rbp), %edx
xorl %eax, %eax
movl $0xe, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::UpdateImage(int)
int CCapsImageStd::UpdateImage(int group)
{
	int res=imgeOk;

	// set track buffer information
	di.track=di.pdt->trackbuf;
	di.trackbc=di.pdt->trackbc;
	di.singletrackbc=di.pdt->singletrackbc;
	trackbuf.InitBitSize(di.track, di.trackbc);
	
	// stop if track buffer is invalid
	if (!di.track || !di.trackbc || !di.singletrackbc)
		return imgeOk;

	// don't change track data if updates are disabled
	if (di.flag & DI_LOCK_NOUPDATE)
		return imgeOk;

	// update weak bit areas
	if (di.pdt->fdpsize && (di.flag & DI_LOCK_UPDATEFD))
		res=UpdateWeakBit(group);

	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x18(%rbp)
movq 0x210(%rax), %rcx
movq 0x48(%rcx), %rcx
movq %rcx, 0x1b8(%rax)
movq 0x210(%rax), %rcx
movl 0xe8(%rcx), %ecx
movl %ecx, 0x1c0(%rax)
movq 0x210(%rax), %rcx
movl 0xec(%rcx), %ecx
movl %ecx, 0x1c4(%rax)
movq %rax, %rdi
addq $0xb8, %rdi
movq 0x1b8(%rax), %rsi
movl 0x1c0(%rax), %edx
callq 0x4ce0
movq -0x20(%rbp), %rax
cmpq $0x0, 0x1b8(%rax)
je 0xeeba
movq -0x20(%rbp), %rax
cmpl $0x0, 0x1c0(%rax)
je 0xeeba
movq -0x20(%rbp), %rax
cmpl $0x0, 0x1c4(%rax)
jne 0xeec3
movl $0x0, -0x4(%rbp)
jmp 0xef21
movq -0x20(%rbp), %rax
movl 0x208(%rax), %eax
andq $0x2000, %rax           # imm = 0x2000
cmpq $0x0, %rax
je 0xeee2
movl $0x0, -0x4(%rbp)
jmp 0xef21
movq -0x20(%rbp), %rax
movq 0x210(%rax), %rax
cmpl $0x0, 0xd0(%rax)
je 0xef1b
movq -0x20(%rbp), %rax
movl 0x208(%rax), %eax
andq $0x100, %rax            # imm = 0x100
cmpq $0x0, %rax
je 0xef1b
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0xf010
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::AllocDiskData(int)
void CCapsImageStd::AllocDiskData(int maxsize)
{
	if (di.datasize < maxsize) {
		FreeDiskData();

		di.data=new uint8_t[maxsize];
		di.datasize=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 0x1f0(%rax), %eax
cmpl -0xc(%rbp), %eax
jge 0xef7b
movq -0x18(%rbp), %rdi
callq 0x10d60
movslq -0xc(%rbp), %rdi
callq 0x4040
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x1e8(%rax)
movl -0xc(%rbp), %ecx
movl %ecx, 0x1f0(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::DecodeImage()
int CCapsImageStd::DecodeImage()
{
	// initialize disk and track data used by decoder
	int res=InitDecoder();

	// run supported encoders only
	if (res == imgeOk) {
		switch (dii.ci.encoder) {
			case CAPS_ENCODER:
			case SPS_ENCODER:
				res=ProcessImage();
				break;

			default:
				res=imgeIncompatible;
				break;
		}
	}

	// if any error destroy track buffers and supress later calls
	if (res != imgeOk) {
		FreeTrack(di.pdt, 1);
		di.pdt->type=dtitError;
	}

	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x18(%rbp)
callq 0xf2b0
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0xefd9
movq -0x18(%rbp), %rax
movl 0x50(%rax), %eax
decl %eax
subl $0x1, %eax
ja 0xefd0
jmp 0xefc2
movq -0x18(%rbp), %rdi
callq 0xf450
movl %eax, -0xc(%rbp)
jmp 0xefd7
movl $0xe, -0xc(%rbp)
jmp 0xefd9
cmpl $0x0, -0xc(%rbp)
je 0xf005
movq -0x18(%rbp), %rax
movq 0x210(%rax), %rdi
movl $0x1, %esi
callq 0x17de0
movq -0x18(%rbp), %rax
movq 0x210(%rax), %rax
movl $0x1, (%rax)
movl -0xc(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::UpdateOverlap()
void CCapsImageStd::UpdateOverlap()
{
	// don't change track data if updates are disabled
	if (di.flag & DI_LOCK_NOUPDATE)
		return;

	// stop if no bits to change
	int ovlsize=CIMG_OVERLAPBIT;
	if (ovlsize <= 0)
		return;

	// stop if overlap position is not available
	if (di.pdt->overlapbit < 0)
		return;

	uint32_t bitpos=di.pdt->overlapbit;

	// flip all bits at the overlap position for all tracks
	for (int trk=0; trk < di.pdt->trackcnt; trk++) {
		uint32_t value=trackbuf.ReadBitWrap(bitpos, ovlsize);
		value=~value;
		trackbuf.WriteBitWrap(bitpos, value, ovlsize);

		// next track
		bitpos+=di.singletrackbc;

		// handle track buffer wrap around (disk rotation)
		if (bitpos >= di.trackbc)
			bitpos-=di.trackbc;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movl 0x208(%rax), %eax
andq $0x2000, %rax           # imm = 0x2000
cmpq $0x0, %rax
je 0xf1cb
jmp 0xf29c
movl $0x3, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jg 0xf1dd
jmp 0xf29c
movq -0x20(%rbp), %rax
movq 0x210(%rax), %rax
cmpl $0x0, 0xe4(%rax)
jge 0xf1f6
jmp 0xf29c
movq -0x20(%rbp), %rax
movq 0x210(%rax), %rax
movl 0xe4(%rax), %eax
movl %eax, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x20(%rbp), %rcx
movl -0x14(%rbp), %eax
movq 0x210(%rcx), %rcx
cmpl 0x28(%rcx), %eax
jge 0xf29c
movq -0x20(%rbp), %rdi
addq $0xb8, %rdi
movl -0x10(%rbp), %esi
movl -0xc(%rbp), %edx
callq 0x13aa0
movq -0x20(%rbp), %rdi
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
xorl $-0x1, %eax
movl %eax, -0x18(%rbp)
addq $0xb8, %rdi
movl -0x10(%rbp), %esi
movl -0x18(%rbp), %edx
movl -0xc(%rbp), %ecx
callq 0x13a60
movq -0x20(%rbp), %rcx
movl 0x1c4(%rcx), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl 0x1c0(%rcx), %eax
jb 0xf28c
movq -0x20(%rbp), %rax
movl 0x1c0(%rax), %ecx
movl -0x10(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x10(%rbp)
jmp 0xf28e
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xf211
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)