LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movq 0x210(%rdi), %rax
movq 0x48(%rax), %rsi
movq %rsi, 0x1b8(%rdi)
movq 0xe8(%rax), %rdx
movq %rdx, 0x1c0(%rdi)
addq $0xb8, %rdi
callq 0x392a
cmpq $0x0, 0x1b8(%r14)
je 0x84f2
cmpl $0x0, 0x1c0(%r14)
je 0x84f2
cmpl $0x0, 0x1c4(%r14)
je 0x84f2
movl 0x208(%r14), %eax
btl $0xd, %eax
jb 0x84f2
btl $0x8, %eax
jae 0x84f2
movq 0x210(%r14), %rax
cmpl $0x0, 0xd0(%rax)
je 0x84f2
movq %r14, %rdi
movl %ebx, %esi
callq 0x8586
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/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:
cmpl %esi, 0x1f0(%rdi)
jge 0x852f
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebp
movq %rdi, %rbx
callq 0x9574
movslq %ebp, %r14
movq %r14, %rdi
callq 0x3040
movq %rax, 0x1e8(%rbx)
movl %r14d, 0x1f0(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x8700
testl %eax, %eax
je 0x8543
movl %eax, %ebp
jmp 0x8560
movl 0x50(%rbx), %eax
decl %eax
cmpl $0x1, %eax
ja 0x855d
movq %rbx, %rdi
callq 0x87fa
testl %eax, %eax
jne 0x853f
xorl %ebp, %ebp
jmp 0x857c
pushq $0xe
popq %rbp
movq 0x210(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0xc720
movq 0x210(%rbx), %rax
movl $0x1, (%rax)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::UpdateWeakBit(int)
int CCapsImageStd::UpdateWeakBit(int group)
{
	// don't change track data if updates are disabled
	if (di.flag & DI_LOCK_NOUPDATE)
		return imgeOk;

	// get random seed
	uint32_t seed=di.pdt->wseed;

	// update all areas marked
	for (int pos=0; pos < di.pdt->fdpsize; pos++) {
		PDISKDATAMARK pd=di.pdt->fdp+pos;

		// skip markers that belong to a different group
		if (pd->group != group)
			continue;

		uint32_t bitpos=pd->position;
		int bitcnt=pd->size;

		// write generated data
		while (bitcnt > 0) {
			// simple random generator
			seed<<=1;
			if ((seed>>22 ^ seed) & DF_1)
				seed++;

			// write largest possible bitfield
			int writebc=(bitcnt >= maxwritelen) ? maxwritelen : bitcnt;

			// write bitfield
			trackbuf.WriteBitWrap(bitpos, seed, writebc);

			// next write position
			bitcnt-=writebc;
			bitpos+=writebc;

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

	// save random seed, so any new update on the same track would give new results
	di.pdt->wseed=seed;

	return imgeOk;
}

// Assembly:
testb $0x20, 0x209(%rdi)
jne 0x866c
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movq 0x210(%rdi), %rax
movl 0xc4(%rax), %r15d
leaq 0xb8(%rdi), %r12
xorl %edi, %edi
movl %esi, 0xc(%rsp)
movslq 0xd0(%rax), %rcx
cmpq %rcx, %rdi
jge 0x8657
movq 0xd8(%rax), %rcx
imulq $0xc, %rdi, %rdx
cmpl %esi, (%rcx,%rdx)
jne 0x864f
movq %rdi, 0x10(%rsp)
addq %rdx, %rcx
movl 0x4(%rcx), %ebp
movl 0x8(%rcx), %ebx
testl %ebx, %ebx
jle 0x863f
movl %r15d, %eax
shrl $0x16, %eax
xorl %r15d, %eax
andl $0x1, %eax
leal (%rax,%r15,2), %r15d
movl 0x218(%r14), %r13d
cmpl %r13d, %ebx
cmovll %ebx, %r13d
movq %r12, %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %r13d, %ecx
callq 0xaae2
subl %r13d, %ebx
addl %ebp, %r13d
movl 0x1c0(%r14), %eax
cmpl %eax, %r13d
movl $0x0, %ecx
cmovbl %ecx, %eax
subl %eax, %r13d
movl %r13d, %ebp
jmp 0x85ed
movq 0x210(%r14), %rax
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %rdi
incq %rdi
jmp 0x85bf
movl %r15d, 0xc4(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
xorl %eax, %eax
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/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:
testb $0x20, 0x209(%rdi)
jne 0x86ff
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x210(%rdi), %rax
movl 0xe4(%rax), %ebp
testl %ebp, %ebp
js 0x86f1
leaq 0xb8(%rbx), %r14
xorl %r12d, %r12d
pushq $0x3
popq %r15
xorl %r13d, %r13d
cmpl 0x28(%rax), %r13d
jge 0x86f1
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0xaaf8
notl %eax
movq %r14, %rdi
movl %ebp, %esi
movl %eax, %edx
movl %r15d, %ecx
callq 0xaae2
addl 0x1c4(%rbx), %ebp
movl 0x1c0(%rbx), %eax
cmpl %eax, %ebp
cmovbl %r12d, %eax
subl %eax, %ebp
incl %r13d
movq 0x210(%rbx), %rax
jmp 0x86ad
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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:
cmpl $0x0, 0x48(%rdi)
je 0x876c
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x210(%rdi), %rax
movl 0x128(%rax), %esi
callq 0x959c
movq 0x210(%rbx), %rax
movl 0x128(%rax), %eax
movl %eax, 0x204(%rbx)
xorl %r15d, %r15d
xorl %r14d, %r14d
movslq 0x204(%rbx), %rsi
cmpq %rsi, %r14
jge 0x8774
movq 0x1f8(%rbx), %rsi
addq %r15, %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0x9606
incq %r14
addq $0x28, %r15
testl %eax, %eax
je 0x8739
movl %eax, %ecx
jmp 0x87f2
pushq $0xe
popq %rcx
jmp 0x87f7
leaq 0x1c8(%rbx), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x1c8(%rbx)
xorl %ecx, %ecx
testl %esi, %esi
cmovlel %ecx, %esi
movq 0x1f8(%rbx), %rdx
imulq $0x28, %rsi, %rdi
xorl %esi, %esi
xorl %r8d, %r8d
cmpq %rcx, %rdi
je 0x87ce
movl 0x4(%rdx,%rcx), %r9d
cmpl $0x7, %r9d
ja 0x87b4
andl $0x0, 0x4(%rdx,%rcx)
xorl %r9d, %r9d
addl (%rdx,%rcx), %r8d
movl %r8d, 0x1cc(%rbx)
addl %r9d, %esi
movl %esi, 0x1d0(%rbx)
addq $0x28, %rcx
jmp 0x879c
addl %r8d, %esi
movl %esi, (%rax)
je 0x87f0
movq 0x210(%rbx), %rax
movl 0x118(%rax), %eax
xorl %ecx, %ecx
xorl %edx, %edx
divl %esi
movl %edx, 0x1d4(%rbx)
jmp 0x87f2
xorl %ecx, %ecx
popq %rbx
popq %r14
popq %r15
movl %ecx, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::ProcessBlock(int, unsigned int, int, int)
int CCapsImageStd::ProcessBlock(int blk, uint32_t bitpos, int datasize, int gapsize)
{
	int res;

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

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

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

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

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

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

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

	return imgeOk;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, 0x1d8(%rdi)
andq $0x0, 0x1dc(%rdi)
andl $0x0, 0x1e4(%rdi)
pushq $0x2
popq %rax
testl %esi, %esi
js 0x8ca2
movl %r8d, %ebp
movl %esi, %r14d
movl %r8d, %esi
orl %ecx, %esi
js 0x8ca2
movq %rdi, %rbx
cmpl %r14d, 0x204(%rdi)
jle 0x8ca2
movq 0x210(%rbx), %rsi
cmpl %r14d, 0xf4(%rsi)
jle 0x8ca2
movq 0x1f8(%rbx), %rax
movl %r14d, %edi
imulq $0x28, %rdi, %r8
andl $0x0, 0x20(%rax,%r8)
movl %edx, 0x24(%rax,%r8)
movq 0xf8(%rsi), %r15
imulq $0x30, %rdi, %r12
movq (%rax,%r8), %rsi
movq %rsi, (%r15,%r12)
movq 0xc(%rax,%r8), %rax
movq %rax, 0x28(%r15,%r12)
movl %edx, 0x10(%r15,%r12)
movl %ecx, 0x8(%r15,%r12)
movq %rbx, %rdi
movl %r14d, %esi
movl %ecx, %edx
callq 0xa50a
testl %eax, %eax
je 0x8cab
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
addq %r12, %r15
movl 0x1d8(%rbx), %eax
movl %eax, 0x14(%r15)
movl %ebp, 0xc(%r15)
movq %rbx, %rdi
movl %r14d, %esi
movl %ebp, %edx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xa588
nop
// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
leaq 0xb8(%rdi), %r14
pushq $0x24
popq %r15
xorl %r12d, %r12d
pushq $0x1
popq %rbp
movslq 0x204(%rbx), %rax
cmpq %rax, %r12
jge 0x8d4b
movq 0x1f8(%rbx), %rax
cmpl $0x2, -0x4(%rax,%r15)
jne 0x8d42
movl (%rax,%r15), %esi
movl %esi, %eax
testl %esi, %esi
jne 0x8d19
movl 0x1c0(%rbx), %eax
decl %eax
movq 0xc0(%rbx), %rcx
movl %eax, %edx
shrl $0x3, %edx
movzbl (%rcx,%rdx), %ecx
notb %al
movzbl %al, %eax
andl $0x7, %eax
btl %eax, %ecx
jae 0x8d42
movq %r14, %rdi
movl %ebp, %edx
callq 0xab20
incq %r12
addq $0x28, %r15
jmp 0x8cee
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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:
movl $0x10030f01, %eax       # imm = 0x10030F01
xorl %ecx, %ecx
movslq 0x50(%rsi), %rdx
cmpq %rdx, %rcx
jge 0x8d73
movq 0x48(%rsi), %rdx
movb %al, (%rdx,%rcx)
roll $0x8, %eax
incq %rcx
jmp 0x8d5b
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::DecodeDensity(DiskTrackInfo*, unsigned char*, unsigned int)
int CCapsImageStd::DecodeDensity(PDISKTRACKINFO pti, PUBYTE buf, UDWORD flag)
{
	// generate density
	switch (pti->ci.dentype) {
		case cpdenNoise:
			if (flag & DI_LOCK_DENNOISE)
				GenerateNoiseDensity(pti);
			break;

		case cpdenAuto:
			if (flag & DI_LOCK_DENAUTO)
				GenerateAutoDensity(pti);
			break;

		case cpdenCLAmiga:
			if (flag & DI_LOCK_DENVAR)
				GenerateCLA(pti, buf);
			break;

		case cpdenCLAmiga2:
			if (flag & DI_LOCK_DENVAR)
				GenerateCLA2(pti, buf);
			break;

		case cpdenCLST:
			if (flag & DI_LOCK_DENVAR)
				GenerateCLST(pti, buf);
			break;

		case cpdenSLAmiga:
			if (flag & DI_LOCK_DENVAR)
				GenerateSLA(pti, buf);
			break;

		case cpdenSLAmiga2:
			if (flag & DI_LOCK_DENVAR)
				GenerateSLA2(pti, buf);
			break;

		case cpdenABAmiga:
			if (flag & DI_LOCK_DENVAR)
				GenerateABA(pti, buf);
			break;

		case cpdenABAmiga2:
			if (flag & DI_LOCK_DENVAR)
				GenerateABA2(pti, buf);
			break;
	}

	// density map conversion
	if (flag & DI_LOCK_DENALT)
		ConvertDensity(pti);

	return imgeOk;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %ecx, %ebp
movq %rsi, %rbx
movl 0x108(%rsi), %eax
decl %eax
cmpl $0x8, %eax
ja 0x8e31
leaq 0x6496(%rip), %rcx      # 0xf22c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testb $0x10, %bpl
je 0x8e31
movq %rbx, %rsi
callq 0x8e54
jmp 0x8e31
testb $0x4, %bpl
je 0x8e31
movq %rbx, %rsi
callq 0x917e
jmp 0x8e31
testb $0x4, %bpl
je 0x8e31
movq %rbx, %rsi
callq 0x8f90
jmp 0x8e31
testb $0x4, %bpl
je 0x8e31
movq %rbx, %rsi
callq 0x9082
jmp 0x8e31
testb $0x4, %bpl
je 0x8e31
movq %rbx, %rsi
callq 0x9340
jmp 0x8e31
testb $0x8, %bpl
je 0x8e31
movq %rbx, %rsi
callq 0x8f14
jmp 0x8e31
testb $0x4, %bpl
je 0x8e31
movq %rbx, %rsi
callq 0x920a
jmp 0x8e31
testb $0x4, %bpl
je 0x8e31
movq %rbx, %rsi
callq 0x92b4
jmp 0x8e31
testb $0x4, %bpl
je 0x8e31
movq %rbx, %rsi
callq 0x945e
btl $0xa, %ebp
jae 0x8e3f
movq %rbx, %rsi
callq 0x953e
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl 0x50(%rsi), %eax
testl %eax, %eax
je 0x8e6e
movl 0x28(%rbx), %ecx
testl %ecx, %ecx
je 0x8e6e
cltd
idivl %ecx
jmp 0x8e7e
movl 0x110(%rbx), %ecx
testl %ecx, %ecx
movl $0x30d4, %eax           # imm = 0x30D4
cmovnel %ecx, %eax
movl %eax, 0xa8(%rbx)
movslq %eax, %r14
leaq 0x4(,%r14,4), %rax
cmpl $-0x1, %r14d
pushq $-0x1
popq %rdi
cmovgeq %rax, %rdi
callq 0x3040
movq %rax, %rcx
movq %rax, 0xb0(%rbx)
xorl %esi, %esi
testl %r14d, %r14d
cmovlel %esi, %r14d
pushq $0x79
popq %r8
pushq $0x63
popq %r9
xorl %r10d, %r10d
xorl %edi, %edi
movl %esi, %eax
xorl %edx, %edx
divl %r8d
cmpq %rdi, %r14
je 0x8f04
btl $0x9, %edi
jb 0x8ee0
imull $0x79, %eax, %eax
movl %esi, %edx
andl $0x1f, %edx
addl %r10d, %edx
addl %eax, %edx
jmp 0x8ef1
movl %edi, %r11d
andl $0x1f, %r11d
movl %edi, %eax
xorl %edx, %edx
divl %r9d
addl %r11d, %edx
addl $0x3e8, %edx            # imm = 0x3E8
movl %edx, (%rcx,%rdi,4)
incq %rdi
decl %r10d
incl %esi
jmp 0x8ebf
andl $0x0, (%rcx,%r14,4)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl 0x50(%rsi), %eax
testl %eax, %eax
je 0x8f2e
movl 0x28(%rbx), %ecx
testl %ecx, %ecx
je 0x8f2e
cltd
idivl %ecx
jmp 0x8f3e
movl 0x110(%rbx), %ecx
testl %ecx, %ecx
movl $0x30d4, %eax           # imm = 0x30D4
cmovnel %ecx, %eax
movl %eax, 0xa8(%rbx)
movslq %eax, %r14
leaq 0x4(,%r14,4), %rax
cmpl $-0x1, %r14d
pushq $-0x1
popq %rdi
cmovgeq %rax, %rdi
callq 0x3040
movq %rax, 0xb0(%rbx)
xorl %ecx, %ecx
testl %r14d, %r14d
cmovlel %ecx, %r14d
cmpq %rcx, %r14
je 0x8f80
movl $0x3e8, (%rax,%rcx,4)   # imm = 0x3E8
incq %rcx
jmp 0x8f6f
andl $0x0, (%rax,%r14,4)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GenerateCLA(DiskTrackInfo*, unsigned char*)
int CCapsImageStd::GenerateCLA(PDISKTRACKINFO pti, PUBYTE buf)
{
	// set auto density
	GenerateAutoDensity(pti);

	// iterate block positions
	int lg = trackbuf.CalculateByteSize(di.block[3].gapbits);
	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 4:
				for (cp=0-lg; cp < bs; cp++) {
					pti->timebuf[pos+cp]-=55;
				}
				break;

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

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

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

	return imgeOk;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
callq 0x8f14
movq 0x1f8(%r14), %rax
movl 0x7c(%rax), %r11d
addl $0x7, %r11d
shrl $0x3, %r11d
movl 0xc0(%rbx), %esi
xorl %ecx, %ecx
xorl %edx, %edx
movl 0x128(%rbx), %edi
cmpq %rdi, %rdx
jae 0x9077
imulq $0x28, %rdx, %rdi
movl (%rax,%rdi), %r8d
movl 0x4(%rax,%rdi), %edi
addl $0x7, %r8d
shrl $0x3, %r8d
movslq %esi, %r9
movl %r8d, %r10d
movl %r11d, %r11d
cmpl $0x6, %edx
je 0x9031
cmpl $0x5, %edx
je 0x9014
cmpl $0x4, %edx
jne 0x904e
subq %r11, %r9
addq %r11, %r10
subq $0x1, %r10
jb 0x904e
movq 0xb0(%rbx), %r11
addl $-0x37, (%r11,%r9,4)
incq %r9
jmp 0x8ffd
subq %r11, %r9
addq %r11, %r10
subq $0x1, %r10
jb 0x904e
movq 0xb0(%rbx), %r11
addl $-0x5, (%r11,%r9,4)
incq %r9
jmp 0x901a
subq %r11, %r9
addq %r11, %r10
subq $0x1, %r10
jb 0x904e
movq 0xb0(%rbx), %r11
addl $0x2d, (%r11,%r9,4)
incq %r9
jmp 0x9037
addl $0x7, %edi
shrl $0x3, %edi
addl %esi, %r8d
addl %edi, %r8d
movl 0xa8(%rbx), %esi
cmpl %esi, %r8d
cmovll %ecx, %esi
subl %esi, %r8d
incq %rdx
movl %r8d, %esi
movl %edi, %r11d
jmp 0x8fbc
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GenerateCLA2(DiskTrackInfo*, unsigned char*)
int CCapsImageStd::GenerateCLA2(PDISKTRACKINFO pti, PUBYTE buf)
{
	// set auto density
	GenerateAutoDensity(pti);

	// iterate block positions
	int lg = trackbuf.CalculateByteSize(di.block[di.blockcount - 1].gapbits);
	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 0:
				for (cp=0-lg; cp < bs; cp++) {
					pti->timebuf[pos+cp]-=55;
				}
				break;

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

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

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

	return imgeOk;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
callq 0x8f14
movq 0x1f8(%r14), %rax
movslq 0x204(%r14), %rcx
imulq $0x28, %rcx, %rcx
movl -0x24(%rax,%rcx), %r11d
addl $0x7, %r11d
shrl $0x3, %r11d
movl 0xc0(%rbx), %esi
xorl %ecx, %ecx
xorl %edx, %edx
movl 0x128(%rbx), %edi
cmpq %rdi, %rdx
jae 0x9174
imulq $0x28, %rdx, %rdi
movl (%rax,%rdi), %r8d
movl 0x4(%rax,%rdi), %edi
addl $0x7, %r8d
shrl $0x3, %r8d
movslq %esi, %r9
movl %r8d, %r10d
movl %r11d, %r11d
cmpl $0x2, %edx
je 0x912e
cmpl $0x1, %edx
je 0x9111
testl %edx, %edx
jne 0x914b
subq %r11, %r9
addq %r11, %r10
subq $0x1, %r10
jb 0x914b
movq 0xb0(%rbx), %r11
addl $-0x37, (%r11,%r9,4)
incq %r9
jmp 0x90fa
subq %r11, %r9
addq %r11, %r10
subq $0x1, %r10
jb 0x914b
movq 0xb0(%rbx), %r11
addl $-0x5, (%r11,%r9,4)
incq %r9
jmp 0x9117
subq %r11, %r9
addq %r11, %r10
subq $0x1, %r10
jb 0x914b
movq 0xb0(%rbx), %r11
addl $0x2d, (%r11,%r9,4)
incq %r9
jmp 0x9134
addl $0x7, %edi
shrl $0x3, %edi
addl %esi, %r8d
addl %edi, %r8d
movl 0xa8(%rbx), %esi
cmpl %esi, %r8d
cmovll %ecx, %esi
subl %esi, %r8d
incq %rdx
movl %r8d, %esi
movl %edi, %r11d
jmp 0x90ba
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
callq 0x8f14
movl 0xc0(%rbx), %esi
movq 0x1f8(%r14), %rax
xorl %ecx, %ecx
xorl %edx, %edx
movl 0x128(%rbx), %edi
cmpq %rdi, %rdx
jae 0x9200
imulq $0x28, %rdx, %r8
movl (%rax,%r8), %edi
movl 0x4(%rax,%r8), %r8d
addl $0x7, %edi
shrl $0x3, %edi
cmpq $0x5, %rdx
jne 0x91df
movslq %esi, %r9
movl %edi, %r10d
subq $0x1, %r10
jb 0x91df
movq 0xb0(%rbx), %r11
addl $0x32, (%r11,%r9,4)
incq %r9
jmp 0x91c8
addl $0x7, %r8d
shrl $0x3, %r8d
addl %esi, %edi
addl %r8d, %edi
movl 0xa8(%rbx), %esi
cmpl %esi, %edi
cmovll %ecx, %esi
subl %esi, %edi
incq %rdx
movl %edi, %esi
jmp 0x919e
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
callq 0x8f14
movl 0xc0(%rbx), %esi
movq 0x1f8(%r14), %rax
xorl %ecx, %ecx
xorl %edx, %edx
movl 0x128(%rbx), %edi
cmpq %rdi, %rdx
jae 0x92aa
imulq $0x28, %rdx, %r8
movl (%rax,%r8), %edi
movl 0x4(%rax,%r8), %r8d
addl $0x7, %edi
shrl $0x3, %edi
movl %edi, %r9d
cmpl $0x1, %edx
je 0x926f
cmpl $0x2, %edx
jne 0x9289
movslq %esi, %r10
subq $0x1, %r9
jb 0x9289
movq 0xb0(%rbx), %r11
addl $-0x64, (%r11,%r10,4)
incq %r10
jmp 0x9258
movslq %esi, %r10
subq $0x1, %r9
jb 0x9289
movq 0xb0(%rbx), %r11
addl $0x64, (%r11,%r10,4)
incq %r10
jmp 0x9272
addl $0x7, %r8d
shrl $0x3, %r8d
addl %esi, %edi
addl %r8d, %edi
movl 0xa8(%rbx), %esi
cmpl %esi, %edi
cmovll %ecx, %esi
subl %esi, %edi
incq %rdx
movl %edi, %esi
jmp 0x922a
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GenerateABA(DiskTrackInfo*, unsigned char*)
int CCapsImageStd::GenerateABA(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]+=50;
				}
				break;

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

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

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

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

	return imgeOk;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
callq 0x8f14
movl 0xc0(%rbx), %edi
movq 0x1f8(%r14), %rax
xorl %ecx, %ecx
leaq 0x5eeb(%rip), %rdx      # 0xf250
xorl %esi, %esi
movl 0x128(%rbx), %r8d
cmpq %r8, %rsi
jae 0x9454
imulq $0x28, %rsi, %r9
movl (%rax,%r9), %r8d
movl 0x4(%rax,%r9), %r9d
addl $0x7, %r8d
shrl $0x3, %r8d
leal -0x1(%rsi), %r10d
cmpl $0x5, %r10d
ja 0x942c
movslq (%rdx,%r10,4), %r11
addq %rdx, %r11
movl %r8d, %r10d
jmpq *%r11
movslq %edi, %r11
subq $0x1, %r10
jb 0x942c
movq 0xb0(%rbx), %r14
addl $0x64, (%r14,%r11,4)
incq %r11
jmp 0x93aa
movslq %edi, %r11
subq $0x1, %r10
jb 0x942c
movq 0xb0(%rbx), %r14
addl $-0x32, (%r14,%r11,4)
incq %r11
jmp 0x93c4
movslq %edi, %r11
subq $0x1, %r10
jb 0x942c
movq 0xb0(%rbx), %r14
addl $0x32, (%r14,%r11,4)
incq %r11
jmp 0x93de
movslq %edi, %r11
subq $0x1, %r10
jb 0x942c
movq 0xb0(%rbx), %r14
addl $-0x64, (%r14,%r11,4)
incq %r11
jmp 0x93f8
movslq %edi, %r11
subq $0x1, %r10
jb 0x942c
movq 0xb0(%rbx), %r14
addl $0xffffff6a, (%r14,%r11,4) # imm = 0xFFFFFF6A
incq %r11
jmp 0x9412
addl $0x7, %r9d
shrl $0x3, %r9d
addl %edi, %r8d
addl %r9d, %r8d
movl 0xa8(%rbx), %edi
cmpl %edi, %r8d
cmovll %ecx, %edi
subl %edi, %r8d
incq %rsi
movl %r8d, %edi
jmp 0x9367
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0x10(%rsp)
callq 0x8f14
movl 0xc0(%r14), %r12d
addq $0x18, %rbx
movq %rbx, 0x8(%rsp)
xorl %r8d, %r8d
pushq $0x1
popq %r13
xorl %ebp, %ebp
xorl %eax, %eax
movl 0x128(%r14), %ecx
cmpq %rcx, %rbp
jae 0x952d
movq 0x10(%rsp), %rcx
movq 0x1f8(%rcx), %rcx
imulq $0x28, %rbp, %rdx
movl (%rcx,%rdx), %ebx
movl 0x4(%rcx,%rdx), %r15d
addl $0x7, %ebx
shrl $0x3, %ebx
testq %rbp, %rbp
je 0x94f5
testl %r13d, %eax
pushq $-0x32
popq %rcx
pushq $0x32
popq %rdx
cmovel %edx, %ecx
movslq %r12d, %rdx
movl %ebx, %esi
subq $0x1, %rsi
jb 0x94f0
movq 0xb0(%r14), %rdi
addl %ecx, (%rdi,%rdx,4)
incq %rdx
jmp 0x94db
addl %r13d, %r13d
jmp 0x9505
movq 0x8(%rsp), %rdi
pushq $0x4
popq %rsi
callq 0xce28
xorl %r8d, %r8d
addl $0x7, %r15d
shrl $0x3, %r15d
addl %r12d, %ebx
addl %r15d, %ebx
movl 0xa8(%r14), %ecx
cmpl %ecx, %ebx
cmovll %r8d, %ecx
subl %ecx, %ebx
incq %rbp
movl %ebx, %r12d
jmp 0x9497
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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:
movq 0xb0(%rsi), %rax
testq %rax, %rax
je 0x9571
movl 0xa8(%rsi), %edi
testl %edi, %edi
je 0x9571
xorl %ecx, %ecx
xorl %edx, %edx
movslq %edi, %rdi
cmpq %rdi, %rcx
jge 0x9571
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
movl 0xa8(%rsi), %edi
jmp 0x9558
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O2/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:
cmpl %esi, 0x200(%rdi)
jge 0x95dc
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebp
movq %rdi, %rbx
callq 0x95de
movslq %ebp, %r14
pushq $0x28
popq %rcx
movq %r14, %rax
mulq %rcx
pushq $-0x1
popq %rdi
cmovnoq %rax, %rdi
callq 0x3040
movq %rax, 0x1f8(%rbx)
movl %r14d, 0x200(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 $0x2
popq %rax
testl %edx, %edx
js 0x96ca
testq %rsi, %rsi
je 0x96ca
movq 0x1e8(%rdi), %rcx
testq %rcx, %rcx
je 0x96ca
cmpl %edx, 0x204(%rdi)
jle 0x96ca
movl %edx, %eax
shll $0x5, %eax
addl $0x20, %eax
movq 0x210(%rdi), %rdi
cmpl 0x24(%rdi), %eax
jle 0x96a0
pushq $0x7
popq %rax
retq
pushq %rax
movl %edx, %eax
shlq $0x5, %rax
movups (%rcx,%rax), %xmm0
movups 0x10(%rcx,%rax), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
pushq $0x20
popq %rax
movq %rsi, %rdi
movl %eax, %esi
callq 0xb0e0
xorl %eax, %eax
addq $0x8, %rsp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
pushq %rax
pushq $0x2
popq %rax
testq %rsi, %rsi
je 0x972e
testl %ecx, %ecx
js 0x972e
movq %rdi, %r14
cmpl %ecx, 0x204(%rdi)
jle 0x972e
movq %rsi, %rbx
movl %edx, (%rsi)
movl %ecx, 0x4(%rsi)
movq 0x1f8(%r14), %rsi
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
movl 0x10(%rsi,%rcx), %ecx
movl %ecx, 0x8(%rbx)
movl %ecx, 0xc(%rbx)
leal -0x1(%rdx), %ecx
cmpl $0x2, %ecx
jae 0x971b
movq %r14, %rdi
movq %rbx, %rsi
callq 0x97bc
jmp 0x972a
testl %edx, %edx
jne 0x972e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x9748
testl %eax, %eax
je 0x9736
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq %r14, %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x98e2
// File: /workspace/github_cpp_makefile_star2_O2/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:
andl $0x0, 0x44(%rsi)
movq 0x1f8(%rdi), %rdx
movslq 0x4(%rsi), %r10
imulq $0x28, %r10, %r9
movl 0x14(%rdx,%r9), %eax
shrl $0x2, %eax
andl $0x1, %eax
movl %eax, 0x10(%rsi)
movl 0x1c(%rdx,%r9), %ecx
movl %ecx, 0x14(%rsi)
movq 0x210(%rdi), %rax
movl 0x24(%rax), %r8d
pushq $0x7
popq %rax
cmpl %r8d, %ecx
jae 0x97ba
movl 0x204(%rdi), %r11d
decl %r11d
cmpl %r11d, %r10d
je 0x979a
addq %r9, %rdx
movl 0x44(%rdx), %r8d
movl %r8d, 0x18(%rsi)
cmpl %ecx, %r8d
jbe 0x97ba
movq %rcx, %rax
addq 0x1e8(%rdi), %rax
movq %rax, 0x28(%rsi)
subl %ecx, %r8d
movl %r8d, 0x20(%rsi)
xorl %eax, %eax
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::FindGapStreamEnd(ImageStreamInfo*, int)
int CCapsImageStd::FindGapStreamEnd(PIMAGESTREAMINFO pstr, int next)
{
	uint8_t *buf=di.data;
	int end=0;

	uint32_t ofs;
	for (ofs=pstr->strstart; !end && ofs < pstr->strend; ) {
		int code=buf[ofs++];

		// read code, sizeof(count), count
		int vc=code >> CAPS_SIZE_S;
		code&=CAPS_DATAMASK;
		uint32_t count;

		if (vc) {
			if (ofs+vc > pstr->strend)
				return imgeTrackData;

			count=ReadValue(buf+ofs, vc);
			ofs+=vc;
		} else
			count=0;

		switch (code) {
			// end of stream
			case cpgapEnd:
				end=1;
				break;

			// skip total bitcount setting, already at next element
			case cpgapCount:
				break;

			// add sample data size and go to next element
			case cpgapData:
				ofs += trackbuf.CalculateByteSize(count);
				break;

			// no other data is allowed
			default:
				return imgeTrackStream;
		}
	}

	// no cpgapEnd encountered, stream error
	if (!end)
		return imgeTrackData;

	// update stream start/end position
	if (next)
		pstr->strstart=ofs;
	else
		pstr->strend=ofs;

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

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

	return imgeOk;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, 0x4(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq 0x1e8(%rdi), %r12
movl 0x14(%rsi), %ecx
movb $0x1, %dl
pushq $0xa
popq %rbp
testb $0x1, %dl
je 0x99bd
movl 0x18(%rbx), %edx
cmpl %edx, %ecx
jae 0x99f3
movl %ecx, %eax
incl %ecx
movzbl (%r12,%rax), %r13d
xorl %eax, %eax
cmpl $0x20, %r13d
jb 0x999d
movl %r13d, %esi
shrl $0x5, %esi
leal (%rsi,%rcx), %r15d
cmpl %edx, %r15d
ja 0x99f3
movl %ecx, %edi
addq %r12, %rdi
callq 0xce28
addl $0x7, %eax
shrl $0x3, %eax
movl %r15d, %ecx
xorl %edx, %edx
andl $0x1f, %r13d
je 0x995a
cmpl $0x1, %r13d
je 0x99b9
cmpl $0x2, %r13d
jne 0x99f0
addl %ecx, %eax
movb $0x1, %dl
movl %eax, %ecx
jmp 0x995a
movb $0x1, %dl
jmp 0x995a
cmpl $0x0, 0x4(%rsp)
je 0x99cc
movl %ecx, 0x14(%rbx)
movl 0x18(%rbx), %eax
jmp 0x99d4
movl %ecx, 0x18(%rbx)
movl %ecx, %eax
movl 0x14(%rbx), %ecx
subl %ecx, %eax
jbe 0x99ec
movl %ecx, %ecx
addq 0x1e8(%r14), %rcx
movq %rcx, 0x28(%rbx)
movl %eax, 0x20(%rbx)
xorl %ebp, %ebp
jmp 0x99f3
pushq $0x7
jmp 0x99f2
pushq $0x9
popq %rbp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
pushq $0x1
popq %rbp
cmpl $0x0, 0x3c(%rsi)
jne 0x9ac5
movq %rsi, %rbx
cmpl $0x0, 0x44(%rsi)
je 0x9a9d
cmpl $0x0, 0x4c(%rbx)
je 0x9ad2
movl 0xc(%rbx), %r14d
movl 0x48(%rbx), %r15d
movq %rbx, %rsi
callq 0x9a04
testl %eax, %eax
jne 0x9ac5
cmpl $0x0, 0x3c(%rbx)
jne 0x9ac5
cmpl %r15d, 0x48(%rbx)
jne 0x9ac5
xorl %eax, %eax
cmpl %r14d, 0xc(%rbx)
je 0x9ac7
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl 0x50(%rbx), %eax
movl %eax, 0x54(%rbx)
movl %eax, 0x58(%rbx)
movabsq $0x8000000000, %rax     # imm = 0x8000000000
movq %rax, 0x5c(%rbx)
xorl %eax, %eax
jmp 0x9ac7
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GetSampleRaw(ImageStreamInfo*)
int CCapsImageStd::GetSampleRaw(PIMAGESTREAMINFO pstr)
{
	// check current offset in ipf encoding
	uint32_t ofs=pstr->strofs;

	if (ofs >= pstr->strsize)
		return imgeTrackData;

	// get stream code and sizeof(count)
	uint8_t *buf=pstr->strbase;
	int code=buf[ofs++];

	int vc=code >> CAPS_SIZE_S;
	code&=CAPS_DATAMASK;
	uint32_t count, bitcount;

	// read the value of the count parameter
	if (vc) {
		if (ofs+vc > pstr->strsize)
			return imgeTrackData;

		count=ReadValue(buf+ofs, vc);
		ofs+=vc;
	} else
		count=0;

	switch (code) {
		// stream finished
		case cpdatEnd:
			if (count)
				return imgeTrackData;

			pstr->readend=1;
			bitcount=0;
			break;

		// raw data sample, size in bytes
		case cpdatRaw:
			if (!count)
				return imgeTrackData;

			if (ofs+count > pstr->strsize)
				return imgeTrackData;

			bitcount=count << 3;
			break;

		// any other data type is an error
		default:
			return imgeTrackStream;
	}

	// next offset in ipf stream after the current sample
	pstr->strofs=ofs+count;

	// position of the sample data, left justified, starting at bit#7
	pstr->samplebase=buf+ofs;

	// set all sample counters to a simple countdown for the whole sample
	pstr->samplebc=bitcount;
	pstr->remstreambc=bitcount;
	pstr->remsamplebc=bitcount;

	return imgeOk;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl 0x1c(%rsi), %eax
movl 0x20(%rsi), %ecx
pushq $0xa
popq %rbp
cmpl %ecx, %eax
jae 0x9e4a
movq %rsi, %rbx
movq 0x28(%rsi), %r14
leal 0x1(%rax), %edx
movzbl (%r14,%rax), %r12d
xorl %eax, %eax
cmpl $0x20, %r12d
jae 0x9de3
movl %edx, %r15d
jmp 0x9dfc
movl %r12d, %esi
shrl $0x5, %esi
leal (%rsi,%rdx), %r15d
cmpl %ecx, %r15d
ja 0x9e4a
movl %edx, %edi
addq %r14, %rdi
callq 0xce28
andl $0x1f, %r12d
cmpl $0x4, %r12d
je 0x9e1d
testl %r12d, %r12d
jne 0x9e47
testl %eax, %eax
jne 0x9e4a
movl $0x1, 0x3c(%rbx)
xorl %eax, %eax
movl %r15d, %ecx
jmp 0x9e2d
testl %eax, %eax
je 0x9e4a
leal (%rax,%r15), %ecx
cmpl 0x20(%rbx), %ecx
ja 0x9e4a
shll $0x3, %eax
movl %ecx, 0x1c(%rbx)
movl %r15d, %ecx
addq %rcx, %r14
movq %r14, 0x68(%rbx)
movl %eax, 0x50(%rbx)
movl %eax, 0x54(%rbx)
movl %eax, 0x58(%rbx)
xorl %ebp, %ebp
jmp 0x9e4a
pushq $0x9
popq %rbp
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl %edx, 0x70(%rsi)
movl %ecx, 0x74(%rsi)
movl %r8d, 0x78(%rsi)
movl %r9d, 0x7c(%rsi)
andl $0x0, 0x80(%rsi)
movq %rdi, %r14
pushq $0x2
popq %rbp
pushq $0xe
popq %r15
testl %ecx, %ecx
jle 0x9efb
cmpl $0x0, 0x3c(%rbx)
jne 0x9efb
movl 0x48(%rbx), %eax
cmpl $0x2, %eax
je 0x9eeb
cmpl $0x1, %eax
je 0x9ec4
testl %eax, %eax
je 0x9ede
jmp 0x9efe
movl 0xc(%rbx), %eax
cmpl $0x2, %eax
je 0x9ede
cmpl $0x1, %eax
jne 0x9f0b
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa044
jmp 0x9ef6
movq %r14, %rdi
movq %rbx, %rsi
callq 0x9f10
jmp 0x9ef6
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa218
movl 0x74(%rbx), %ecx
jmp 0x9ea7
movl 0x38(%rbx), %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl %r15d, %ebp
jmp 0x9efe
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::ProcessStreamRaw(ImageStreamInfo*)
void CCapsImageStd::ProcessStreamRaw(PIMAGESTREAMINFO pstr)
{
	// get process state
	uint32_t bitpos=pstr->prcbitpos;
	int maxbc=pstr->prcrembc;
	int skipbc=pstr->prcskipbc;
	int actbc=0;

	// process remaining bits
	while (maxbc > 0) {
		// read the ipf stream
		int readbc=ReadSample(pstr, rawreadlen);

		// number of bits not read/missing
		int diffbc=rawreadlen-readbc;

		// write track data if anything was read
		if (readbc > 0) {
			// number of bits to be written
			int writebc=readbc;

			// skip bits if needed and write bitfield
			if (writebc > skipbc) {
				writebc-=skipbc;
				skipbc=0;

				// get value read
				uint32_t value=pstr->readvalue;

				// if less bits to write than available, right align field to bit#0
				if (writebc > maxbc) {
					value >>= (writebc-maxbc);
					writebc=maxbc;
				}

				trackbuf.WriteBitWrap(bitpos, value, writebc);

				// next write position
				actbc+=writebc;
				maxbc-=writebc;
				bitpos+=writebc;

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

		// stop processing if encoding method changed or stream stopped 
		if (diffbc)
			break;
	}

	// set the type of the very first data
	if (!pstr->prcwritebc && pstr->prcencstate && actbc)
		di.block[pstr->actblock].fdenc=ibieRaw;

	// save process state
	pstr->prcbitpos=bitpos;
	pstr->prcrembc=maxbc;
	pstr->prcskipbc=skipbc;
	pstr->prcwritebc+=actbc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbp
movq %rdi, %r14
movl 0x70(%rsi), %eax
movl %eax, 0x8(%rsp)
movl 0x74(%rsi), %eax
movl %eax, (%rsp)
movl 0x78(%rsi), %esi
leaq 0xb8(%rdi), %rax
movq %rax, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
cmpl $0x0, (%rsp)
jle 0x9fed
movl %esi, %r15d
movl 0x21c(%r14), %edx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x9aee
movl %eax, %r12d
movl 0x21c(%r14), %eax
testl %r12d, %r12d
jle 0x9fd9
movl %r12d, %r13d
subl %r15d, %r13d
jle 0x9fde
movl 0x40(%rbp), %edx
movl %eax, 0xc(%rsp)
xorl %eax, %eax
movl %r13d, %ecx
movl (%rsp), %r15d
subl %r15d, %ecx
cmovgel %r15d, %r13d
cmovlel %eax, %ecx
shrl %cl, %edx
movq 0x10(%rsp), %rdi
movl 0x8(%rsp), %ebx
movl %ebx, %esi
movl %r13d, %ecx
callq 0xaae2
xorl %esi, %esi
addl %r13d, 0x4(%rsp)
subl %r13d, %r15d
movl %r15d, (%rsp)
addl %ebx, %r13d
movl 0x1c0(%r14), %eax
cmpl %eax, %r13d
cmovbl %esi, %eax
subl %eax, %r13d
movl 0xc(%rsp), %eax
movl %r13d, 0x8(%rsp)
jmp 0x9fe4
movl %r15d, %esi
jmp 0x9fe4
movl %r15d, %esi
subl %r12d, %esi
cmpl %r12d, %eax
je 0x9f48
movl 0x80(%rbp), %eax
testl %eax, %eax
jne 0xa01b
cmpl $0x0, 0x7c(%rbp)
je 0xa01b
cmpl $0x0, 0x4(%rsp)
je 0xa01b
movq 0x1f8(%r14), %rcx
movslq 0x4(%rbp), %rdx
imulq $0x28, %rdx, %rdx
movl $0x1, 0x20(%rcx,%rdx)
movl 0x8(%rsp), %ecx
movl %ecx, 0x70(%rbp)
movl (%rsp), %ecx
movl %ecx, 0x74(%rbp)
movl %esi, 0x78(%rbp)
addl 0x4(%rsp), %eax
movl %eax, 0x80(%rbp)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq