LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComReadNoise(CapsFdc*)
int FdcComReadNoise(PCAPSFDC pc)
{
	// clear dsr signals
	pc->aminfo&=~(CAPSFDC_AI_DSRREADY|CAPSFDC_AI_DSRAM|CAPSFDC_AI_DSRMA1);

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

	// all cycles possibly advanced this time
	UDWORD dist=pd->idistance+(pc->clockreq-pc->clockact);

	// next bit complete divident, increased by clockrev
	UQUAD nextccn=(UQUAD)(pc->datalock+1)*pd->clockrev;

	// process until broken
	while (true) {
		// next bit is complete at this disk cycle
		UDWORD nextcyc=UDWORD(nextccn/pd->trackbits);

		// if not enough time to read bit, return
		if (dist < nextcyc) {
			pd->idistance=dist;
			pc->clockact=pc->clockreq;
			return 0;
		}

		// read bit into shifter
		FdcShiftBit(pc);

		// next bit
		pc->datalock++;
		nextccn+=pd->clockrev;

		// if index reached
		if (nextcyc >= pd->clockrev) {
			// adjust to index position
			dist-=pd->clockrev;
			pc->clockact+=pd->clockrev-pd->idistance;
			pd->idistance=0;
			pc->datalock=0;
			nextccn=pd->clockrev;

			// process disk index
			FdcIndex(pc, pc->driveact);

			// we read a complete byte exactly at index, set flag
			if (pc->aminfo & pc->amisigmask)
				return 1;

			// stop on end
			if (pc->endrequest)
				return 0;
		}

		// if a byte is complete, break and signal new byte
		if (pc->aminfo & pc->amisigmask) {
			int dst=pd->idistance;
			pd->idistance=nextcyc;
			pc->clockact+=nextcyc-dst;
			return 1;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
andb $-0x8, 0x61(%rdi)
movq 0x100(%rdi), %rdi
movl 0x10(%rbx), %r12d
addl 0x24(%rdi), %r12d
subl 0xc(%rbx), %r12d
movslq 0x80(%rbx), %rax
incq %rax
movl 0x28(%rdi), %r15d
imulq %rax, %r15
movq %rdi, 0x8(%rsp)
movslq 0x50(%rdi), %rcx
movq %r15, %rax
xorl %edx, %edx
divq %rcx
movq %rax, %r14
cmpl %r14d, %r12d
jae 0x7fe0
movl %r12d, 0x24(%rdi)
movl 0x10(%rbx), %eax
xorl %r8d, %r8d
movq %r15, %rbp
jmp 0x8023
movl %r8d, 0x14(%rsp)
movq %rbx, %rdi
callq 0x8398
movq 0x8(%rsp), %rdi
incl 0x80(%rbx)
movl 0x28(%rdi), %ebp
cmpl %r14d, %ebp
jbe 0x802b
addq %r15, %rbp
movl 0x64(%rbx), %eax
testl %eax, 0x60(%rbx)
movl 0x14(%rsp), %r8d
je 0x8064
movl %r14d, %eax
subl 0x24(%rdi), %eax
movl %r14d, 0x24(%rdi)
addl 0xc(%rbx), %eax
movl $0x1, %r8d
movl %eax, 0xc(%rbx)
xorl %r13d, %r13d
jmp 0x8077
subl %ebp, %r12d
movl 0x24(%rdi), %eax
movl %ebp, %ecx
subl %eax, %ecx
addl %ecx, 0xc(%rbx)
xorl %r13d, %r13d
movl %r13d, 0x24(%rdi)
movl %r13d, 0x80(%rbx)
movl 0xfc(%rbx), %esi
movq %rbx, %rdi
callq 0x7be5
movl 0x64(%rbx), %eax
testl %eax, 0x60(%rbx)
je 0x8069
movl $0x1, %r8d
jmp 0x8072
movb $0x1, %r13b
jmp 0x8077
cmpl $0x0, 0x8(%rbx)
je 0x8085
xorl %r8d, %r8d
movq 0x8(%rsp), %rdi
movq %rbp, %r15
testb %r13b, %r13b
jne 0x7fbd
jmp 0x808f
movq 0x8(%rsp), %rdi
jmp 0x8003
movl %r8d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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:
movq 0x100(%rdi), %rax
movl 0x80(%rdi), %ecx
movq 0x38(%rax), %rax
movl %ecx, %edx
sarl $0x3, %edx
notb %cl
andb $0x7, %cl
movl $0x1, %esi
shll %cl, %esi
movslq %edx, %rcx
movzbl (%rax,%rcx), %eax
andl %esi, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
testq %rdi, %rdi
je 0x86e2
movq (%rdi), %rax
callq *0x10(%rax)
movl %eax, %ebp
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x86d8
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x8(%rbx)
jmp 0x86e4
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movq 0x8(%rdi), %rdi
testq %rdi, %rdi
je 0x8737
movq (%rdi), %rax
callq *0x10(%rax)
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x872f
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x8(%r14)
testq %rbx, %rbx
je 0x877b
testb $0x2, 0x10(%rbx)
jne 0x8786
movl $0x228, %edi            # imm = 0x228
callq 0x4200
movq %rax, %r15
movq %rax, %rdi
callq 0xdef0
movq %r15, 0x8(%r14)
movl 0x10(%rbx), %edx
movl %edx, %eax
andl $0x1, %eax
shrl $0x2, %edx
andl $0x2, %edx
orl %eax, %edx
movq (%rbx), %rsi
movq %r15, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0xdf50
movl $0x1, %eax
popq %rbx
popq %r14
popq %r15
retq
movl $0x48, %edi
callq 0x4200
movq %rax, %r15
movq %rax, %rdi
callq 0xf768
movq %r15, 0x8(%r14)
movl 0x10(%rbx), %ecx
notl %ecx
shrl %ecx
andl $0x2, %ecx
movq 0x8(%rbx), %rsi
movslq 0x14(%rbx), %rdx
movq %r15, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0xf866
movq %rax, %rbx
movl $0x48, %esi
jmp 0x87d0
movq %rax, %rbx
movl $0x228, %esi            # imm = 0x228
movq %r15, %rdi
callq 0x4210
movq %rbx, %rdi
callq 0x43a0
// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
testq %rdi, %rdi
je 0x88b2
movq %rdi, %rbx
btl $0x9, %esi
jae 0x8865
cmpl $0x0, (%rbx)
je 0x8865
movl $0x0, (%rbx)
movl $0xf, %eax
jmp 0x88b7
cmpq $0x0, 0x10(%rbx)
je 0x88b9
movl 0x18(%rbx), %ecx
testl %ecx, %ecx
je 0x88b9
movl 0x1c(%rbx), %edx
testl %edx, %edx
je 0x88b9
movl $0x13, %eax
cmpl %edx, %ecx
ja 0x88b7
movq %rbx, %rdi
callq 0x88c2
testl %eax, %eax
jne 0x88b7
movl 0x18(%rbx), %ecx
movl $0x13, %eax
cmpl 0x20(%rbx), %ecx
jb 0x88b7
movl $0x12, %eax
cmpl %ecx, 0x24(%rbx)
jae 0x88b7
movq %rbx, %rdi
callq 0x8997
xorl %eax, %eax
jmp 0x88b7
movl $0x2, %eax
popq %rbx
retq
movq %rbx, %rdi
popq %rbx
jmp 0x88c2
// File: /workspace/github_cpp_makefile_star2_O1/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:
movl $0x0, 0x20(%rdi)
movl 0x4(%rdi), %ecx
movl 0x28(%rdi), %edx
testq %rdx, %rdx
je 0x88df
cmpq $0x0, 0x2c(%rdi)
je 0x8991
pushq %rbp
pushq %rbx
testl %edx, %edx
setg %sil
jle 0x8981
movq 0x2c(%rdi), %r8
addq $0x30, %r8
movq %rdx, %r9
negq %r9
movl $0x1, %r10d
movl $0x8b, %r11d
addl -0x30(%r8), %ecx
addl -0x28(%r8), %ecx
addl -0x20(%r8), %ecx
addl -0x18(%r8), %ecx
movl -0x10(%r8), %ebx
cmpl $0x2, %ebx
je 0x892d
cmpl $0x1, %ebx
jne 0x8959
addl $0x4, %ecx
movb $0x1, %bpl
jmp 0x8937
movl (%r8), %ebx
addl %ebx, %ecx
addl $0x10, %ecx
xorl %ebp, %ebp
movb $0x1, %bl
testb %bpl, %bpl
jne 0x8960
movl (%r8), %ebp
addl $-0x80, %ebp
roll $0x19, %ebp
cmpl $0x7, %ebp
ja 0x8952
btl %ebp, %r11d
jb 0x8960
movl $0x11, %eax
jmp 0x895e
movl $0x10, %eax
xorl %ebx, %ebx
testb %bl, %bl
je 0x8981
cmpq %rdx, %r10
setb %sil
addq $0x40, %r8
leaq (%r9,%r10), %rbx
incq %rbx
incq %r10
cmpq $0x1, %rbx
jne 0x8907
jmp 0x8981
testb $0x1, %sil
jne 0x898e
addl %ecx, %ecx
movl %ecx, 0x20(%rdi)
xorl %eax, %eax
popq %rbx
popq %rbp
retq
movl $0x2, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl $0x0, 0x34(%rdi)
movl 0x4(%rdi), %ecx
movl 0x8(%rdi), %edx
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x8a3d
cmpl $0x0, 0x28(%rbx)
jle 0x89fe
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x2c(%rbx), %rdx
movl 0x20(%rdx,%r14), %ecx
addq %r14, %rdx
cmpl $0x2, %ecx
je 0x89e4
cmpl $0x1, %ecx
jne 0x89ee
movq %rbx, %rdi
movl %eax, %esi
callq 0x8aad
jmp 0x89ee
movq %rbx, %rdi
movl %eax, %esi
callq 0x8afe
incq %r15
movslq 0x28(%rbx), %rcx
addq $0x40, %r14
cmpq %rcx, %r15
jl 0x89c2
movl 0x18(%rbx), %ecx
subl 0x34(%rbx), %ecx
cmpl $0x2, %ecx
jb 0x8a18
shrl %ecx
movl 0xc(%rbx), %edx
movq %rbx, %rdi
movl %eax, %esi
callq 0x8a3d
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O1/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:
leal (%rcx,%rcx), %eax
addl %eax, 0x34(%rdi)
movl %esi, %eax
movl 0x24(%rdi), %r9d
testl %ecx, %ecx
je 0x8aa5
pushq %rbp
pushq %rbx
movzbl %dl, %edx
leaq 0x12b1f(%rip), %rsi     # 0x1b578
xorl %r8d, %r8d
movq (%rsi), %r10
andl (%r10,%rdx,4), %eax
movl %eax, %r11d
shll $0xf, %r11d
movq 0x10(%rdi), %rbx
movl %r9d, %ebp
incl %r9d
movb %ah, (%rbx,%rbp)
cmpl 0x18(%rdi), %r9d
cmovael %r8d, %r9d
movq 0x10(%rdi), %rbx
leal 0x1(%r9), %r10d
movb %al, (%rbx,%r9)
cmpl 0x18(%rdi), %r10d
cmovael %r8d, %r10d
notl %r11d
movzwl %r11w, %eax
movl %r10d, %r9d
decl %ecx
jne 0x8a5c
popq %rbx
popq %rbp
jmp 0x8aa8
movl %r9d, %r10d
movl %r10d, 0x24(%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rdi, %r14
movl (%rdx), %ecx
movl 0x4(%rdx), %edx
callq 0x8a3d
movq %r14, %rdi
movl $0x5224, %edx           # imm = 0x5224
movl $0x3, %ecx
callq 0x8da3
movq %r14, %rdi
movl %eax, %esi
movl $0xfc, %edx
movl $0x1, %ecx
callq 0x8a3d
movl 0x8(%rbx), %ecx
movl 0xc(%rbx), %edx
movq %r14, %rdi
movl %eax, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x8a3d
// File: /workspace/github_cpp_makefile_star2_O1/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:
leal (%rcx,%rcx), %eax
addl %eax, 0x34(%rdi)
movl 0x24(%rdi), %esi
testl %ecx, %ecx
je 0x8de9
movl %edx, %eax
shrl $0x8, %eax
xorl %r8d, %r8d
movq 0x10(%rdi), %r9
movl %esi, %r10d
incl %esi
movb %al, (%r9,%r10)
cmpl 0x18(%rdi), %esi
cmovael %r8d, %esi
movq 0x10(%rdi), %r10
leal 0x1(%rsi), %r9d
movb %dl, (%r10,%rsi)
cmpl 0x18(%rdi), %r9d
cmovael %r8d, %r9d
movl %r9d, %esi
decl %ecx
jne 0x8db8
jmp 0x8dec
movl %esi, %r9d
shll $0xf, %edx
notl %edx
movzwl %dx, %eax
movl %r9d, 0x24(%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O1/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:
movl %edi, %eax
testl %edx, %edx
je 0x8e1d
movzbl %sil, %ecx
leaq 0x112e6(%rip), %rsi     # 0x1a0f0
movzwl %ax, %edi
shrl $0x8, %edi
xorl %ecx, %edi
shll $0x8, %eax
xorw (%rsi,%rdi,2), %ax
decl %edx
jne 0x8e0a
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movq 0x210(%rdi), %r15
xorl %eax, %eax
xorl %ecx, %ecx
cmpl $0x1, 0x108(%r15)
setne %cl
movl %ecx, 0x28(%r15)
je 0x8e4e
movl 0x110(%r15), %eax
movl %eax, 0x50(%r15)
testl %eax, %eax
je 0x8e70
movslq %eax, %rdi
callq 0x4040
movq %rax, 0x48(%r15)
movslq 0x50(%r15), %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x4140
movq 0x48(%r15), %rax
movq %rax, 0x58(%r15)
xorl %ecx, %ecx
movl %ecx, 0x80(%r15)
movl %ecx, 0x94(%r15)
movq $0x0, 0xbc(%r15)
cmpl %ecx, 0x28(%r15)
je 0x8f06
movl 0xcc(%r15), %r12d
testl %r12d, %r12d
js 0x8eaa
incl %r12d
jmp 0x8eb1
movl 0x128(%r15), %r12d
movl 0xc8(%r15), %ebp
cmpl %r12d, %ebp
setl %r14b
jge 0x8ed3
movq %rbx, %rdi
movl %ebp, %esi
callq 0x8f20
testl %eax, %eax
je 0x8ed7
movl %eax, %ecx
jmp 0x8f01
xorl %ecx, %ecx
jmp 0x8f01
incl %ebp
movl %ebp, %r14d
cmpl %ebp, %r12d
je 0x8ef8
movq %rbx, %rdi
movl %r14d, %esi
callq 0x8f20
leal 0x1(%r14), %ebp
movl %eax, %ecx
testl %eax, %eax
je 0x8ed9
jmp 0x8efa
xorl %ecx, %ecx
cmpl %r12d, %r14d
setl %r14b
testb %r14b, %r14b
jne 0x8f16
movl 0xbc(%r15), %eax
movl %eax, 0x80(%r15)
movl %ecx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl $0x1, %ebx
testl $0x80000002, 0x208(%rdi) # imm = 0x80000002
jne 0x9280
movq %rdi, %r14
movq 0x1e8(%rdi), %rbx
movq 0x210(%rdi), %r12
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x5174
movl 0x24(%r12), %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x5354
movl %eax, %ebx
testl %eax, %eax
je 0x9269
movl $0x1, (%r12)
jmp 0x9276
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x92a6
leaq 0x8(%rsp), %rdi
callq 0x519e
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x519e
movq %rbx, %rdi
callq 0x43a0
// File: /workspace/github_cpp_makefile_star2_O1/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:
cmpl $0x0, 0x110fb(%rip)     # 0x1a544
je 0x944c
retq
pushq %rbx
movl $0x1, 0x110ed(%rip)     # 0x1a544
xorl %eax, %eax
leaq 0x110f0(%rip), %rdx     # 0x1a550
leaq 0x118e9(%rip), %rsi     # 0x1ad50
movb $0x7, %cl
subb %al, %cl
movl $0x1, %edi
shll %cl, %edi
movq %rax, %rcx
shlq $0x8, %rcx
leaq (%rdx,%rcx), %r8
addq %rsi, %rcx
xorl %r9d, %r9d
movl %eax, %r10d
testl %r9d, %edi
je 0x949c
movl %edi, %r11d
movl %eax, %r10d
shrl %r11d
incl %r10d
testl %r9d, %r11d
jne 0x9491
movb %r10b, (%r9,%r8)
movl %eax, %r10d
testl %r9d, %edi
jne 0x94c2
movl %edi, %r11d
movl %eax, %r10d
incl %r10d
cmpl $0x2, %r11d
jb 0x94c2
shrl %r11d
movl %r11d, %ebx
andl %r9d, %ebx
je 0x94ae
movb %r10b, (%r9,%rcx)
incq %r9
cmpq $0x100, %r9             # imm = 0x100
jne 0x9483
incq %rax
cmpq $0x8, %rax
jne 0x9467
popq %rbx
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImage.cpp
// Function: CCapsImage::UpdateDump()
int CCapsImage::UpdateDump()
{
	PDISKTRACKINFO pti = di.pdt;

	// get actual revolution number, restart after the last revolution
	int rev = dii.nextrev % pti->rawtrackcnt;

	// true if all the available revolutions should be returned
	int allrev = (pti->trackcnt == pti->rawtrackcnt);

	// if all revolutions used the used data must be revolution#0
	if (allrev)
		rev = 0;

	// save the real revolution number
	dii.realrev = rev;

	// set data buffer
	pti->trackbuf = pti->trackdata[rev];
	pti->tracklen = allrev ? pti->rawlen : pti->tracksize[rev];
	pti->trackbc = pti->tracklen << 3;
	pti->singletrackbc = pti->trackbc;

	// timing information is the same size as the current data, rev#0 for all revolutions
	pti->timecnt = pti->tracksize[rev];

	// the real size of the sampled timings
	int rawsize = pti->rawtimecnt;

	// the amount of timing to be copied track size or real size - whichever is shorter
	int tsize = std::min(rawsize, pti->timecnt);

	// copy the timing
	memcpy(pti->timebuf, pti->rawtimebuf, tsize*sizeof(UDWORD));

	// If sampled timing is shorter, fill the remaining area with 1000, default value
	// This does not change the average, since the previous data adds up to an average of 1000
	int pos;
	for (pos = tsize; pos < pti->timecnt; pos++) {
			pti->timebuf[pos] = 1000;
	}

	// reset alternate density
	pti->timebuf[pos] = 0;

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

	UpdateImage(rev);

	return imgeOk;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x210(%rdi), %r14
movl 0x3c(%rdi), %eax
movl 0x28(%r14), %ecx
movl 0x2c(%r14), %esi
cltd
idivl %esi
xorl %ebp, %ebp
cmpl %esi, %ecx
cmovnel %edx, %ebp
leaq 0x30(%r14), %rax
movq %rdi, (%rsp)
movl %ebp, 0x44(%rdi)
movslq %ebp, %rcx
movq 0x58(%r14,%rcx,8), %rdx
movq %rdx, 0x48(%r14)
leaq 0x80(%r14,%rcx,4), %rcx
cmovneq %rcx, %rax
movl (%rax), %eax
movl %eax, 0x50(%r14)
shll $0x3, %eax
movl %eax, 0xe8(%r14)
movl %eax, 0xec(%r14)
movl (%rcx), %r12d
movl %r12d, 0xa8(%r14)
movl 0x34(%r14), %r13d
cmpl %r13d, %r12d
movl %r13d, %r15d
cmovll %r12d, %r15d
movq 0xb0(%r14), %rdi
movq 0x38(%r14), %rsi
movslq %r15d, %rbx
leaq (,%rbx,4), %rdx
callq 0x4190
cmpl 0xa8(%r14), %ebx
jge 0x9772
movq 0xb0(%r14), %rax
cmpl %r13d, %r12d
cmovll %r12d, %r13d
movslq %r13d, %rcx
movl %r13d, %r15d
movl $0x3e8, (%rax,%rcx,4)   # imm = 0x3E8
incq %rcx
movslq 0xa8(%r14), %rdx
incl %r15d
cmpq %rdx, %rcx
jl 0x9759
movq 0xb0(%r14), %rax
movslq %r15d, %rcx
movl $0x0, (%rax,%rcx,4)
movq (%rsp), %rbx
testb $0x4, 0x209(%rbx)
je 0x979b
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb398
movq %rbx, %rdi
movl %ebp, %esi
callq 0x9f94
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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:
subq $0x18, %rsp
leaq 0xc(%rsp), %rax
movl %esi, (%rax)
movl %edx, 0x4(%rax)
movl %ecx, 0x8(%rax)
movq 0x210(%rdi), %rdi
movq %rax, %rsi
movl $0x1, %edx
movl $0x140, %ecx            # imm = 0x140
callq 0xf18c
addq $0x18, %rsp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
movq %rdi, %rbx
movabsq $0x2000000020, %rax     # imm = 0x2000000020
movq %rax, 0x218(%rdi)
movl $0x10000, %edi          # imm = 0x10000
callq 0xd600
leaq 0x11c44(%rip), %rax     # 0x1b574
movl (%rax), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
movl %ecx, 0x220(%rbx)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
addl %ecx, %ecx
decb %cl
shll %cl, %edx
notl %eax
movl %eax, 0x224(%rbx)
notl %edx
movl %edx, 0x228(%rbx)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rax
callq *0x18(%rax)
leaq 0xd0(%rbx), %rdi
movq %r14, %rsi
callq 0xcdf6
testl %eax, %eax
je 0x9a87
cmpl $0x1, %eax
je 0x9a80
cmpl $0x2, %eax
jne 0x9ac1
movl $0x6, %eax
jmp 0x9ac6
movl $0x5, %eax
jmp 0x9ac6
movl 0x10(%r14), %eax
notl %eax
andl $0x1, %eax
movl %eax, 0x14(%rbx)
movq %rbx, %rdi
callq 0x9ae2
testl %eax, %eax
jne 0x9ac6
cmpl $0x0, 0x48(%rbx)
je 0x9ace
movl 0x54(%rbx), %ecx
movl 0x50(%rbx), %edx
cmpl $0x2, %edx
je 0x9ad2
movl $0xe, %eax
cmpl $0x1, %edx
jne 0x9ac6
xorl %edx, %edx
cmpl $0x1, %ecx
jmp 0x9adc
movl $0x2, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
xorl %eax, %eax
jmp 0x9ac6
xorl %edx, %edx
cmpl $0x1, %ecx
movl $0xe, %eax
cmovel %edx, %eax
jmp 0x9ac6
nop
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::LoadTrack(DiskTrackInfo*, unsigned int)
int CCapsImageStd::LoadTrack(PDISKTRACKINFO pti, UDWORD flag)
{
	// set lock flags
	di.pdt=pti;
	di.flag=flag;

	int res = imgeOk;

	// update the track image if already available
	if (pti->trackcnt) {
		switch (pti->type) {
			case dtitCapsDump:
				res = UpdateDump();
				break;

			case dtitCapsImage:
				res = UpdateImage(0);
				break;

			default:
				res = imgeGeneric;
				break;
		}

		return res;
	}

	// process stored track data or generate data
	if (pti->datasize) {
		// load data, check data header
		loader.SetPosition(pti->datapos);
		if (loader.ReadChunk() == CCapsLoader::ccidData) {
			// allocate data buffer if needed
			AllocDiskData(pti->datasize);
			di.datacount=pti->datasize;

			// load and decode data
			if (loader.ReadData(di.data) == pti->datasize) {
				switch (pti->type) {
					case dtitCapsDump:
						res=DecompressDump();
						break;

					case dtitCapsImage:
						res=DecodeImage();
						break;

					default:
						res=imgeGeneric;
						break;
				}
			} else
				res=imgeGeneric;
		} else
			res=imgeGeneric;
	} else {
		// generate data
		switch (pti->type) {
			case dtitCapsImage:
				di.datacount=0;
				res=DecodeImage();
				break;

			default:
				res=imgeGeneric;
				break;
		}
	}

	return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, 0x210(%rdi)
movl %edx, 0x208(%rdi)
cmpl $0x0, 0x28(%rsi)
je 0x9ed1
movl (%r14), %eax
cmpl $0x3, %eax
je 0x9f52
movl $0x2, %ebp
cmpl $0x2, %eax
jne 0x9f87
movq (%rbx), %rax
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmpq *0x40(%rax)
cmpl $0x0, 0x24(%r14)
je 0x9f60
leaq 0xd0(%rbx), %r15
movl 0x20(%r14), %esi
movq %r15, %rdi
callq 0xd1e4
movq %r15, %rdi
xorl %esi, %esi
callq 0xce9a
movl $0x2, %ebp
cmpl $0xa, %eax
jne 0x9f87
movl 0x24(%r14), %esi
movq %rbx, %rdi
callq 0xa028
movl 0x24(%r14), %eax
movl %eax, 0x1f4(%rbx)
movq 0x1e8(%rbx), %rsi
movq %r15, %rdi
callq 0xd0fe
cmpl 0x24(%r14), %eax
jne 0x9f87
movl (%r14), %eax
cmpl $0x3, %eax
je 0x9f75
cmpl $0x2, %eax
jne 0x9f87
movq (%rbx), %rax
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmpq *0x38(%rax)
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x9f94
jmp 0x9f87
movl $0x2, %ebp
cmpl $0x3, (%r14)
jne 0x9f87
movl $0x0, 0x1f4(%rbx)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xa07e
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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)
movl 0xe8(%rax), %edx
movl %edx, 0x1c0(%rdi)
movl 0xec(%rax), %eax
movl %eax, 0x1c4(%rdi)
addq $0xb8, %rdi
callq 0x4994
cmpq $0x0, 0x1b8(%r14)
je 0xa01e
cmpl $0x0, 0x1c0(%r14)
je 0xa01e
cmpl $0x0, 0x1c4(%r14)
je 0xa01e
movl 0x208(%r14), %eax
btl $0xd, %eax
jb 0xa01e
btl $0x8, %eax
jae 0xa01e
movq 0x210(%r14), %rax
cmpl $0x0, 0xd0(%rax)
je 0xa01e
movq %r14, %rdi
movl %ebx, %esi
callq 0xa0d4
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 0xa07d
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebp
movq %rdi, %rbx
movq $0x0, 0x1f0(%rdi)
movq 0x1e8(%rdi), %rdi
testq %rdi, %rdi
je 0xa055
callq 0x4280
movq $0x0, 0x1e8(%rbx)
movslq %ebp, %r14
movq %r14, %rdi
callq 0x4040
movq %rax, 0x1e8(%rbx)
movl %r14d, 0x1f0(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 0xa25e
movl %eax, %ebp
testl %eax, %eax
jne 0xa0a8
movl 0x50(%rbx), %eax
decl %eax
movl $0xe, %ebp
cmpl $0x1, %eax
ja 0xa0a8
movq %rbx, %rdi
callq 0xa372
movl %eax, %ebp
testl %ebp, %ebp
je 0xa0ca
movq 0x210(%rbx), %rdi
movl $0x1, %esi
callq 0xe8c0
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_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, 0x4(%rsp)
testb $0x20, 0x209(%rdi)
jne 0xa1ab
movq %rdi, %r14
movq 0x210(%rdi), %rax
movl 0xc4(%rax), %ebx
cmpl $0x0, 0xd0(%rax)
jle 0xa1a5
xorl %ebp, %ebp
movq 0xd8(%rax), %rax
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
movl 0x4(%rsp), %edx
cmpl %edx, (%rax,%rcx,4)
jne 0xa18b
leaq (%rax,%rcx,4), %rax
movl 0x8(%rax), %r13d
testl %r13d, %r13d
jle 0xa18b
movl 0x4(%rax), %r15d
movl %ebx, %eax
shrl $0x16, %eax
xorl %ebx, %eax
andl $0x1, %eax
leal (%rax,%rbx,2), %ebx
movl 0x218(%r14), %r12d
cmpl %r12d, %r13d
cmovll %r13d, %r12d
movq 0xc0(%r14), %rdi
movl 0xcc(%r14), %esi
movl %r15d, %edx
movl %ebx, %ecx
movl %r12d, %r8d
callq 0x4a6a
xorl %ecx, %ecx
addl %r12d, %r15d
movl 0x1c0(%r14), %eax
cmpl %eax, %r15d
cmovbl %ecx, %eax
subl %eax, %r15d
subl %r12d, %r13d
jg 0xa13b
incq %rbp
movq 0x210(%r14), %rax
movslq 0xd0(%rax), %rcx
cmpq %rcx, %rbp
jl 0xa10f
movl %ebx, 0xc4(%rax)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 0xa25c
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x210(%rdi), %rax
movl 0xe4(%rax), %ebp
testl %ebp, %ebp
js 0xa252
movq 0x210(%rbx), %rax
cmpl $0x0, 0x28(%rax)
jle 0xa252
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0xc0(%rbx), %rdi
movl 0xcc(%rbx), %esi
movl %ebp, %edx
movl $0x3, %ecx
callq 0x49a6
notl %eax
movq 0xc0(%rbx), %rdi
movl 0xcc(%rbx), %esi
movl %ebp, %edx
movl %eax, %ecx
movl $0x3, %r8d
callq 0x4a6a
addl 0x1c4(%rbx), %ebp
movl 0x1c0(%rbx), %eax
cmpl %eax, %ebp
cmovbl %r14d, %eax
subl %eax, %ebp
incl %r15d
movq 0x210(%rbx), %rax
cmpl 0x28(%rax), %r15d
jl 0xa1f7
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::InitDecoder()
int CCapsImageStd::InitDecoder()
{
	// stop if image descriptor is not available
	if (!dii.civalid)
		return imgeIncompatible;

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

	int blk;

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

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

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

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

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

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

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

	return imgeOk;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
cmpl $0x0, 0x48(%rdi)
je 0xa35b
movq %rdi, %rbx
movq 0x210(%rdi), %rax
movl 0x128(%rax), %esi
callq 0xb400
movq 0x210(%rbx), %rax
movl 0x128(%rax), %esi
movl %esi, 0x204(%rbx)
testl %esi, %esi
jle 0xa2d4
xorl %r15d, %r15d
xorl %r14d, %r14d
movq 0x1f8(%rbx), %rsi
addq %r15, %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0xb498
testl %eax, %eax
cmovnel %eax, %ebp
jne 0xa364
incq %r14
movslq 0x204(%rbx), %rsi
addq $0x28, %r15
cmpq %rsi, %r14
jl 0xa2a1
xorps %xmm0, %xmm0
movups %xmm0, 0x1c8(%rbx)
testl %esi, %esi
jle 0xa32c
movl 0x1cc(%rbx), %eax
movl 0x1d0(%rbx), %ecx
movq 0x1f8(%rbx), %rdx
movl %esi, %esi
shlq $0x3, %rsi
leaq (%rsi,%rsi,4), %rsi
xorl %edi, %edi
cmpl $0x7, 0x4(%rdx,%rdi)
ja 0xa310
movl $0x0, 0x4(%rdx,%rdi)
addl (%rdx,%rdi), %eax
addl 0x4(%rdx,%rdi), %ecx
addq $0x28, %rdi
cmpq %rdi, %rsi
jne 0xa301
movl %eax, 0x1cc(%rbx)
movl %ecx, 0x1d0(%rbx)
movl 0x1d0(%rbx), %ecx
addl 0x1cc(%rbx), %ecx
movl %ecx, 0x1c8(%rbx)
je 0xa362
movq 0x210(%rbx), %rax
movl 0x118(%rax), %eax
xorl %ebp, %ebp
xorl %edx, %edx
divl %ecx
movl %edx, 0x1d4(%rbx)
jmp 0xa364
movl $0xe, %ebp
jmp 0xa364
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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)
movq $0x0, 0x1dc(%rdi)
movl $0x0, 0x1e4(%rdi)
movl $0x2, %eax
testl %esi, %esi
js 0xa8e0
movl %r8d, %ebx
movl %esi, %ebp
movl %r8d, %esi
orl %ecx, %esi
js 0xa8e0
movq %rdi, %r14
cmpl %ebp, 0x204(%rdi)
jle 0xa8e0
movq 0x210(%r14), %rsi
cmpl %ebp, 0xf4(%rsi)
jle 0xa8e0
movq 0x1f8(%r14), %rax
movl %ebp, %edi
leaq (%rdi,%rdi,4), %r8
movl $0x0, 0x20(%rax,%r8,8)
movl %edx, 0x24(%rax,%r8,8)
movq 0xf8(%rsi), %r15
leaq (%rdi,%rdi,2), %r12
shlq $0x4, %r12
movl (%rax,%r8,8), %esi
movl %esi, (%r15,%r12)
movl 0x4(%rax,%r8,8), %esi
movl %esi, 0x4(%r15,%r12)
movl 0xc(%rax,%r8,8), %esi
movl %esi, 0x28(%r15,%r12)
movl 0x10(%rax,%r8,8), %eax
movl %eax, 0x2c(%r15,%r12)
movl %edx, 0x10(%r15,%r12)
movl %ecx, 0x8(%r15,%r12)
movq %r14, %rdi
movl %ebp, %esi
movl %ecx, %edx
callq 0xc4be
testl %eax, %eax
je 0xa8e9
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
addq %r12, %r15
movl 0x1d8(%r14), %eax
movl %eax, 0x14(%r15)
movl %ebx, 0xc(%r15)
movq %r14, %rdi
movl %ebp, %esi
movl %ebx, %edx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xc538
nop
// File: /workspace/github_cpp_makefile_star2_O1/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:
cmpl $0x0, 0x204(%rdi)
jle 0xa98a
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl $0x24, %r14d
xorl %r15d, %r15d
movq 0x1f8(%rbx), %rax
cmpl $0x2, -0x4(%rax,%r14)
jne 0xa972
movl (%rax,%r14), %esi
movl %esi, %eax
testl %esi, %esi
jne 0xa949
movl 0x1c0(%rbx), %eax
decl %eax
movq 0xc0(%rbx), %rdi
movl %eax, %ecx
shrl $0x3, %ecx
movzbl (%rdi,%rcx), %ecx
notb %al
movzbl %al, %eax
andl $0x7, %eax
btl %eax, %ecx
jae 0xa972
movl $0x1, %edx
callq 0x4c12
incq %r15
movslq 0x204(%rbx), %rax
addq $0x28, %r14
cmpq %rax, %r15
jl 0xa92a
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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:
cmpl $0x0, 0x50(%rsi)
jle 0xa9af
movl $0x10030f01, %eax       # imm = 0x10030F01
xorl %ecx, %ecx
movq 0x48(%rsi), %rdx
movb %al, (%rdx,%rcx)
roll $0x8, %eax
incq %rcx
movslq 0x50(%rsi), %rdx
cmpq %rdx, %rcx
jl 0xa999
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 0xaa6d
leaq 0x7846(%rip), %rcx      # 0x12218
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testb $0x10, %bpl
je 0xaa6d
movq %rbx, %rsi
callq 0xaabc
jmp 0xaa6d
testb $0x4, %bpl
je 0xaa6d
movq %rbx, %rsi
callq 0xaeee
jmp 0xaa6d
testb $0x4, %bpl
je 0xaa6d
movq %rbx, %rsi
callq 0xac50
jmp 0xaa6d
testb $0x4, %bpl
je 0xaa6d
movq %rbx, %rsi
callq 0xad9a
jmp 0xaa6d
testb $0x4, %bpl
je 0xaa6d
movq %rbx, %rsi
callq 0xb112
jmp 0xaa6d
testb $0x8, %bpl
je 0xaa6d
movq %rbx, %rsi
callq 0xabb8
jmp 0xaa6d
testb $0x4, %bpl
je 0xaa6d
movq %rbx, %rsi
callq 0xaf94
jmp 0xaa6d
testb $0x4, %bpl
je 0xaa6d
movq %rbx, %rsi
callq 0xb06c
jmp 0xaa6d
testb $0x4, %bpl
je 0xaa6d
movq %rbx, %rsi
callq 0xb28c
btl $0xa, %ebp
jae 0xaaa1
movq 0xb0(%rbx), %rax
testq %rax, %rax
je 0xaaa1
cmpl $0x0, 0xa8(%rbx)
jle 0xaaa1
xorl %ecx, %ecx
xorl %edx, %edx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
movslq 0xa8(%rbx), %rsi
cmpq %rsi, %rcx
jl 0xaa8c
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
movq %rsi, %rbx
movl 0x50(%rsi), %eax
testl %eax, %eax
je 0xaad9
movl 0x28(%rbx), %ecx
testl %ecx, %ecx
je 0xaad9
cltd
idivl %ecx
movl %eax, 0xa8(%rbx)
jmp 0xaaef
movl 0x110(%rbx), %eax
testl %eax, %eax
movl $0x30d4, %ecx           # imm = 0x30D4
cmovnel %eax, %ecx
movl %ecx, 0xa8(%rbx)
movslq 0xa8(%rbx), %rax
cmpq $-0x1, %rax
leaq 0x4(,%rax,4), %rax
movq $-0x1, %rdi
cmovgeq %rax, %rdi
callq 0x4040
movq %rax, 0xb0(%rbx)
xorl %ecx, %ecx
cmpl $0x0, 0xa8(%rbx)
jle 0xabaa
movl 0xa8(%rbx), %esi
cmpl $0x2, %esi
movl $0x1, %edx
cmovgel %esi, %edx
movl $0xa57eb503, %edi       # imm = 0xA57EB503
xorl %esi, %esi
btl $0x9, %esi
jb 0xab77
movl %esi, %r9d
andl $0x1f, %r9d
movl %esi, %r8d
imulq $0xecf56bf, %r8, %r8    # imm = 0xECF56BF
shrq $0x20, %r8
movl %esi, %r10d
subl %r8d, %r10d
shrl %r10d
addl %r8d, %r10d
shrl $0x6, %r10d
imull $0x79, %r10d, %r8d
subl %esi, %r8d
addl %r9d, %r8d
jmp 0xab93
movl %ecx, %r8d
andl $0x1f, %r8d
movl %ecx, %r9d
imulq %rdi, %r9
shrq $0x26, %r9
imull $0x63, %r9d, %r9d
subl %r9d, %r8d
addl %esi, %r8d
addl $0x3e8, %r8d            # imm = 0x3E8
movl %r8d, (%rax,%rsi,4)
incq %rsi
incl %ecx
cmpq %rsi, %rdx
jne 0xab40
jmp 0xabac
xorl %esi, %esi
movl $0x0, (%rax,%rsi,4)
xorl %eax, %eax
popq %rbx
retq
nop