LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::ProcessStreamWeak(ImageStreamInfo*)
void CCapsImageStd::ProcessStreamWeak(PIMAGESTREAMINFO pstr)
{
	// get process state
	uint32_t bitpos=pstr->prcbitpos;
	int maxbc=pstr->prcrembc;
	int skipbc=pstr->prcskipbc;
	int actbc=0;
		
	// process remaining bits
	if (maxbc > 0) {
		// get weak field size without encoding
		int writebc=pstr->remstreambc;

		// skip reading the sample associated with this field and get the next sample
		ReadSampleInit(pstr);

		// calculate field size after encoding
		switch (pstr->actenctype) {
			case cpencMFM:
				writebc <<= 1;
				break;
		}

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

			// limit to available bit size
			if (writebc > maxbc)
				writebc=maxbc;

			// mark weak data, use group#0 for IPF image
			DiskDataMark ddm;
			ddm.group = 0;
			ddm.position=bitpos;
			ddm.size=writebc;
			AddFD(di.pdt, &ddm, 1, DEF_FDALLOC);

			// clear field
			trackbuf.ClearBitWrap(bitpos, 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;
	}

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

	// 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, %rbx
movl 0x70(%rsi), %ebp
movl 0x74(%rsi), %r12d
movl 0x78(%rsi), %r13d
xorl %r14d, %r14d
testl %r12d, %r12d
jle 0xa2c6
movl 0x54(%rbx), %r15d
movq %rdi, (%rsp)
movq %rbx, %rsi
callq 0x9a7e
cmpl $0x1, 0xc(%rbx)
sete %cl
shll %cl, %r15d
movl %r15d, %r14d
subl %r13d, %r14d
jle 0xa2bc
cmpl %r12d, %r14d
cmovgel %r12d, %r14d
leaq 0xc(%rsp), %rsi
andl $0x0, (%rsi)
movl %ebp, 0x4(%rsi)
movl %r14d, 0x8(%rsi)
movq (%rsp), %r15
movq 0x210(%r15), %rdi
pushq $0x1
popq %rdx
pushq $0x8
popq %rcx
callq 0xce3e
leaq 0xb8(%r15), %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0xab0c
subl %r14d, %r12d
addl %r14d, %ebp
movl 0x1c0(%r15), %eax
xorl %r13d, %r13d
cmpl %eax, %ebp
cmovbl %r13d, %eax
subl %eax, %ebp
movq %r15, %rdi
jmp 0xa2c6
subl %r15d, %r13d
movq (%rsp), %rdi
xorl %r14d, %r14d
movl 0x80(%rbx), %eax
testl %eax, %eax
jne 0xa2f2
testl %r14d, %r14d
je 0xa2f2
cmpl $0x0, 0x7c(%rbx)
je 0xa2f2
movq 0x1f8(%rdi), %rcx
movslq 0x4(%rbx), %rdx
imulq $0x28, %rdx, %rdx
movl $0x3, 0x20(%rcx,%rdx)
movl %ebp, 0x70(%rbx)
movl %r12d, 0x74(%rbx)
movl %r13d, 0x78(%rbx)
addl %r14d, %eax
movl %eax, 0x80(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
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::CalculateStreamSize(ImageStreamInfo*)
int CCapsImageStd::CalculateStreamSize(PIMAGESTREAMINFO pstr)
{
	// find loop point and loop type
	int res=FindLoopPoint(pstr);
	if (res != imgeOk)
		return res;

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

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

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

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

			default:
				return imgeGeneric;
		}

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

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

	return imgeOk;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %rbx
movq %rdi, %r14
callq 0xa3f8
movl %eax, %ebp
testl %eax, %eax
jne 0xa3e3
movq %rsp, %r15
movl $0xa8, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3160
xorl %r12d, %r12d
pushq $0x2
popq %rbp
xorl %r13d, %r13d
cmpl $0x0, 0x3c(%rsp)
jne 0xa3d3
movl 0x8c(%rsp), %eax
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jae 0xa3a2
movl 0x54(%rsp), %eax
movl 0x48(%rsp), %ecx
decl %ecx
cmpl $0x2, %ecx
setb %dl
cmpl $0x1, 0xc(%rsp)
sete %cl
andb %dl, %cl
shll %cl, %eax
movl 0x1c(%rsp), %edx
cmpl 0x84(%rsp), %edx
jne 0xa3bf
movl 0x50(%rsp), %edx
shll %cl, %edx
addl %edx, %r13d
jmp 0xa3bf
testl %eax, %eax
jne 0xa3e3
movl 0x48(%rsp), %ecx
movl 0x54(%rsp), %eax
decl %ecx
cmpl $0x1, %ecx
ja 0xa3bf
cmpl $0x1, 0xc(%rsp)
sete %cl
shll %cl, %eax
addl %eax, %r12d
movq %r14, %rdi
movq %r15, %rsi
callq 0x9a04
testl %eax, %eax
je 0xa358
jmp 0xa3e3
movl %r12d, 0x90(%rbx)
movl %r13d, 0x94(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
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::FindLoopPoint(ImageStreamInfo*)
int CCapsImageStd::FindLoopPoint(PIMAGESTREAMINFO pstr)
{
	// no loop point if sample looping is not allowed
	if (!pstr->allowloop) {
		pstr->loopofs=0;
		pstr->loopsize=0;
		pstr->looptype=isiltNone;
		return imgeOk;
	}

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

	// no loop point
	uint32_t loopofs=0;
	int loopsize=0, loopfound=0, cnt=0;

	while (!isi.readend) {
		uint32_t ofs=isi.strofs;
		int bc=isi.samplebc;

		switch (isi.strtype) {
			// loop point is the last data in forward gap stream; any data after a loop is invalid
			case isitGap0:
				if (loopfound)
					return imgeGeneric;

				loopofs=ofs;
				loopsize=bc;
				break;

			// loop point is the first data in backward gap stream; any loop after first data is invalid
			case isitGap1:
				if (!cnt) {
					loopofs=ofs;
					loopsize=bc;
				} else
					if (!isi.streambc)
						return imgeGeneric;
				break;
		}

		// only allow 1 loop
		if (!isi.streambc) {
			if (loopfound)
				return imgeGeneric;

			loopfound++;
		}

		cnt++;

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

	// set loop point information
	pstr->loopofs=loopofs;
	pstr->loopsize=loopsize;

	if (loopsize)
		pstr->looptype=loopfound ? isiltStream : isiltAuto;
	else
		pstr->looptype=isiltNone;

	return imgeOk;
}

// Assembly:
cmpl $0x0, 0x44(%rsi)
je 0xa4a6
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %r14
leaq 0x10(%rsp), %r15
movl $0xa8, %edx
movq %r15, %rdi
movq %rsi, 0x8(%rsp)
callq 0x3160
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %ebx, %ebx
cmpl $0x0, 0x4c(%rsp)
jne 0xa4b8
movl 0x10(%rsp), %edx
movl 0x2c(%rsp), %eax
movl 0x60(%rsp), %ecx
cmpl $0x1, %edx
je 0xa463
cmpl $0x2, %edx
jne 0xa479
movl 0x5c(%rsp), %edx
testl %r12d, %r12d
je 0xa47f
testl %edx, %edx
jne 0xa48f
jmp 0xa4a1
testl %ebp, %ebp
jne 0xa4a1
xorl %ebp, %ebp
cmpl $0x0, 0x5c(%rsp)
sete %bpl
movl %eax, %ebx
movl %ecx, %r13d
jmp 0xa48f
movl 0x5c(%rsp), %edx
jmp 0xa484
movl %ecx, %r13d
movl %eax, %ebx
testl %edx, %edx
jne 0xa48f
testl %ebp, %ebp
pushq $0x1
popq %rbp
jne 0xa4a1
movq %r14, %rdi
movq %r15, %rsi
callq 0x9a04
decl %r12d
testl %eax, %eax
je 0xa437
pushq $0x2
popq %rax
jmp 0xa4e2
andq $0x0, 0x84(%rsi)
andl $0x0, 0x8c(%rsi)
xorl %eax, %eax
retq
movq 0x8(%rsp), %rcx
movl %ebx, 0x84(%rcx)
movl %r13d, 0x88(%rcx)
cmpl $0x1, %ebp
pushq $0x2
popq %rax
sbbl $0x0, %eax
testl %r13d, %r13d
cmovel %r13d, %eax
movl %eax, 0x8c(%rcx)
xorl %eax, %eax
addq $0xb8, %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::ProcessBlockData(int, int)
int CCapsImageStd::ProcessBlockData(int blk, int datasize)
{
	// stop if no data area
	if (!datasize)
		return imgeOk;

	int res;
	ImageStreamInfo dsi;

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

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

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

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

	return imgeOk;
}

// Assembly:
testl %edx, %edx
je 0xa576
pushq %r14
pushq %rbx
subq $0xa8, %rsp
movl %edx, %ebx
movl %esi, %ecx
movq %rdi, %r14
movq %rsp, %rsi
xorl %edx, %edx
callq 0x96cc
testl %eax, %eax
jne 0xa57c
movl 0x1d8(%r14), %edx
xorl %r9d, %r9d
cmpl $0x0, 0x1dc(%r14)
sete %r9b
movq %rsp, %rsi
movq %r14, %rdi
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x9e7e
testl %eax, %eax
jne 0xa57c
cmpl %ebx, 0x80(%rsp)
jne 0xa579
movl 0x70(%rsp), %eax
movl %eax, 0x1d8(%r14)
addl %ebx, 0x1dc(%r14)
xorl %eax, %eax
jmp 0xa57c
xorl %eax, %eax
retq
pushq $0x2
popq %rax
addq $0xa8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::ProcessBlockGap(ImageStreamInfo*, int)
int CCapsImageStd::ProcessBlockGap(PIMAGESTREAMINFO pg, int gapsize)
{
	// stop if no gap area
	if (!gapsize)
		return imgeOk;

	int skip=0;

	if (pg->esfixbc >= gapsize) {
		// fixed size is enough to fill the gap; disable loop
		SetLoop(pg, 0);

		// if backwards stream, skip unneeded bits
		if (pg->strtype == isitGap1)
			skip=pg->esfixbc-gapsize;
	} else {
		// loop required to fill the gap; error if loop point is not found
		if (!pg->esloopbc)
			return imgeGeneric;

		// number of bits to be generated using the loop
		int miss=gapsize-pg->esfixbc;

		// number of new samples required to generate the bits
		int scnt=miss/pg->esloopbc;

		// partial new sample size, 0 if all samples are complete
		int smod=miss%pg->esloopbc;

		// if partial sample is required
		if (smod) {
			// add another sample
			scnt++;

			// if backwards stream, skip bits not required from the added sample
			if (pg->strtype == isitGap1)
				skip=pg->esloopbc-smod;
		}

		// enable loop
		SetLoop(pg, scnt);
	}

	// encode gap data
	int res=ProcessStream(pg, di.encbitpos, gapsize, skip, !di.encwritebc);
	if (res != imgeOk)
		return res;

	// error if the requested data size was not filled
	if (pg->prcwritebc != gapsize)
		return imgeGeneric;

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

	if (pg->strtype == isitGap0)
		di.pdt->sip[pg->actblock].gapsizews0=gapsize;
	else
		di.pdt->sip[pg->actblock].gapsizews1=gapsize;

	return imgeOk;
}

// Assembly:
xorl %eax, %eax
testl %edx, %edx
je 0xa7f8
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
movl %edx, %eax
pushq $0x2
popq %r12
subl 0x90(%rsi), %eax
jle 0xa755
movl 0x94(%r14), %ecx
testl %ecx, %ecx
je 0xa772
cltd
idivl %ecx
testl %edx, %edx
je 0xa777
incl %eax
subl %edx, %ecx
xorl %ebp, %ebp
cmpl $0x2, (%r14)
cmovel %ecx, %ebp
jmp 0xa779
xorl %ebp, %ebp
movq %r14, %rsi
xorl %edx, %edx
callq 0xa9ce
cmpl $0x2, (%r14)
jne 0xa783
movl 0x90(%r14), %ebp
subl %ebx, %ebp
jmp 0xa783
movl %r12d, %eax
jmp 0xa7f0
xorl %ebp, %ebp
movq %r14, %rsi
movl %eax, %edx
callq 0xa9ce
movl 0x1d8(%r15), %edx
xorl %r9d, %r9d
cmpl $0x0, 0x1dc(%r15)
sete %r9b
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %ecx
movl %ebp, %r8d
callq 0x9e7e
testl %eax, %eax
jne 0xa7f0
movl %r12d, %eax
cmpl %ebx, 0x80(%r14)
jne 0xa7f0
movl 0x70(%r14), %eax
movl %eax, 0x1d8(%r15)
addl %ebx, 0x1dc(%r15)
xorl %eax, %eax
cmpl $0x1, (%r14)
setne %al
movq 0x210(%r15), %rcx
movslq 0x4(%r14), %rdx
imulq $0x30, %rdx, %rdx
addq 0xf8(%rcx), %rdx
movl %ebx, 0x18(%rdx,%rax,4)
xorl %eax, %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::ProcessBlockGap(ImageStreamInfo*, ImageStreamInfo*, int, int)
int CCapsImageStd::ProcessBlockGap(PIMAGESTREAMINFO pg0, PIMAGESTREAMINFO pg1, int gapsize, int loopsel)
{
	int gs0=pg0->esfixbc;
	int gs1=pg1->esfixbc;

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

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

		gs0=gapsize-gs1;
	}

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

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

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

	return imgeOk;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %ecx, %ebx
movq %rdx, %r14
movq %rdi, %r15
testl %r8d, %r8d
je 0xa81d
movl 0x90(%rsi), %edx
cmpl %ebx, %edx
cmovgel %ebx, %edx
subl %edx, %ebx
jmp 0xa82f
movl 0x90(%r14), %eax
cmpl %ebx, %eax
cmovgel %ebx, %eax
subl %eax, %ebx
movl %ebx, %edx
movl %eax, %ebx
movq %r15, %rdi
callq 0xa70c
movl %eax, %ebp
testl %eax, %eax
jne 0xa863
movl $0x1, 0x1e0(%r15)
movl 0x1d8(%r15), %eax
movl %eax, 0x1e4(%r15)
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0xa70c
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsLoader.cpp
// Function: CCapsLoader::Unlock()
void CCapsLoader::Unlock()
{
	file.Close();
	flen=0;
	chunk.type=ccidUnknown;
	readmode=true;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
addq $0x10, %rdi
callq 0x6f3a
andl $0x0, 0x20(%rbx)
movl $0x7, 0x84(%rbx)
movl $0x1, 0x8(%rbx)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsLoader.cpp
// Function: CCapsLoader::Lock(CapsFile*)
int CCapsLoader::Lock(PCAPSFILE pcf)
{
	// close previous file
	Unlock();

	// open file
	if (file.Open(pcf)) {
		Unlock();
		return ccidErrFile;
	}

	// set read mode
	readmode=(pcf->flag & CFF_WRITE) ? false : true;

	// get file size, no file skip
	flen=file.GetSize();

	// check for caps id
	if (ReadChunk(true) != ccidFile) {
		Unlock();
		return ccidErrType;
	}

	return ccidCaps;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %rbx
callq 0xae22
leaq 0x10(%rbx), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x6f88
testl %eax, %eax
je 0xaeaf
pushq $0x1
jmp 0xaeda
movl 0x10(%r15), %eax
notl %eax
andl $0x1, %eax
movl %eax, 0x8(%rbx)
movq %r14, %rdi
callq 0x707e
movl %eax, 0x20(%rbx)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xaef0
xorl %ebp, %ebp
cmpl $0x8, %eax
je 0xaee3
pushq $0x2
popq %rbp
movq %rbx, %rdi
callq 0xae22
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsLoader.cpp
// Function: CCapsLoader::SkipData()
int CCapsLoader::SkipData()
{
	// handle file error
	if (!file.IsOpen())
		return 0;

	// do not skip next time, clear type
	int type=chunk.type;
	chunk.type=ccidUnknown;

	// skip only data area
	if (type != ccidData)
		return 0;

	// do not skip empty area
	int skip=chunk.cg.mod.data.size;
	if (!skip)
		return 0;

	// correct skip size if image is short
	int pos=file.GetPosition();
	if (flen-pos < skip)
		skip=flen-pos;

	// seek to new chunk
	file.Seek(skip, 0);
	return skip;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %r15
leaq 0x10(%rdi), %r14
movq %r14, %rdi
callq 0x7076
xorl %ebx, %ebx
testl %eax, %eax
je 0xb0ad
movl 0x84(%r15), %eax
movl $0x7, 0x84(%r15)
cmpl $0xa, %eax
jne 0xb0ad
movl 0x94(%r15), %ebp
testl %ebp, %ebp
je 0xb0ad
movq %r14, %rdi
callq 0x7088
movl 0x20(%r15), %ebx
subl %eax, %ebx
cmpl %ebp, %ebx
cmovgel %ebp, %ebx
movq %r14, %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0x705c
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsLoader.cpp
// Function: CCapsLoader::GetChunkType(CapsChunk*)
int CCapsLoader::GetChunkType(PCAPSCHUNK pc)
{
	int pos;

	for (pos=0; chunklist[pos].name; pos++)
		if (!memcmp(chunklist[pos].name, pc->cg.file.name, sizeof(pc->cg.file.name)))
			break;

	return pc->type=chunklist[pos].type;
}

// Assembly:
leaq 0x4(%rdi), %rax
leaq 0xc533(%rip), %rdx      # 0x175f8
movq %rdx, %rcx
movq -0x8(%rdx), %rdx
testq %rdx, %rdx
je 0xb0db
movl (%rdx), %esi
leaq 0x10(%rcx), %rdx
cmpl (%rax), %esi
jne 0xb0c5
movl (%rcx), %eax
movl %eax, (%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsLoader.cpp
// Function: CCapsLoader::Swap(unsigned int*, int)
void CCapsLoader::Swap(PUDWORD buf, int cnt)
{
#ifdef INTEL
	for (cnt>>=2; cnt > 0; cnt--, buf++) {
		UDWORD src=*buf;
		UDWORD dst=_lrotl(src, 8)&0x00ff00ff | _lrotr(src, 8)&0xff00ff00;
		*buf=dst;
	}
#endif
}

// Assembly:
sarl $0x2, %esi
testl %esi, %esi
jle 0xb0f5
movl (%rdi), %eax
bswapl %eax
movl %eax, (%rdi)
decl %esi
addq $0x4, %rdi
jmp 0xb0e3
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsLoader.cpp
// Function: CCapsLoader::ReadData(unsigned char*)
int CCapsLoader::ReadData(PUBYTE buf)
{
	// handle file error
	if (!file.IsOpen())
		return 0;

	// do not read next time, clear type
	int type=chunk.type;
	chunk.type=ccidUnknown;

	// skip only data area
	if (type != ccidData)
		return 0;

	// do not skip empty area
	int size=chunk.cg.mod.data.size;
	if (!size)
		return 0;

	// correct and skip size if image is short
	int pos=file.GetPosition();
	if (flen-pos < size) {
		size=flen-pos;

		// seek to new chunk
		file.Seek(size, 0);
		return 0;
	}

	// read data area
	if (file.Read(buf, size) != size)
		return 0;

	// check data CRC if available
	if (chunk.cg.mod.data.dcrc)
		if (chunk.cg.mod.data.dcrc != CalcCRC(buf, size))
			return 0;

	return size;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq 0x10(%rdi), %r12
movq %r12, %rdi
callq 0x7076
xorl %ebx, %ebx
testl %eax, %eax
je 0xb186
movl 0x84(%r15), %eax
movl $0x7, 0x84(%r15)
cmpl $0xa, %eax
jne 0xb186
movl 0x94(%r15), %ebp
testl %ebp, %ebp
je 0xb186
movq %r12, %rdi
callq 0x7088
movl 0x20(%r15), %esi
subl %eax, %esi
cmpl %ebp, %esi
jge 0xb158
xorl %ebx, %ebx
movq %r12, %rdi
xorl %edx, %edx
callq 0x705c
jmp 0xb186
movq %r12, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x703c
cmpl %ebp, %eax
jne 0xb186
movl 0x9c(%r15), %r15d
testl %r15d, %r15d
je 0xb184
movq %r14, %rdi
movl %ebp, %esi
callq 0x3f42
cmpl %eax, %r15d
jne 0xb186
movl %ebp, %ebx
movl %ebx, %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/CapsLoader.cpp
// Function: CCapsLoader::SetPosition(int)
int CCapsLoader::SetPosition(int pos)
{
	// handle file error
	if (!file.IsOpen())
		return 0;

	// chunk type unknown after seek
	chunk.type=ccidUnknown;

	// keep file boundaries
	if (pos < 0)
		pos=0;
	else
		if (flen < pos)
			pos=flen;

	// seek
	file.Seek(pos, -1);

	return pos;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebp
movq %rdi, %r14
leaq 0x10(%rdi), %rbx
movq %rbx, %rdi
callq 0x7076
testl %eax, %eax
je 0xb222
movl $0x7, 0x84(%r14)
movl 0x20(%r14), %eax
cmpl %ebp, %eax
cmovgel %ebp, %eax
xorl %r14d, %r14d
testl %ebp, %ebp
cmovnsl %eax, %r14d
pushq $-0x1
popq %rdx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x705c
jmp 0xb225
xorl %r14d, %r14d
movl %r14d, %eax
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsLoader.cpp
// Function: CCapsLoader::ConvertChunk(CapsChunk*)
void CCapsLoader::ConvertChunk(PCAPSCHUNK pc)
{
	if (!pc)
		return;

	// set complete chunk to network byte order
	int ofs=sizeof(pc->cg.file.name);
	int size=pc->cg.file.size;
	Swap(PUDWORD((PUBYTE)&pc->cg.file+ofs), size-ofs);

	// calculate crc and set to network byte order
	pc->cg.file.hcrc=0;
	pc->cg.file.hcrc=CalcCRC((PUBYTE)&pc->cg.file, size);
	CCapsLoader::Swap(&pc->cg.file.hcrc, sizeof(pc->cg.file.hcrc));
}

// Assembly:
testq %rdi, %rdi
je 0xb27f
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x4(%rdi), %r14
addq $0x8, %rdi
movl 0x8(%rbx), %r15d
leal -0x4(%r15), %esi
callq 0xb0e0
leaq 0xc(%rbx), %r12
andl $0x0, 0xc(%rbx)
movq %r14, %rdi
movl %r15d, %esi
callq 0x3f42
movl %eax, 0xc(%rbx)
pushq $0x4
popq %rsi
movq %r12, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xb0e0
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Codec/DiskEncoding.cpp
// Function: CDiskEncoding::~CDiskEncoding()
CDiskEncoding::~CDiskEncoding()
{
	delete [] fmcode;
	delete [] fmdecode;

	delete [] mfmcode;
	delete [] mfmdecode;

	delete [] gcrcode;
	delete [] gcrdecode;

	delete [] gcrcode_s;
	delete [] gcrdecode_s;

	delete [] gcrahcode;
	delete [] gcrahdecode;

	delete [] gcra5code;
	delete [] gcra5decode;

	delete [] gcra6code;
	delete [] gcra6decode;

	delete [] gcrvorpalcode;
	delete [] gcrvorpaldecode;

	delete [] gcrvorpal2code;
	delete [] gcrvorpal2decode;

	delete [] gcrvmaxcode;
	delete [] gcrvmaxdecode;

	delete [] gcr4bitcode;
	delete [] gcr4bitdecode;

	Clear();
}

// Assembly:
pushq %rax
leaq 0xb8e4(%rip), %rax      # 0x16b78
movq %rax, (%rdi)
movq 0xe2c2(%rip), %rdi      # 0x19560
testq %rdi, %rdi
je 0xb2a8
callq 0x3250
movq 0xe2b9(%rip), %rdi      # 0x19568
testq %rdi, %rdi
je 0xb2b9
callq 0x3250
movq 0xe2b8(%rip), %rdi      # 0x19578
testq %rdi, %rdi
je 0xb2ca
callq 0x3250
movq 0xe2af(%rip), %rdi      # 0x19580
testq %rdi, %rdi
je 0xb2db
callq 0x3250
movq 0xe2ae(%rip), %rdi      # 0x19590
testq %rdi, %rdi
je 0xb2ec
callq 0x3250
movq 0xe2a5(%rip), %rdi      # 0x19598
testq %rdi, %rdi
je 0xb2fd
callq 0x3250
movq 0xe2a4(%rip), %rdi      # 0x195a8
testq %rdi, %rdi
je 0xb30e
callq 0x3250
movq 0xe29b(%rip), %rdi      # 0x195b0
testq %rdi, %rdi
je 0xb31f
callq 0x3250
movq 0xe29a(%rip), %rdi      # 0x195c0
testq %rdi, %rdi
je 0xb330
callq 0x3250
movq 0xe291(%rip), %rdi      # 0x195c8
testq %rdi, %rdi
je 0xb341
callq 0x3250
movq 0xe290(%rip), %rdi      # 0x195d8
testq %rdi, %rdi
je 0xb352
callq 0x3250
movq 0xe287(%rip), %rdi      # 0x195e0
testq %rdi, %rdi
je 0xb363
callq 0x3250
movq 0xe286(%rip), %rdi      # 0x195f0
testq %rdi, %rdi
je 0xb374
callq 0x3250
movq 0xe27d(%rip), %rdi      # 0x195f8
testq %rdi, %rdi
je 0xb385
callq 0x3250
movq 0xe27c(%rip), %rdi      # 0x19608
testq %rdi, %rdi
je 0xb396
callq 0x3250
movq 0xe273(%rip), %rdi      # 0x19610
testq %rdi, %rdi
je 0xb3a7
callq 0x3250
movq 0xe272(%rip), %rdi      # 0x19620
testq %rdi, %rdi
je 0xb3b8
callq 0x3250
movq 0xe269(%rip), %rdi      # 0x19628
testq %rdi, %rdi
je 0xb3c9
callq 0x3250
movq 0xe268(%rip), %rdi      # 0x19638
testq %rdi, %rdi
je 0xb3da
callq 0x3250
movq 0xe25f(%rip), %rdi      # 0x19640
testq %rdi, %rdi
je 0xb3eb
callq 0x3250
movq 0xe25e(%rip), %rdi      # 0x19650
testq %rdi, %rdi
je 0xb3fc
callq 0x3250
movq 0xe255(%rip), %rdi      # 0x19658
testq %rdi, %rdi
je 0xb40d
callq 0x3250
popq %rax
jmp 0xb414
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Codec/DiskEncoding.cpp
// Function: CDiskEncoding::InitFM()
void CDiskEncoding::InitFM()
{
	// stop if correct tables are available
	if (fminit)
		return;

	// create tables
	if (!fmcode)
		fmcode=new uint32_t[256];

	if (!fmdecode)
		fmdecode=new uint32_t[65536];

	uint32_t sval;

	// create FM word code table
	for (sval=0x0000; sval < 256; sval++) {
		uint32_t code=0;

		// generate clock and data bits
		for (uint32_t bit=0x80; bit; bit>>=1) {
			code<<=2;

			// always set clock to 1, and add data
			code|=(sval & bit) ? 3 : 2;
		}

		// store encoding
		fmcode[sval]=code;
	}

	// create FM decode table
	for (sval=0x0000; sval < 0x10000; sval++) {
		uint32_t code=0;

		// all bits
		for (uint32_t bit=0x4000; bit; bit>>=2) {
			code<<=1;
			if (sval & bit)
				code|=1;
		}

		// store decoding, mark coding erros
		uint32_t cd=fmcode[code] & 0xffff;
		if (cd != sval)
			code|=DF_31;
		fmdecode[sval]=code;
	}

	fminit=1;
}

// Assembly:
cmpl $0x0, 0xe025(%rip)      # 0x1955c
je 0xb53a
retq
pushq %rbx
movq 0xe01e(%rip), %rbx      # 0x19560
testq %rbx, %rbx
jne 0xb55b
movl $0x400, %edi            # imm = 0x400
callq 0x3040
movq %rax, %rbx
movq %rax, 0xe005(%rip)      # 0x19560
movq 0xe006(%rip), %rax      # 0x19568
testq %rax, %rax
jne 0xb578
movl $0x40000, %edi          # imm = 0x40000
callq 0x3040
movq %rax, 0xdff0(%rip)      # 0x19568
xorl %ecx, %ecx
pushq $0x3
popq %rdx
cmpq $0x100, %rcx            # imm = 0x100
je 0xb5b2
movl $0x80, %edi
xorl %esi, %esi
testl %edi, %edi
je 0xb5aa
movl %edi, %r8d
andl %ecx, %r8d
cmpl $0x1, %r8d
movl %edx, %r8d
sbbl $0x0, %r8d
leal (%r8,%rsi,4), %esi
shrl %edi
jmp 0xb58d
movl %esi, (%rbx,%rcx,4)
incq %rcx
jmp 0xb57d
xorl %ecx, %ecx
cmpq $0x10000, %rcx          # imm = 0x10000
je 0xb5f4
movl $0x4000, %esi           # imm = 0x4000
xorl %edx, %edx
testl %esi, %esi
je 0xb5d8
xorl %edi, %edi
testl %ecx, %esi
setne %dil
leal (%rdi,%rdx,2), %edx
shrl $0x2, %esi
jmp 0xb5c4
movl %edx, %esi
movzwl (%rbx,%rsi,4), %esi
movl %edx, %edi
orl $0x80000000, %edi       # imm = 0x80000000
cmpq %rsi, %rcx
cmovel %edx, %edi
movl %edi, (%rax,%rcx,4)
incq %rcx
jmp 0xb5b4
movl $0x1, 0xdf5e(%rip)      # 0x1955c
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Codec/DiskEncoding.cpp
// Function: CDiskEncoding::InitGCRCBM(unsigned int*, int)
void CDiskEncoding::InitGCRCBM(uint32_t *gcrtable, int gcrid)
{
	// cancel if table initialized with the same gcr version
	if (gcrid == gcrinit)
		return;

	// create tables
	if (!gcrcode)
		gcrcode=new uint32_t[256];

	if (!gcrdecode)
		gcrdecode=new uint32_t[1024];

	uint32_t sval;

	// set GCR decode table to coding error as default
	for (sval=0; sval < 1024; sval++)
		gcrdecode[sval]=DF_31;

	// create GCR table
	for (sval=0; sval < 256; sval++) {
		uint32_t ghi=gcrtable[sval >> 4];
		uint32_t glo=gcrtable[sval & 0xf];
		uint32_t code=ghi << 5 | glo;
		gcrcode[sval]=code;
		gcrdecode[code]=sval;
	}

	gcrinit=gcrid;
}

// Assembly:
cmpl %esi, 0xde0e(%rip)      # 0x19588
je 0xb815
pushq %r15
pushq %r14
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
movq 0xddff(%rip), %r15      # 0x19590
testq %r15, %r15
jne 0xb7aa
movl $0x400, %edi            # imm = 0x400
callq 0x3040
movq %rax, %r15
movq %rax, 0xdde6(%rip)      # 0x19590
movq 0xdde7(%rip), %rax      # 0x19598
testq %rax, %rax
jne 0xb7c7
movl $0x1000, %edi           # imm = 0x1000
callq 0x3040
movq %rax, 0xddd1(%rip)      # 0x19598
xorl %ecx, %ecx
cmpq $0x400, %rcx            # imm = 0x400
je 0xb7de
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
incq %rcx
jmp 0xb7c9
xorl %ecx, %ecx
cmpq $0x100, %rcx            # imm = 0x100
je 0xb80a
movl %ecx, %edx
shrl $0x4, %edx
movl (%r14,%rdx,4), %edx
movl %ecx, %esi
andl $0xf, %esi
shll $0x5, %edx
orl (%r14,%rsi,4), %edx
movl %edx, (%r15,%rcx,4)
movl %ecx, (%rax,%rdx,4)
incq %rcx
jmp 0xb7e0
movl %ebx, 0xdd78(%rip)      # 0x19588
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Codec/DiskEncoding.cpp
// Function: CDiskEncoding::InitGCRCBM_S(unsigned int*, int)
void CDiskEncoding::InitGCRCBM_S(uint32_t *gcrtable, int gcrid)
{
	// cancel if table initialized with the same gcr version
	if (gcrid == gcrinit_s)
		return;

	// create tables
	if (!gcrcode_s)
		gcrcode_s=new uint32_t[256];

	if (!gcrdecode_s)
		gcrdecode_s=new uint32_t[1024];

	uint32_t sval;

	// set GCR decode table to coding error as default
	for (sval=0; sval < 1024; sval++)
		gcrdecode_s[sval]=DF_31;

	// create GCR table
	for (sval=0; sval < 256; sval++) {
		uint32_t ghi=gcrtable[sval >> 4];
		uint32_t glo=gcrtable[sval & 0xf];
		uint32_t code=ghi << 5 | glo;
		gcrcode_s[sval]=code;
		gcrdecode_s[code]=sval;
	}

	gcrinit_s=gcrid;
}

// Assembly:
cmpl %esi, 0xdd84(%rip)      # 0x195a0
je 0xb8b7
pushq %r15
pushq %r14
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
movq 0xdd75(%rip), %r15      # 0x195a8
testq %r15, %r15
jne 0xb84c
movl $0x400, %edi            # imm = 0x400
callq 0x3040
movq %rax, %r15
movq %rax, 0xdd5c(%rip)      # 0x195a8
movq 0xdd5d(%rip), %rax      # 0x195b0
testq %rax, %rax
jne 0xb869
movl $0x1000, %edi           # imm = 0x1000
callq 0x3040
movq %rax, 0xdd47(%rip)      # 0x195b0
xorl %ecx, %ecx
cmpq $0x400, %rcx            # imm = 0x400
je 0xb880
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
incq %rcx
jmp 0xb86b
xorl %ecx, %ecx
cmpq $0x100, %rcx            # imm = 0x100
je 0xb8ac
movl %ecx, %edx
shrl $0x4, %edx
movl (%r14,%rdx,4), %edx
movl %ecx, %esi
andl $0xf, %esi
shll $0x5, %edx
orl (%r14,%rsi,4), %edx
movl %edx, (%r15,%rcx,4)
movl %ecx, (%rax,%rdx,4)
incq %rcx
jmp 0xb882
movl %ebx, 0xdcee(%rip)      # 0x195a0
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Codec/DiskEncoding.cpp
// Function: CDiskEncoding::InitGCRAppleH()
void CDiskEncoding::InitGCRAppleH()
{
	// stop if correct tables are available
	if (gcrahinit)
		return;

	// create tables
	if (!gcrahcode)
		gcrahcode=new uint32_t[256];

	if (!gcrahdecode)
		gcrahdecode=new uint32_t[65536];

	uint32_t sval;

	// create code table
	for (sval=0x0000; sval < 256; sval++) {
		// generate clock and data bits, like FM but bits are interleaved
		// C7C5C3C1 C6C4C2C0
		uint32_t ahi=(sval >> 1) | 0xaa;
		uint32_t alo=sval | 0xaa;
		uint32_t code=ahi << 8 | alo;

		// store encoding
		gcrahcode[sval]=code;
	}

	// create decode table
	for (sval=0x0000; sval < 0x10000; sval++) {
		uint32_t dhi=(sval >> 8) & 0x55;
		uint32_t dlo=sval & 0x55;
		uint32_t code=dhi << 1 | dlo;

		// store decoding, mark coding erros
		uint32_t cd=gcrahcode[code] & 0xffff;
		if (cd != sval)
			code|=DF_31;
		gcrahdecode[sval]=code;
	}

	gcrahinit=1;
}

// Assembly:
cmpl $0x0, 0xdcf9(%rip)      # 0x195b8
je 0xb8c2
retq
pushq %rbx
movq 0xdcf6(%rip), %rbx      # 0x195c0
testq %rbx, %rbx
jne 0xb8e3
movl $0x400, %edi            # imm = 0x400
callq 0x3040
movq %rax, %rbx
movq %rax, 0xdcdd(%rip)      # 0x195c0
movq 0xdcde(%rip), %rax      # 0x195c8
testq %rax, %rax
jne 0xb900
movl $0x40000, %edi          # imm = 0x40000
callq 0x3040
movq %rax, 0xdcc8(%rip)      # 0x195c8
xorl %ecx, %ecx
xorl %edx, %edx
cmpq $0x100, %rdx            # imm = 0x100
je 0xb922
movl %ecx, %esi
orl %edx, %esi
orl $0xaaaa, %esi           # imm = 0xAAAA
movl %esi, (%rbx,%rdx,4)
incq %rdx
subl $-0x80, %ecx
jmp 0xb904
xorl %ecx, %ecx
cmpq $0x10000, %rcx          # imm = 0x10000
je 0xb95a
movl %ecx, %edx
andl $0x55, %edx
movl %ecx, %esi
shrl $0x7, %esi
andl $0xaa, %esi
leal (%rsi,%rdx), %edi
movzwl (%rbx,%rdi,4), %r8d
cmpq %r8, %rcx
leal -0x80000000(%rsi,%rdx), %edx
cmovel %edi, %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
jmp 0xb924
movl $0x1, 0xdc54(%rip)      # 0x195b8
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Codec/DiskEncoding.cpp
// Function: CDiskEncoding::InitGCRApple5(unsigned int*)
void CDiskEncoding::InitGCRApple5(uint32_t *gcrtable)
{
	// stop if correct tables are available
	if (gcra5init)
		return;

	// create tables
	if (!gcra5code)
		gcra5code=new uint32_t[32];

	if (!gcra5decode)
		gcra5decode=new uint32_t[256];

	uint32_t sval;

	// set GCR decode table to coding error as default
	for (sval=0; sval < 256; sval++)
		gcra5decode[sval]=DF_31;

	// create GCR table
	for (sval=0; sval < 32; sval++) {
		uint32_t code=gcrtable[sval];
		gcra5code[sval]=code;
		gcra5decode[code]=sval;
	}

	gcra5init=1;
}

// Assembly:
cmpl $0x0, 0xdc63(%rip)      # 0x195d0
je 0xb970
retq
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xdc5a(%rip), %r14      # 0x195d8
testq %r14, %r14
jne 0xb997
movl $0x80, %edi
callq 0x3040
movq %rax, %r14
movq %rax, 0xdc41(%rip)      # 0x195d8
movq 0xdc42(%rip), %rax      # 0x195e0
testq %rax, %rax
jne 0xb9b4
movl $0x400, %edi            # imm = 0x400
callq 0x3040
movq %rax, 0xdc2c(%rip)      # 0x195e0
xorl %ecx, %ecx
cmpq $0x100, %rcx            # imm = 0x100
je 0xb9cb
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
incq %rcx
jmp 0xb9b6
xorl %ecx, %ecx
cmpq $0x20, %rcx
je 0xb9e2
movl (%rbx,%rcx,4), %edx
movl %edx, (%r14,%rcx,4)
movl %ecx, (%rax,%rdx,4)
incq %rcx
jmp 0xb9cd
movl $0x1, 0xdbe4(%rip)      # 0x195d0
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Codec/DiskEncoding.cpp
// Function: CDiskEncoding::InitGCRApple6(unsigned int*)
void CDiskEncoding::InitGCRApple6(uint32_t *gcrtable)
{
	// stop if correct tables are available
	if (gcra6init)
		return;

	// create tables
	if (!gcra6code)
		gcra6code=new uint32_t[64];

	if (!gcra6decode)
		gcra6decode=new uint32_t[256];

	uint32_t sval;

	// set GCR decode table to coding error as default
	for (sval=0; sval < 256; sval++)
		gcra6decode[sval]=DF_31;

	// create GCR table
	for (sval=0; sval < 64; sval++) {
		uint32_t code=gcrtable[sval];
		gcra6code[sval]=code;
		gcra6decode[code]=sval;
	}

	gcra6init=1;
}

// Assembly:
cmpl $0x0, 0xdbed(%rip)      # 0x195e8
je 0xb9fe
retq
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xdbe4(%rip), %r14      # 0x195f0
testq %r14, %r14
jne 0xba25
movl $0x100, %edi            # imm = 0x100
callq 0x3040
movq %rax, %r14
movq %rax, 0xdbcb(%rip)      # 0x195f0
movq 0xdbcc(%rip), %rax      # 0x195f8
testq %rax, %rax
jne 0xba42
movl $0x400, %edi            # imm = 0x400
callq 0x3040
movq %rax, 0xdbb6(%rip)      # 0x195f8
xorl %ecx, %ecx
cmpq $0x100, %rcx            # imm = 0x100
je 0xba59
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
incq %rcx
jmp 0xba44
xorl %ecx, %ecx
cmpq $0x40, %rcx
je 0xba70
movl (%rbx,%rcx,4), %edx
movl %edx, (%r14,%rcx,4)
movl %ecx, (%rax,%rdx,4)
incq %rcx
jmp 0xba5b
movl $0x1, 0xdb6e(%rip)      # 0x195e8
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Codec/DiskEncoding.cpp
// Function: CDiskEncoding::InitGCRVorpal(unsigned int*)
void CDiskEncoding::InitGCRVorpal(uint32_t *gcrtable)
{
	// stop if correct tables are available
	if (gcrvorpalinit)
		return;

	// create tables
	if (!gcrvorpalcode)
		gcrvorpalcode=new uint32_t[64];

	if (!gcrvorpaldecode)
		gcrvorpaldecode=new uint32_t[256];

	uint32_t sval;

	// set GCR decode table to coding error as default
	for (sval=0; sval < 256; sval++)
		gcrvorpaldecode[sval]=DF_31;

	// create GCR table
	for (sval=0; sval < 64; sval++) {
		uint32_t code=gcrtable[sval];
		gcrvorpalcode[sval]=code;
		gcrvorpaldecode[code]=sval;
	}

	gcrvorpalinit=1;
}

// Assembly:
cmpl $0x0, 0xdb77(%rip)      # 0x19600
je 0xba8c
retq
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xdb6e(%rip), %r14      # 0x19608
testq %r14, %r14
jne 0xbab3
movl $0x100, %edi            # imm = 0x100
callq 0x3040
movq %rax, %r14
movq %rax, 0xdb55(%rip)      # 0x19608
movq 0xdb56(%rip), %rax      # 0x19610
testq %rax, %rax
jne 0xbad0
movl $0x400, %edi            # imm = 0x400
callq 0x3040
movq %rax, 0xdb40(%rip)      # 0x19610
xorl %ecx, %ecx
cmpq $0x100, %rcx            # imm = 0x100
je 0xbae7
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
incq %rcx
jmp 0xbad2
xorl %ecx, %ecx
cmpq $0x40, %rcx
je 0xbafe
movl (%rbx,%rcx,4), %edx
movl %edx, (%r14,%rcx,4)
movl %ecx, (%rax,%rdx,4)
incq %rcx
jmp 0xbae9
movl $0x1, 0xdaf8(%rip)      # 0x19600
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Codec/DiskEncoding.cpp
// Function: CDiskEncoding::InitGCRVMax(unsigned int*, int)
void CDiskEncoding::InitGCRVMax(uint32_t *gcrtable, int vmaxid)
{
	// cancel if table initialized with the same gcr version
	if (gcrvmaxinit == vmaxid)
		return;

	// create tables
	if (!gcrvmaxcode)
		gcrvmaxcode=new uint32_t[64];

	if (!gcrvmaxdecode)
		gcrvmaxdecode=new uint32_t[256];

	uint32_t sval;

	// set GCR decode table to coding error as default
	for (sval=0; sval < 256; sval++)
		gcrvmaxdecode[sval]=DF_31;

	// create GCR table
	for (sval=0; sval < 64; sval++) {
		uint32_t code=gcrtable[sval];
		if (!code)
			continue;

		gcrvmaxcode[sval]=code;
		gcrvmaxdecode[code]=sval;
	}

	gcrvmaxinit=vmaxid;
}

// Assembly:
cmpl %esi, 0xd9da(%rip)      # 0x19630
je 0xbceb
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
cmpq $0x0, 0xd9cb(%rip)      # 0x19638
jne 0xbc80
movl $0x100, %edi            # imm = 0x100
callq 0x3040
movq %rax, 0xd9b8(%rip)      # 0x19638
movq 0xd9b9(%rip), %rax      # 0x19640
testq %rax, %rax
jne 0xbc9d
movl $0x400, %edi            # imm = 0x400
callq 0x3040
movq %rax, 0xd9a3(%rip)      # 0x19640
xorl %ecx, %ecx
cmpq $0x100, %rcx            # imm = 0x100
je 0xbcb4
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
incq %rcx
jmp 0xbc9f
movq 0xd97d(%rip), %rax      # 0x19638
movq 0xd97e(%rip), %rcx      # 0x19640
xorl %edx, %edx
cmpq $0x40, %rdx
je 0xbcde
movl (%r14,%rdx,4), %esi
testq %rsi, %rsi
je 0xbcd9
movl %esi, (%rax,%rdx,4)
movl %edx, (%rcx,%rsi,4)
incq %rdx
jmp 0xbcc4
movl %ebx, 0xd94c(%rip)      # 0x19630
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Codec/DiskEncoding.cpp
// Function: CDiskEncoding::InitGCR4Bit(unsigned int*)
void CDiskEncoding::InitGCR4Bit(uint32_t *gcrtable)
{
	// stop if correct tables are available
	if (gcr4bitinit)
		return;

	// create tables
	if (!gcr4bitcode)
		gcr4bitcode=new uint32_t[16];

	if (!gcr4bitdecode)
		gcr4bitdecode=new uint32_t[256];

	uint32_t sval;

	// set GCR decode table to coding error as default
	for (sval=0; sval < 256; sval++)
		gcr4bitdecode[sval]=DF_31;

	// create GCR table
	for (sval=0; sval < 16; sval++) {
		uint32_t code=gcrtable[sval];
		gcr4bitcode[sval]=code;
		gcr4bitdecode[code]=sval;
	}

	gcr4bitinit=1;
}

// Assembly:
cmpl $0x0, 0xd955(%rip)      # 0x19648
je 0xbcf6
retq
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xd94c(%rip), %r14      # 0x19650
testq %r14, %r14
jne 0xbd1b
pushq $0x40
popq %rdi
callq 0x3040
movq %rax, %r14
movq %rax, 0xd935(%rip)      # 0x19650
movq 0xd936(%rip), %rax      # 0x19658
testq %rax, %rax
jne 0xbd38
movl $0x400, %edi            # imm = 0x400
callq 0x3040
movq %rax, 0xd920(%rip)      # 0x19658
xorl %ecx, %ecx
cmpq $0x100, %rcx            # imm = 0x100
je 0xbd4f
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
incq %rcx
jmp 0xbd3a
xorl %ecx, %ecx
cmpq $0x10, %rcx
je 0xbd66
movl (%rbx,%rcx,4), %edx
movl %edx, (%r14,%rcx,4)
movl %ecx, (%rax,%rdx,4)
incq %rcx
jmp 0xbd51
movl $0x1, 0xd8d8(%rip)      # 0x19648
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Codec/DiskEncoding.cpp
// Function: CDiskEncoding::FindViolation(unsigned char*, int, int, int, int, int)
int CDiskEncoding::FindViolation(uint8_t *buffer, int bitpos, int bitcnt, int max0, int max1, int mode)
{
	int vcnt=0;

	// no violation if any of the parameters is incorrect or nothing to check
	if (!buffer || bitpos < 0 || bitcnt <= 0 || (max0 < 0 && max1 < 0))
		return mode ? vcnt : -1;

	// calculate the buffer position and bit mask for the first bit to check
	uint32_t bitmask=1 << ((bitpos & 7) ^ 7);
	uint32_t pos=bitpos >> 3;
	uint32_t sval=buffer[pos++];

	// reset bit counter
	int lbv=-1;
	int bc=0;

	// process all bits
	while (bitcnt-- > 0) {
		// if mask underflowed, reset the mask to b7 and read the next buffer value
		if (!bitmask) {
			bitmask=0x80;
			sval=buffer[pos++];
		}

		// current bit value
		int bitval=(sval & bitmask) ? 1 : 0;

		if (lbv != bitval) {
			// if different from previous bit, restart counting
			lbv=bitval;
			bc=1;
		} else {
			// same as previous bit, count it in
			bc++;

			// violation found if the stream contains max1 consecutive 1 bits or max0 consecutive 0 bits
			if ((!lbv && max0 >= 0 && bc >= max0) || (lbv && max1 >= 0 && bc >= max1)) {
				// count violations or return on first violation found depending on mode
				if (mode)
					vcnt++;
				else
					return bitpos;
			}
		}

		// move to next bit
		bitpos++;
		bitmask >>= 1;
	}

	// return violation count or no violation found depending on mode
	return mode ? vcnt : -1;
}

// Assembly:
movl %ecx, %r10d
movl %esi, %eax
testq %rdi, %rdi
setne %cl
testl %esi, %esi
setns %sil
testl %edx, %edx
setg %r11b
andb %sil, %r11b
andb %cl, %r11b
testl %r10d, %r8d
setns %cl
testb %cl, %r11b
je 0xbe5b
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %eax, %ecx
notb %cl
andb $0x7, %cl
movl $0x1, %r11d
shll %cl, %r11d
movl %eax, %ecx
shrl $0x3, %ecx
movzbl (%rdi,%rcx), %ebp
movl %ecx, %ebx
incl %ebx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %ecx, %ecx
xorl %r15d, %r15d
testl %edx, %edx
jle 0xbe64
testl %r11d, %r11d
jne 0xbdf3
movl %ebx, %r11d
incl %ebx
movzbl (%rdi,%r11), %ebp
movl $0x80, %r11d
xorl %r12d, %r12d
testl %r11d, %ebp
setne %r12b
cmpl %r12d, %r14d
jne 0xbe3d
testl %r10d, %r10d
sets %r12b
incl %r15d
testl %r14d, %r14d
setne %r13b
cmpl %r10d, %r15d
setl %sil
orb %r12b, %r13b
orb %sil, %r13b
cmpb $0x1, %r13b
jne 0xbe48
testl %r8d, %r8d
js 0xbe4f
testl %r14d, %r14d
je 0xbe4f
cmpl %r8d, %r15d
jge 0xbe48
movl $0x1, %r14d
jmp 0xbe4f
movl %r12d, %r14d
movl $0x1, %r15d
jmp 0xbe4f
testl %r9d, %r9d
je 0xbe6e
incl %ecx
incl %eax
shrl %r11d
decl %edx
jmp 0xbdd6
xorl %eax, %eax
cmpl $0x1, %r9d
sbbl %eax, %eax
retq
xorl %eax, %eax
cmpl $0x1, %r9d
sbbl %eax, %eax
orl %ecx, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/DiskFile.cpp
// Function: CDiskFile::Open(char const*, unsigned int)
int CDiskFile::Open(const char *name, unsigned int mode)
{
	// close file if it is open
	Close();

	// check name
	if (!name || !strlen(name))
		return 1;

	// select open mode
	const char *om;

	if (mode & BFFLAG_WRITE) {
		if (mode & BFFLAG_CREATE)
			om="w+b";
		else
			om="r+b";
	} else
		om="rb";

	// open file, stop on error
	if (!(dfile=fopen(name, om)))
		return 1;

	// success
	fileopen=1;
	filemode=mode;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %ebx
movq %rsi, %r15
movq %rdi, %r14
movq (%rdi), %rax
callq *0x10(%rax)
pushq $0x1
popq %rbp
testq %r15, %r15
je 0xbf3b
cmpb $0x0, (%r15)
je 0xbf3b
testb $0x2, %bl
leaq 0x342c(%rip), %rax      # 0xf32f
leaq 0x3421(%rip), %rcx      # 0xf32b
cmoveq %rax, %rcx
testb $0x1, %bl
leaq 0x341b(%rip), %rsi      # 0xf333
cmovneq %rcx, %rsi
movq %r15, %rdi
callq 0x3220
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0xbf3b
movl $0x1, 0x8(%r14)
movl %ebx, 0xc(%r14)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/DiskFile.cpp
// Function: CDiskFile::OpenAny(char**, unsigned int)
int CDiskFile::OpenAny(char **name, unsigned int mode)
{
	int pos;

	// if name list is valid
	if (name) {
		// try each name in order
		for (pos=0; name[pos]; pos++) {
			// open the file, return the name index position on success
			if (!Open(name[pos], mode))
				return pos;
		}
	}

	// all attempts failed
	return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq $-0x1
popq %rbx
testq %rsi, %rsi
je 0xbf82
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r15
xorl %r12d, %r12d
movq (%r14,%r12,8), %rsi
testq %rsi, %rsi
je 0xbf82
movq %r15, %rdi
movl %ebp, %edx
callq 0xbed6
testl %eax, %eax
je 0xbf7f
incq %r12
jmp 0xbf63
movl %r12d, %ebx
movl %ebx, %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/Core/DiskFile.cpp
// Function: CDiskFile::OpenAnyPath(char**, char const*, unsigned int)
int CDiskFile::OpenAnyPath(char **path, const char *name, unsigned int mode)
{
	int pos;

	// if name and path list are valid
	if (name && path) {
		// try each path entry in order
		for (pos=0; path[pos]; pos++) {
			// append name to current path entry
			int len=sprintf(tempname, "%s", path[pos]);
			sprintf(tempname+len, "%s", name);

			// open the file, return the name index position on success
			if (!Open(tempname, mode))
				return pos;
		}
	}

	// all attempts failed
	return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebp
movq %rdx, %r14
testq %rdx, %rdx
sete %dl
testq %rsi, %rsi
sete %cl
pushq $-0x1
popq %rax
orb %dl, %cl
jne 0xbffc
movq %rsi, %r15
movq %rdi, %r12
leaq 0x1c(%rdi), %r13
xorl %ebx, %ebx
movq (%r15,%rbx,8), %rsi
testq %rsi, %rsi
je 0xbff5
movq %r13, %rdi
callq 0x3200
subl %r13d, %eax
movslq %eax, %rdi
addq %r13, %rdi
movq %r14, %rsi
callq 0x31b0
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0xbed6
testl %eax, %eax
je 0xbffa
incq %rbx
jmp 0xbfbd
pushq $-0x1
popq %rax
jmp 0xbffc
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/DiskFile.cpp
// Function: CDiskFile::Close()
int CDiskFile::Close()
{
	// finished if file is not open
	if (!dfile)
		return 0;

	// close file, set error
	int res=fclose(dfile) ? 1 : 0;

	// clear settings
	dfile=NULL;
	lastop=-1;
	Clear();

	return res;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
testq %rdi, %rdi
je 0xc03b
callq 0x31d0
xorl %ebp, %ebp
testl %eax, %eax
setne %bpl
andq $0x0, 0x10(%rbx)
orl $-0x1, 0x18(%rbx)
movq %rbx, %rdi
callq 0x38ec
jmp 0xc03d
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/DiskFile.cpp
// Function: CDiskFile::Read(void*, unsigned long)
size_t CDiskFile::Read(void *buf, size_t size)
{
	// 0 bytes read if file is not open
	if (!dfile)
		return 0;

	// read/write change
	if (lastop != 0) {
		fseek(dfile, 0, SEEK_CUR);
		lastop=0;
	}

	// read the file
	return fread(buf, 1, size, dfile);
}

// Assembly:
movq 0x10(%rdi), %rcx
testq %rcx, %rcx
je 0xc08c
pushq %r15
pushq %r14
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
cmpl $0x0, 0x18(%rdi)
je 0xc079
pushq $0x1
popq %rdx
movq %rcx, %rdi
xorl %esi, %esi
callq 0x3210
andl $0x0, 0x18(%r15)
movq 0x10(%r15), %rcx
pushq $0x1
popq %rsi
movq %r14, %rdi
movq %rbx, %rdx
popq %rbx
popq %r14
popq %r15
jmp 0x32e0
xorl %eax, %eax
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/DiskFile.cpp
// Function: CDiskFile::Write(void*, unsigned long)
size_t CDiskFile::Write(void *buf, size_t size)
{
	// 0 bytes written if file is not open or read-only
	if (!dfile || !(filemode & BFFLAG_WRITE))
		return 0;

	// read/write change
	if (lastop != 1) {
		fseek(dfile, 0, SEEK_CUR);
		lastop=1;
	}

	// read the file
	return fwrite(buf, 1, size, dfile);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq 0x10(%rdi), %rcx
testq %rcx, %rcx
je 0xc0a7
movq %rdi, %r15
testb $0x1, 0xc(%rdi)
jne 0xc0af
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
movq %rdx, %rbx
movq %rsi, %r14
cmpl $0x1, 0x18(%r15)
je 0xc0d5
pushq $0x1
popq %rdx
movq %rcx, %rdi
xorl %esi, %esi
callq 0x3210
movl $0x1, 0x18(%r15)
movq 0x10(%r15), %rcx
pushq $0x1
popq %rsi
movq %r14, %rdi
movq %rbx, %rdx
popq %rbx
popq %r14
popq %r15
jmp 0x33c0
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/DiskFile.cpp
// Function: CDiskFile::GetSize()
long CDiskFile::GetSize()
{
	// default result 
	long res=0;

	// return default result if file is not open
	if (!dfile)
		return res;

	// get the current file position, stop on error
	long pos=ftell(dfile);
	if (pos < 0)
		return res;

	// get the file size
	long size=Seek(0, End);

	// restore file position, stop on error
	if (Seek(pos, Position) != pos)
		return res;

	return size;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
testq %rdi, %rdi
je 0xc18f
callq 0x3030
testq %rax, %rax
js 0xc18f
movq %rax, %r14
movq (%rbx), %rax
xorl %r12d, %r12d
pushq $0x3
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq *0x28(%rax)
movq %rax, %r15
movq (%rbx), %rax
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq *0x28(%rax)
cmpq %r14, %rax
cmovneq %r12, %r15
jmp 0xc192
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop