LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O3/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:
movq 0xc46b(%rip), %rcx      # 0x195f0
leaq 0xc464(%rip), %rax      # 0x195f0
testq %rcx, %rcx
je 0xd1b5
movl (%rcx), %ecx
cmpl 0x4(%rdi), %ecx
je 0xd1b5
leaq 0xc461(%rip), %rcx      # 0x19600
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
je 0xd1b5
movl (%rcx), %edx
leaq 0x10(%rax), %rcx
cmpl 0x4(%rdi), %edx
jne 0xd19f
movl 0x8(%rax), %eax
movl %eax, (%rdi)
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 0xd1d6
incl %esi
movl (%rdi), %eax
bswapl %eax
movl %eax, (%rdi)
addq $0x4, %rdi
decl %esi
cmpl $0x1, %esi
ja 0xd1c5
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 0x863e
xorl %ebx, %ebx
testl %eax, %eax
je 0xd268
movl 0x84(%r15), %eax
movl $0x7, 0x84(%r15)
cmpl $0xa, %eax
jne 0xd268
movl 0x94(%r15), %ebp
testl %ebp, %ebp
je 0xd268
movq %r12, %rdi
callq 0x8650
movl 0x20(%r15), %esi
subl %eax, %esi
cmpl %ebp, %esi
jge 0xd23a
xorl %ebx, %ebx
movq %r12, %rdi
xorl %edx, %edx
callq 0x8624
jmp 0xd268
movq %r12, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x8604
cmpl %ebp, %eax
jne 0xd268
movl 0x9c(%r15), %r15d
testl %r15d, %r15d
je 0xd266
movq %r14, %rdi
movl %ebp, %esi
callq 0x5055
cmpl %eax, %r15d
jne 0xd268
movl %ebp, %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 0x863e
testl %eax, %eax
je 0xd306
movl $0x7, 0x84(%r14)
movl 0x20(%r14), %eax
cmpl %ebp, %eax
cmovgel %ebp, %eax
xorl %r14d, %r14d
testl %ebp, %ebp
cmovnsl %eax, %r14d
movq %rbx, %rdi
movl %r14d, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x8624
jmp 0xd309
xorl %r14d, %r14d
movl %r14d, %eax
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 0xd355
pushq %rbx
movq %rdi, %rbx
addq $0x4, %rdi
movl 0x8(%rbx), %esi
leal -0x4(%rsi), %eax
sarl $0x2, %eax
testl %eax, %eax
jle 0xd343
leaq 0x8(%rbx), %rcx
incl %eax
movl (%rcx), %edx
bswapl %edx
movl %edx, (%rcx)
addq $0x4, %rcx
decl %eax
cmpl $0x1, %eax
ja 0xd332
movl $0x0, 0xc(%rbx)
callq 0x5055
bswapl %eax
movl %eax, 0xc(%rbx)
popq %rbx
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 0xb804(%rip), %rax      # 0x18b70
movq %rax, (%rdi)
movq 0xe1ea(%rip), %rdi      # 0x1b560
testq %rdi, %rdi
je 0xd380
callq 0x4280
movq 0xe1e1(%rip), %rdi      # 0x1b568
testq %rdi, %rdi
je 0xd391
callq 0x4280
movq 0xe1e0(%rip), %rdi      # 0x1b578
testq %rdi, %rdi
je 0xd3a2
callq 0x4280
movq 0xe1d7(%rip), %rdi      # 0x1b580
testq %rdi, %rdi
je 0xd3b3
callq 0x4280
movq 0xe1d6(%rip), %rdi      # 0x1b590
testq %rdi, %rdi
je 0xd3c4
callq 0x4280
movq 0xe1cd(%rip), %rdi      # 0x1b598
testq %rdi, %rdi
je 0xd3d5
callq 0x4280
movq 0xe1cc(%rip), %rdi      # 0x1b5a8
testq %rdi, %rdi
je 0xd3e6
callq 0x4280
movq 0xe1c3(%rip), %rdi      # 0x1b5b0
testq %rdi, %rdi
je 0xd3f7
callq 0x4280
movq 0xe1c2(%rip), %rdi      # 0x1b5c0
testq %rdi, %rdi
je 0xd408
callq 0x4280
movq 0xe1b9(%rip), %rdi      # 0x1b5c8
testq %rdi, %rdi
je 0xd419
callq 0x4280
movq 0xe1b8(%rip), %rdi      # 0x1b5d8
testq %rdi, %rdi
je 0xd42a
callq 0x4280
movq 0xe1af(%rip), %rdi      # 0x1b5e0
testq %rdi, %rdi
je 0xd43b
callq 0x4280
movq 0xe1ae(%rip), %rdi      # 0x1b5f0
testq %rdi, %rdi
je 0xd44c
callq 0x4280
movq 0xe1a5(%rip), %rdi      # 0x1b5f8
testq %rdi, %rdi
je 0xd45d
callq 0x4280
movq 0xe1a4(%rip), %rdi      # 0x1b608
testq %rdi, %rdi
je 0xd46e
callq 0x4280
movq 0xe19b(%rip), %rdi      # 0x1b610
testq %rdi, %rdi
je 0xd47f
callq 0x4280
movq 0xe19a(%rip), %rdi      # 0x1b620
testq %rdi, %rdi
je 0xd490
callq 0x4280
movq 0xe191(%rip), %rdi      # 0x1b628
testq %rdi, %rdi
je 0xd4a1
callq 0x4280
movq 0xe190(%rip), %rdi      # 0x1b638
testq %rdi, %rdi
je 0xd4b2
callq 0x4280
movq 0xe187(%rip), %rdi      # 0x1b640
testq %rdi, %rdi
je 0xd4c3
callq 0x4280
movq 0xe186(%rip), %rdi      # 0x1b650
testq %rdi, %rdi
je 0xd4d4
callq 0x4280
movq 0xe17d(%rip), %rdi      # 0x1b658
testq %rdi, %rdi
je 0xd4e5
callq 0x4280
popq %rax
jmp 0xd4ec
nop
// File: /workspace/github_cpp_makefile_star2_O3/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, 0xdf6b(%rip)      # 0x1b55c
je 0xd5f4
retq
pushq %rbx
movq 0xdf64(%rip), %rbx      # 0x1b560
testq %rbx, %rbx
jne 0xd615
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, %rbx
movq %rax, 0xdf4b(%rip)      # 0x1b560
movq 0xdf4c(%rip), %rax      # 0x1b568
testq %rax, %rax
jne 0xd632
movl $0x40000, %edi          # imm = 0x40000
callq 0x4040
movq %rax, 0xdf36(%rip)      # 0x1b568
xorl %ecx, %ecx
movl $0x80, %esi
xorl %edx, %edx
movl $0x80, %edi
movl %esi, %r8d
andl %ecx, %r8d
cmpl $0x1, %r8d
movl $0x3, %r8d
sbbl $0x0, %r8d
leal (%r8,%rdx,4), %edx
shrl %edi
cmpl $0x2, %esi
movl %edi, %esi
jae 0xd640
movl %edx, (%rbx,%rcx,4)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xd634
xorl %ecx, %ecx
movl $0x4000, %esi           # imm = 0x4000
xorl %edx, %edx
movl $0x4000, %edi           # imm = 0x4000
xorl %r8d, %r8d
testl %ecx, %esi
setne %r8b
leal (%r8,%rdx,2), %edx
shrl $0x2, %edi
cmpl $0x4, %esi
movl %edi, %esi
jae 0xd67e
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
cmpq $0x10000, %rcx          # imm = 0x10000
jne 0xd672
movl $0x1, 0xde9a(%rip)      # 0x1b55c
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/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, 0xdd36(%rip)      # 0x1b588
je 0xd8ee
pushq %r15
pushq %r14
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
movq 0xdd27(%rip), %r15      # 0x1b590
testq %r15, %r15
jne 0xd882
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, %r15
movq %rax, 0xdd0e(%rip)      # 0x1b590
movq 0xdd0f(%rip), %rax      # 0x1b598
testq %rax, %rax
jne 0xd89f
movl $0x1000, %edi           # imm = 0x1000
callq 0x4040
movq %rax, 0xdcf9(%rip)      # 0x1b598
xorl %ecx, %ecx
movaps 0x4a28(%rip), %xmm0     # 0x122d0
movups %xmm0, (%rax,%rcx,4)
addq $0x4, %rcx
cmpq $0x400, %rcx            # imm = 0x400
jne 0xd8a8
xorl %ecx, %ecx
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
cmpq $0x100, %rcx            # imm = 0x100
jne 0xd8bb
movl %ebx, 0xdc9f(%rip)      # 0x1b588
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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, 0xdcaa(%rip)      # 0x1b5a0
je 0xd992
pushq %r15
pushq %r14
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
movq 0xdc9b(%rip), %r15      # 0x1b5a8
testq %r15, %r15
jne 0xd926
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, %r15
movq %rax, 0xdc82(%rip)      # 0x1b5a8
movq 0xdc83(%rip), %rax      # 0x1b5b0
testq %rax, %rax
jne 0xd943
movl $0x1000, %edi           # imm = 0x1000
callq 0x4040
movq %rax, 0xdc6d(%rip)      # 0x1b5b0
xorl %ecx, %ecx
movaps 0x4984(%rip), %xmm0     # 0x122d0
movups %xmm0, (%rax,%rcx,4)
addq $0x4, %rcx
cmpq $0x400, %rcx            # imm = 0x400
jne 0xd94c
xorl %ecx, %ecx
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
cmpq $0x100, %rcx            # imm = 0x100
jne 0xd95f
movl %ebx, 0xdc13(%rip)      # 0x1b5a0
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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, 0xdc1d(%rip)      # 0x1b5b8
je 0xd99e
retq
pushq %rbx
movq 0xdc1a(%rip), %rbx      # 0x1b5c0
testq %rbx, %rbx
jne 0xd9bf
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, %rbx
movq %rax, 0xdc01(%rip)      # 0x1b5c0
movq 0xdc02(%rip), %rax      # 0x1b5c8
testq %rax, %rax
jne 0xd9dc
movl $0x40000, %edi          # imm = 0x40000
callq 0x4040
movq %rax, 0xdbec(%rip)      # 0x1b5c8
movdqa 0x48dc(%rip), %xmm0     # 0x122c0
xorl %ecx, %ecx
movdqa 0x49f2(%rip), %xmm1     # 0x123e0
movdqa 0x495a(%rip), %xmm2     # 0x12350
movdqa %xmm0, %xmm3
pslld $0x7, %xmm3
por %xmm0, %xmm3
por %xmm1, %xmm3
movdqu %xmm3, (%rbx,%rcx,4)
addq $0x4, %rcx
paddd %xmm2, %xmm0
cmpq $0x100, %rcx            # imm = 0x100
jne 0xd9f6
xorl %ecx, %ecx
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
cmpq $0x10000, %rcx          # imm = 0x10000
jne 0xda1f
movl $0x1, 0xdb5b(%rip)      # 0x1b5b8
popq %rbx
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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, 0xdb69(%rip)      # 0x1b5d0
je 0xda6a
retq
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xdb60(%rip), %r14      # 0x1b5d8
testq %r14, %r14
jne 0xda91
movl $0x80, %edi
callq 0x4040
movq %rax, %r14
movq %rax, 0xdb47(%rip)      # 0x1b5d8
movq 0xdb48(%rip), %rax      # 0x1b5e0
testq %rax, %rax
jne 0xdaae
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, 0xdb32(%rip)      # 0x1b5e0
xorl %ecx, %ecx
movaps 0x4819(%rip), %xmm0     # 0x122d0
movups %xmm0, (%rax,%rcx,4)
addq $0x4, %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xdab7
xorl %ecx, %ecx
movl (%rbx,%rcx,4), %edx
movl %edx, (%r14,%rcx,4)
movl %ecx, (%rax,%rdx,4)
incq %rcx
cmpq $0x20, %rcx
jne 0xdaca
movl $0x1, 0xdae9(%rip)      # 0x1b5d0
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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, 0xdaf1(%rip)      # 0x1b5e8
je 0xdafa
retq
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xdae8(%rip), %r14      # 0x1b5f0
testq %r14, %r14
jne 0xdb21
movl $0x100, %edi            # imm = 0x100
callq 0x4040
movq %rax, %r14
movq %rax, 0xdacf(%rip)      # 0x1b5f0
movq 0xdad0(%rip), %rax      # 0x1b5f8
testq %rax, %rax
jne 0xdb3e
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, 0xdaba(%rip)      # 0x1b5f8
xorl %ecx, %ecx
movaps 0x4789(%rip), %xmm0     # 0x122d0
movups %xmm0, (%rax,%rcx,4)
addq $0x4, %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xdb47
xorl %ecx, %ecx
movl (%rbx,%rcx,4), %edx
movl %edx, (%r14,%rcx,4)
movl %ecx, (%rax,%rdx,4)
incq %rcx
cmpq $0x40, %rcx
jne 0xdb5a
movl $0x1, 0xda71(%rip)      # 0x1b5e8
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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, 0xda79(%rip)      # 0x1b600
je 0xdb8a
retq
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xda70(%rip), %r14      # 0x1b608
testq %r14, %r14
jne 0xdbb1
movl $0x100, %edi            # imm = 0x100
callq 0x4040
movq %rax, %r14
movq %rax, 0xda57(%rip)      # 0x1b608
movq 0xda58(%rip), %rax      # 0x1b610
testq %rax, %rax
jne 0xdbce
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, 0xda42(%rip)      # 0x1b610
xorl %ecx, %ecx
movaps 0x46f9(%rip), %xmm0     # 0x122d0
movups %xmm0, (%rax,%rcx,4)
addq $0x4, %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xdbd7
xorl %ecx, %ecx
movl (%rbx,%rcx,4), %edx
movl %edx, (%r14,%rcx,4)
movl %ecx, (%rax,%rdx,4)
incq %rcx
cmpq $0x40, %rcx
jne 0xdbea
movl $0x1, 0xd9f9(%rip)      # 0x1b600
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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, 0xd8c4(%rip)      # 0x1b630
je 0xde02
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
cmpq $0x0, 0xd8b5(%rip)      # 0x1b638
jne 0xdd96
movl $0x100, %edi            # imm = 0x100
callq 0x4040
movq %rax, 0xd8a2(%rip)      # 0x1b638
movq 0xd8a3(%rip), %rax      # 0x1b640
testq %rax, %rax
jne 0xddb3
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, 0xd88d(%rip)      # 0x1b640
xorl %ecx, %ecx
movaps 0x4514(%rip), %xmm0     # 0x122d0
movups %xmm0, (%rax,%rcx,4)
addq $0x4, %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xddbc
movq 0xd864(%rip), %rax      # 0x1b638
movq 0xd865(%rip), %rcx      # 0x1b640
xorl %edx, %edx
movl (%r14,%rdx,4), %esi
testq %rsi, %rsi
je 0xddec
movl %esi, (%rax,%rdx,4)
movl %edx, (%rcx,%rsi,4)
incq %rdx
cmpq $0x40, %rdx
jne 0xdddd
movl %ebx, 0xd835(%rip)      # 0x1b630
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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, 0xd83d(%rip)      # 0x1b648
je 0xde0e
retq
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xd834(%rip), %r14      # 0x1b650
testq %r14, %r14
jne 0xde35
movl $0x40, %edi
callq 0x4040
movq %rax, %r14
movq %rax, 0xd81b(%rip)      # 0x1b650
movq 0xd81c(%rip), %rax      # 0x1b658
testq %rax, %rax
jne 0xde52
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, 0xd806(%rip)      # 0x1b658
xorl %ecx, %ecx
movaps 0x4475(%rip), %xmm0     # 0x122d0
movups %xmm0, (%rax,%rcx,4)
addq $0x4, %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xde5b
xorl %ecx, %ecx
movl (%rbx,%rcx,4), %edx
movl %edx, (%r14,%rcx,4)
movl %ecx, (%rax,%rdx,4)
incq %rcx
cmpq $0x10, %rcx
jne 0xde6e
movl $0x1, 0xd7bd(%rip)      # 0x1b648
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/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 0xdf7c
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %eax, %ecx
notb %cl
andb $0x7, %cl
movl $0x1, %esi
shll %cl, %esi
movl %eax, %ecx
shrl $0x3, %ecx
movzbl (%rdi,%rcx), %r11d
incl %ecx
incl %edx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %ebp, %ebp
xorl %ebx, %ebx
testl %esi, %esi
jne 0xdf02
movl %ecx, %esi
incl %ecx
movzbl (%rdi,%rsi), %r11d
movl $0x80, %esi
xorl %r15d, %r15d
testl %esi, %r11d
setne %r15b
cmpl %r15d, %r14d
jne 0xdf4b
testl %r10d, %r10d
sets %r15b
incl %ebp
testl %r14d, %r14d
setne %r12b
cmpl %r10d, %ebp
setl %r13b
orb %r15b, %r12b
orb %r13b, %r12b
cmpb $0x1, %r12b
jne 0xdf55
testl %r8d, %r8d
js 0xdf5c
testl %r14d, %r14d
je 0xdf5c
cmpl %r8d, %ebp
jge 0xdf55
movl $0x1, %r14d
jmp 0xdf5c
movl %r15d, %r14d
movl $0x1, %ebp
jmp 0xdf5c
testl %r9d, %r9d
je 0xdf71
incl %ebx
incl %eax
shrl %esi
decl %edx
cmpl $0x1, %edx
ja 0xdef0
xorl %eax, %eax
cmpl $0x1, %r9d
sbbl %eax, %eax
orl %ebx, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
cmpl $0x1, %r9d
sbbl %eax, %eax
retq
nopl (%rax)
// File: /workspace/github_cpp_makefile_star2_O3/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)
movl $0x1, %ebp
testq %r15, %r15
je 0xe04f
cmpb $0x0, (%r15)
je 0xe04f
testb $0x2, %bl
leaq 0x4408(%rip), %rax      # 0x1241f
leaq 0x43fd(%rip), %rcx      # 0x1241b
cmoveq %rax, %rcx
testb $0x1, %bl
leaq 0x43f7(%rip), %rsi      # 0x12423
cmovneq %rcx, %rsi
movq %r15, %rdi
callq 0x4250
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0xe04f
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_O3/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
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rsi, %rsi
je 0xe0a1
movq %rsi, %r14
movq (%rsi), %rsi
testq %rsi, %rsi
je 0xe0a1
movl %edx, %ebp
movq %rdi, %r15
xorl %r12d, %r12d
movq %r15, %rdi
movl %ebp, %edx
callq 0xdfe8
testl %eax, %eax
je 0xe09e
movq 0x8(%r14,%r12,8), %rsi
incq %r12
testq %rsi, %rsi
jne 0xe081
jmp 0xe0a1
movl %r12d, %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
orb %dl, %cl
jne 0xe125
movq %rsi, %r15
movq (%rsi), %rsi
testq %rsi, %rsi
je 0xe125
movq %rdi, %r12
leaq 0x1c(%rdi), %r13
xorl %ebx, %ebx
movq %r13, %rdi
callq 0x4220
subl %r13d, %eax
movslq %eax, %rdi
addq %r13, %rdi
movq %r14, %rsi
callq 0x41e0
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0xdfe8
testl %eax, %eax
je 0xe123
movq 0x8(%r15,%rbx,8), %rsi
incq %rbx
testq %rsi, %rsi
jne 0xe0e5
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xe125
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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 0xe169
callq 0x41f0
xorl %ebp, %ebp
testl %eax, %eax
setne %bpl
movq $0x0, 0x10(%rbx)
movl $0xffffffff, 0x18(%rbx) # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x4950
jmp 0xe16b
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/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 0xe1c1
pushq %r15
pushq %r14
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
cmpl $0x0, 0x18(%rdi)
je 0xe1ac
movq %rcx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x4230
movl $0x0, 0x18(%r15)
movq 0x10(%r15), %rcx
movl $0x1, %esi
movq %r14, %rdi
movq %rbx, %rdx
popq %rbx
popq %r14
popq %r15
jmp 0x42e0
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O3/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 0xe1db
movq %rdi, %r15
testb $0x1, 0xc(%rdi)
jne 0xe1e3
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
movq %rdx, %rbx
movq %rsi, %r14
cmpl $0x1, 0x18(%r15)
je 0xe20b
movq %rcx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x4230
movl $0x1, 0x18(%r15)
movq 0x10(%r15), %rcx
movl $0x1, %esi
movq %r14, %rdi
movq %rbx, %rdx
popq %rbx
popq %r14
popq %r15
jmp 0x43e0
// File: /workspace/github_cpp_makefile_star2_O3/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 0xe2cf
callq 0x4030
testq %rax, %rax
js 0xe2cf
movq %rax, %r14
movq (%rbx), %rax
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %esi, %esi
movl $0x3, %edx
callq *0x28(%rax)
movq %rax, %r15
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq *0x28(%rax)
cmpq %r14, %rax
cmovneq %r12, %r15
jmp 0xe2d2
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/Core/DiskFile.cpp
// Function: CDiskFile::MakePath(char const*)
void CDiskFile::MakePath(const char *filename)
{
	if (!filename)
		return;

	char path[MAX_FILENAMELEN];

	// create each directory level delimited by / or \ if does not exist
	for (int rpos = 0, wpos = 0; filename[rpos]; rpos++) {
		if (filename[rpos] == '/' || filename[rpos] == '\\') {
			path[wpos] = 0;

			if (_access(path, 0) == -1)
				_mkdir(path);
		}

		path[wpos++] = filename[rpos];
	}
}

// Assembly:
testq %rdi, %rdi
je 0xe36a
pushq %r15
pushq %r14
pushq %rbx
subq $0x210, %rsp            # imm = 0x210
movq %rdi, %rbx
xorl %r15d, %r15d
movq %rsp, %r14
movzbl (%rbx,%r15), %eax
cmpl $0x2f, %eax
je 0xe333
cmpl $0x5c, %eax
je 0xe333
testl %eax, %eax
jne 0xe351
jmp 0xe35e
movb $0x0, (%rsp,%r15)
movq %r14, %rdi
xorl %esi, %esi
callq 0x4350
cmpl $-0x1, %eax
jne 0xe351
movq %r14, %rdi
xorl %esi, %esi
callq 0x4100
movb (%rbx,%r15), %al
movb %al, (%rsp,%r15)
incq %r15
jmp 0xe31e
addq $0x210, %rsp            # imm = 0x210
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::Destroy()
void CDiskImage::Destroy()
{
	// unlock all track data
	UnlockTrack(true);

	// invalid image
	memset(&dii, 0, sizeof(dii));

	// read only
	dii.readonly=true;

	// track lock to raw format
	dii.rawlock=true;

	// no track data
	dticnt=0;
	delete [] dti;
	dti=NULL;
	dticyl=0;
	dtihed=0;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl $0x1, %ebp
movl $0x1, %esi
callq 0xe912
leaq 0x8(%rbx), %rdi
movl $0x98, %edx
xorl %esi, %esi
callq 0x4140
movl %ebp, 0x14(%rbx)
movl %ebp, 0x1c(%rbx)
movl $0x0, 0xa0(%rbx)
movq 0xb0(%rbx), %rdi
testq %rdi, %rdi
je 0xe78a
callq 0x4280
xorl %eax, %eax
movq %rax, 0xb0(%rbx)
movq %rax, 0xa4(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::LoadImage(unsigned int, int)
int CDiskImage::LoadImage(UDWORD flag, int free)
{
	int res=imgeOk;

	// cancel, if no track data
	if (!dti)
		return res;

	// try to load all tracks
	for (int trk=0; trk < dticnt; trk++) {
		PDISKTRACKINFO pt=dti+trk;

		// test only untested tracks
		switch (pt->type) {
			case dtitUndefined:
			case dtitError:
				continue;
		}

		// load and decode
		int read=AllocTrack(pt, flag);

		// free track only if requested
		if (free)
			FreeTrack(pt);

		// test load result
		switch (read) {
			// stop if image can't be read
			case imgeUnsupported:
			case imgeIncompatible:
				trk=dticnt;
				res=read;
				continue;

			// no errors
			case imgeOk:
				break;

			// set error
			default:
				res=imgeGeneric;
				break;
		}
	}

	return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, 0x4(%rsp)
xorl %ebp, %ebp
cmpq $0x0, 0xb0(%rdi)
je 0xe8a1
movq %rdi, %r14
cmpl $0x0, 0xa0(%rdi)
jle 0xe8a1
movl %edx, %ebx
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0xb0(%r14), %r12
movslq %r13d, %rax
imulq $0x148, %rax, %rcx      # imm = 0x148
movl (%r12,%rcx), %eax
cmpl $0x2, %eax
jae 0xe836
movl %r15d, %ebp
jmp 0xe88e
addq %rcx, %r12
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0xe855
movq (%r14), %rax
movq %r14, %rdi
movq %r12, %rsi
movl 0x4(%rsp), %edx
callq *0x28(%rax)
movl %eax, %ebp
jmp 0xe864
movl $0x2, %ebp
cmpl $0x4, %eax
jne 0xe864
movl $0x1, %ebp
testl %ebx, %ebx
je 0xe872
movq %r12, %rdi
xorl %esi, %esi
callq 0xe8dc
testl %ebp, %ebp
je 0xe831
cmpl $0xe, %ebp
je 0xe880
cmpl $0x1, %ebp
jne 0xe889
movl 0xa0(%r14), %r13d
jmp 0xe88e
movl $0x2, %ebp
incl %r13d
movl %ebp, %r15d
cmpl 0xa0(%r14), %r13d
jl 0xe817
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::FreeTrack(DiskTrackInfo*, int)
void CDiskImage::FreeTrack(PDISKTRACKINFO pti, int forced)
{
	// cancel if invalid track data
	if (!pti)
		return;

	// cancel if track data linked and free is not forced
	if (pti->linked && !forced)
		return;

	// linked track data does not exist anymore
	pti->linked=false;
	pti->linkinfo=0;
	pti->linkflag=0;

	// free buffers
	FreeTrackData(pti);
	FreeTrackTiming(pti);
}

// Assembly:
pushq %rbx
testq %rdi, %rdi
je 0xe8ef
movq %rdi, %rbx
testl %esi, %esi
jne 0xe8f1
cmpl $0x0, 0x4(%rbx)
je 0xe8f1
popq %rbx
retq
movq $0x0, 0x4(%rbx)
movl $0x0, 0xc(%rbx)
movq %rbx, %rdi
callq 0xeddc
movq %rbx, %rdi
popq %rbx
jmp 0xeed0
nop
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::UnlockTrack(int)
void CDiskImage::UnlockTrack(int forced)
{
	// cancel, if no track data
	if (!dti)
		return;

	// free all buffers
	for (int trk=0; trk < dticnt; trk++)
		FreeTrack(dti+trk, forced);
}

// Assembly:
cmpq $0x0, 0xb0(%rdi)
je 0xe96a
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
cmpl $0x0, 0xa0(%rdi)
jle 0xe95f
movl %esi, %ebx
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0xb0(%r14), %rdi
addq %r15, %rdi
movl %ebx, %esi
callq 0xe8dc
incq %r12
movslq 0xa0(%r14), %rax
addq $0x148, %r15            # imm = 0x148
cmpq %rax, %r12
jl 0xe938
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::AddTrack(DiskTrackInfo*)
int CDiskImage::AddTrack(PDISKTRACKINFO pdti)
{
	// clear track data
	UnlockTrack(pdti->cylinder, pdti->head, true);

	// map track info to memory
	PDISKTRACKINFO pt=MapTrack(pdti->cylinder, pdti->head);
	if (!pt)
		return imgeOutOfRange;

	// replace info
	*pt=*pdti;

	// update image info
	UpdateImageInfo(pdti);

	return imgeOk;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl 0x10(%rsi), %esi
movl 0x14(%rbx), %edx
movl $0x1, %ecx
callq 0xe9c6
movl 0x10(%rbx), %esi
movl 0x14(%rbx), %edx
movq %r14, %rdi
callq 0xea14
testq %rax, %rax
je 0xe9b8
movl $0x148, %edx            # imm = 0x148
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4190
movq %r14, %rdi
movq %rbx, %rsi
callq 0xeba6
xorl %eax, %eax
jmp 0xe9bd
movl $0x3, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::UnlockTrack(int, int, int)
PDISKTRACKINFO CDiskImage::GetTrack(int cylinder, int head)
{
	// cancel, if no track data
	if (!dti)
		return NULL;

	// ignore wrong cylinder
	if (cylinder<0 || cylinder>=dticyl)
		return NULL;

	// ignore wrong head
	if (head<0 || head>=dtihed)
		return NULL;

	return &dti[cylinder*dtihed+head];
}

// Assembly:
pushq %rbx
movq 0xb0(%rdi), %rax
testq %rax, %rax
je 0xea03
xorl %ebx, %ebx
movl %edx, %r8d
orl %esi, %r8d
js 0xea05
cmpl %esi, 0xa4(%rdi)
jle 0xea05
movl 0xa8(%rdi), %edi
cmpl %edx, %edi
jle 0xea03
imull %esi, %edi
addl %edx, %edi
imulq $0x148, %rdi, %rdx      # imm = 0x148
addq %rdx, %rax
movq %rax, %rbx
jmp 0xea05
xorl %ebx, %ebx
movq %rbx, %rdi
movl %ecx, %esi
callq 0xe8dc
movq %rbx, %rax
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::MapTrack(int, int)
PDISKTRACKINFO CDiskImage::MapTrack(int cylinder, int head)
{
	// ignore wrong cylinder
	if (cylinder<0 || cylinder>=MAX_CYLINDER)
		return NULL;

	// ignore wrong head
	if (head<0 || head>=MAX_HEAD)
		return NULL;

	// return if available
	PDISKTRACKINFO pt=GetTrack(cylinder, head);
	if (pt)
		return pt;

	if (!dti) {
		// first allocation
		dtihed=MAX_HEAD;
		dticnt=((cylinder*dtihed)/DEF_TRACKINFO+1)*DEF_TRACKINFO;
		dticyl=dticnt/MAX_HEAD;
		dti=new DiskTrackInfo[dticnt];
		memset(dti, 0, sizeof(DiskTrackInfo)*dticnt);
	} else {
		// reallocation
		int scnt=dticnt;
		PDISKTRACKINFO sti=dti;
		dticnt=((cylinder*dtihed)/DEF_TRACKINFO+1)*DEF_TRACKINFO;
		dticyl=dticnt/MAX_HEAD;
		dti=new DiskTrackInfo[dticnt];
		memcpy(dti, sti, sizeof(DiskTrackInfo)*scnt);
		memset(dti+scnt, 0, sizeof(DiskTrackInfo)*(dticnt-scnt));
		delete [] sti;
	}

	return &dti[cylinder*dtihed+head];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpl $0x10000, %esi          # imm = 0x10000
setae %al
cmpl $0x2, %edx
setae %cl
orb %al, %cl
je 0xea3d
xorl %r15d, %r15d
jmp 0xeb93
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r14
movq 0xb0(%rdi), %r15
testq %r15, %r15
je 0xea81
movl 0xa8(%r14), %eax
cmpl %ebp, 0xa4(%r14)
setg %cl
cmpl %ebx, %eax
setg %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0xeada
imull %ebp, %eax
addl %ebx, %eax
imulq $0x148, %rax, %rax      # imm = 0x148
addq %rax, %r15
jmp 0xeb93
movl $0x2, 0xa8(%r14)
movl %ebp, %eax
andl $0xfc00, %eax           # imm = 0xFC00
leal 0x800(,%rax,2), %eax
movl %eax, 0xa0(%r14)
imull $0x148, %eax, %r15d     # imm = 0x148
shrl %eax
movl %eax, 0xa4(%r14)
movq %r15, %rdi
callq 0x4040
movq %rax, %r12
movq %rax, 0xb0(%r14)
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x4140
movl $0x2, %eax
jmp 0xeb82
movslq 0xa0(%r14), %rcx
movq %rcx, 0x8(%rsp)
imull %ebp, %eax
leal 0x7ff(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $0xfffff800, %ecx       # imm = 0xFFFFF800
addl $0x800, %ecx            # imm = 0x800
movl %ecx, 0xa0(%r14)
movslq %ecx, %r12
sarl %ecx
movl %ecx, 0xa4(%r14)
movl $0x148, %ecx            # imm = 0x148
movq %r12, %rax
mulq %rcx
movq $-0x1, %rdi
cmovnoq %rax, %rdi
callq 0x4040
movq %rax, %r13
movq %rax, 0xb0(%r14)
imulq $0x148, 0x8(%rsp), %rdx # imm = 0x148
movq %rdx, 0x10(%rsp)
movq %rax, %rdi
movq %r15, %rsi
callq 0x4190
addq 0x10(%rsp), %r13
subq 0x8(%rsp), %r12
imulq $0x148, %r12, %rdx      # imm = 0x148
movq %r13, %rdi
xorl %esi, %esi
callq 0x4140
movq %r15, %rdi
callq 0x4280
movq 0xb0(%r14), %r12
movl 0xa8(%r14), %eax
imull %ebp, %eax
addl %ebx, %eax
cltq
imulq $0x148, %rax, %r15      # imm = 0x148
addq %r12, %r15
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::UpdateImageInfo(DiskTrackInfo*)
void CDiskImage::UpdateImageInfo(PDISKTRACKINFO pti)
{
	if (!dii.valid) {
		// first time
		dii.umincylinder=pti->cylinder;
		dii.umaxcylinder=pti->cylinder;
		dii.uminhead=pti->head;
		dii.umaxhead=pti->head;
		dii.valid=true;
	} else {
		// compare and update
		if (pti->cylinder < dii.umincylinder)
			dii.umincylinder=pti->cylinder;
		if (pti->cylinder > dii.umaxcylinder)
			dii.umaxcylinder=pti->cylinder;
		if (pti->head < dii.uminhead)
			dii.uminhead=pti->head;
		if (pti->head > dii.umaxhead)
			dii.umaxhead=pti->head;
	}
}

// Assembly:
cmpl $0x0, 0x8(%rdi)
movl 0x10(%rsi), %eax
je 0xebd3
cmpl 0x20(%rdi), %eax
jge 0xebb7
movl %eax, 0x20(%rdi)
cmpl 0x24(%rdi), %eax
jle 0xebbf
movl %eax, 0x24(%rdi)
movl 0x14(%rsi), %eax
cmpl 0x28(%rdi), %eax
jge 0xebca
movl %eax, 0x28(%rdi)
cmpl 0x2c(%rdi), %eax
jle 0xebd2
movl %eax, 0x2c(%rdi)
retq
movl %eax, 0x20(%rdi)
movl %eax, 0x24(%rdi)
movl 0x14(%rsi), %eax
movl %eax, 0x28(%rdi)
movl %eax, 0x2c(%rdi)
movl $0x1, 0x8(%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::LockTrack(int, int, unsigned int)
PDISKTRACKINFO CDiskImage::LockTrack(int cylinder, int head, UDWORD flag)
{
	// save the current revolution counter
	dii.lastrev = dii.nextrev;

	// locate track information
	PDISKTRACKINFO pti=GetTrack(cylinder, head);

	// allocate and load buffers
	dii.error=AllocTrack(pti, flag);

	// update the revolution counter unless updates are disabled
	// limit the counter value to 8 bit
	if (!(flag & DI_LOCK_NOUPDATE))
		dii.nextrev = (dii.nextrev + 1) & 0xff;

	return dii.error == imgeOk ? pti : NULL;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %ecx, %ebp
movq %rdi, %rbx
movl 0x3c(%rdi), %eax
movl %eax, 0x40(%rdi)
movq 0xb0(%rdi), %rcx
movl $0x2, %eax
testq %rcx, %rcx
je 0xec8e
xorl %r14d, %r14d
movl %edx, %edi
orl %esi, %edi
js 0xec91
cmpl %esi, 0xa4(%rbx)
jle 0xec91
movl 0xa8(%rbx), %edi
cmpl %edx, %edi
jle 0xec8e
imull %esi, %edi
addl %edx, %edi
imulq $0x148, %rdi, %rdx      # imm = 0x148
leaq (%rcx,%rdx), %r14
movl (%rcx,%rdx), %ecx
leal -0x2(%rcx), %edx
cmpl $0x2, %edx
jae 0xecb5
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq *0x28(%rax)
jmp 0xec91
xorl %r14d, %r14d
movl %eax, 0xc(%rbx)
btl $0xd, %ebp
jb 0xeca5
movl 0x3c(%rbx), %ecx
incl %ecx
movzbl %cl, %ecx
movl %ecx, 0x3c(%rbx)
xorl %ecx, %ecx
testl %eax, %eax
cmoveq %r14, %rcx
movq %rcx, %rax
popq %rbx
popq %r14
popq %rbp
retq
cmpl $0x4, %ecx
jne 0xec91
movl $0x1, %eax
jmp 0xec91
nop
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::LockTrackComp(int, int, unsigned int, int, int)
PDISKTRACKINFO CDiskImage::LockTrackComp(int cylinder, int head, UDWORD flag, int sblk, int eblk)
{
	// locate track information
	PDISKTRACKINFO pti=GetTrack(cylinder, head);
	pti->compsblk=sblk;
	pti->compeblk=eblk;
	flag|=DI_LOCK_COMP;

	// allocate and load buffers
	dii.error=AllocTrack(pti, flag);
	return dii.error == imgeOk ? pti : NULL;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0xb0(%rdi), %rax
testq %rax, %rax
je 0xed04
xorl %r14d, %r14d
movl %edx, %edi
orl %esi, %edi
js 0xed07
cmpl %esi, 0xa4(%rbx)
jle 0xed07
movl 0xa8(%rbx), %edi
cmpl %edx, %edi
jle 0xed04
imull %esi, %edi
addl %edx, %edi
imulq $0x148, %rdi, %rdx      # imm = 0x148
addq %rdx, %rax
movq %rax, %r14
jmp 0xed07
xorl %r14d, %r14d
movl %r8d, 0xc8(%r14)
movl %r9d, 0xcc(%r14)
movl (%r14), %edx
leal -0x2(%rdx), %eax
cmpl $0x2, %eax
jae 0xed43
orl $0x80000000, %ecx       # imm = 0x80000000
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
movl %ecx, %edx
callq *0x28(%rax)
movl %eax, %ecx
movl %eax, 0xc(%rbx)
xorl %eax, %eax
testl %ecx, %ecx
cmoveq %r14, %rax
jmp 0xed57
movl $0x2, %eax
cmpl $0x4, %edx
jne 0xed52
movl $0x1, %eax
movl %eax, 0xc(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::LinkTrackData(DiskTrackInfo*, int)
int CDiskImage::LinkTrackData(PDISKTRACKINFO pti, int size)
{
	// cancel if bad parameters
	if (!pti || size<0)
		return imgeGeneric;

	// free existing buffers
	FreeTrackData(pti);

	// 1 revolution
	if (size) {
		pti->trackcnt=1;
		pti->tracklen=size;
		pti->trackbuf=new UBYTE[pti->tracklen];
		pti->trackdata[0]=pti->trackbuf;
		pti->tracksize[0]=pti->tracklen;
		pti->trackstart[0]=0;

		// clear track data
		memset(pti->trackbuf, 0, pti->tracklen);
	}

	// prevent operations that could modify or remove the buffer
	pti->linked=true;
	pti->linkinfo=0;
	pti->linkflag=0;

	return imgeOk;
}

// Assembly:
testq %rdi, %rdi
sete %al
testl %esi, %esi
sets %cl
orb %al, %cl
movl $0x2, %eax
jne 0xeddb
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebp
movq %rdi, %rbx
callq 0xeddc
testl %ebp, %ebp
je 0xedc6
movl $0x1, 0x28(%rbx)
movl %ebp, 0x50(%rbx)
movl %ebp, %r14d
movq %r14, %rdi
callq 0x4040
movq %rax, 0x48(%rbx)
movq %rax, 0x58(%rbx)
movl %ebp, 0x80(%rbx)
movl $0x0, 0x94(%rbx)
movq %rax, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x4140
movq $0x1, 0x4(%rbx)
movl $0x0, 0xc(%rbx)
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq