LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O1/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 0xd0fc
incl %esi
movl (%rdi), %eax
bswapl %eax
movl %eax, (%rdi)
addq $0x4, %rdi
decl %esi
cmpl $0x1, %esi
jg 0xd0eb
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0x881a
xorl %ebx, %ebx
testl %eax, %eax
je 0xd18e
movl 0x84(%r15), %eax
movl $0x7, 0x84(%r15)
cmpl $0xa, %eax
jne 0xd18e
movl 0x94(%r15), %ebp
testl %ebp, %ebp
je 0xd18e
movq %r12, %rdi
callq 0x882c
movl 0x20(%r15), %esi
subl %eax, %esi
cmpl %ebp, %esi
jge 0xd160
xorl %ebx, %ebx
movq %r12, %rdi
xorl %edx, %edx
callq 0x8800
jmp 0xd18e
movq %r12, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x87e0
cmpl %ebp, %eax
jne 0xd18e
movl 0x9c(%r15), %r15d
testl %r15d, %r15d
je 0xd18c
movq %r14, %rdi
movl %ebp, %esi
callq 0x506f
cmpl %eax, %r15d
jne 0xd18e
movl %ebp, %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/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 0x881a
testl %eax, %eax
je 0xd22c
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 0x8800
jmp 0xd22f
xorl %r14d, %r14d
movl %r14d, %eax
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0xd27b
pushq %rbx
movq %rdi, %rbx
addq $0x4, %rdi
movl 0x8(%rbx), %esi
leal -0x4(%rsi), %eax
sarl $0x2, %eax
testl %eax, %eax
jle 0xd269
leaq 0x8(%rbx), %rcx
incl %eax
movl (%rcx), %edx
bswapl %edx
movl %edx, (%rcx)
addq $0x4, %rcx
decl %eax
cmpl $0x1, %eax
jg 0xd258
movl $0x0, 0xc(%rbx)
callq 0x506f
bswapl %eax
movl %eax, 0xc(%rbx)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 0xb8e0(%rip), %rax      # 0x18b70
movq %rax, (%rdi)
movq 0xe2c6(%rip), %rdi      # 0x1b560
testq %rdi, %rdi
je 0xd2a4
callq 0x4280
movq 0xe2bd(%rip), %rdi      # 0x1b568
testq %rdi, %rdi
je 0xd2b5
callq 0x4280
movq 0xe2bc(%rip), %rdi      # 0x1b578
testq %rdi, %rdi
je 0xd2c6
callq 0x4280
movq 0xe2b3(%rip), %rdi      # 0x1b580
testq %rdi, %rdi
je 0xd2d7
callq 0x4280
movq 0xe2b2(%rip), %rdi      # 0x1b590
testq %rdi, %rdi
je 0xd2e8
callq 0x4280
movq 0xe2a9(%rip), %rdi      # 0x1b598
testq %rdi, %rdi
je 0xd2f9
callq 0x4280
movq 0xe2a8(%rip), %rdi      # 0x1b5a8
testq %rdi, %rdi
je 0xd30a
callq 0x4280
movq 0xe29f(%rip), %rdi      # 0x1b5b0
testq %rdi, %rdi
je 0xd31b
callq 0x4280
movq 0xe29e(%rip), %rdi      # 0x1b5c0
testq %rdi, %rdi
je 0xd32c
callq 0x4280
movq 0xe295(%rip), %rdi      # 0x1b5c8
testq %rdi, %rdi
je 0xd33d
callq 0x4280
movq 0xe294(%rip), %rdi      # 0x1b5d8
testq %rdi, %rdi
je 0xd34e
callq 0x4280
movq 0xe28b(%rip), %rdi      # 0x1b5e0
testq %rdi, %rdi
je 0xd35f
callq 0x4280
movq 0xe28a(%rip), %rdi      # 0x1b5f0
testq %rdi, %rdi
je 0xd370
callq 0x4280
movq 0xe281(%rip), %rdi      # 0x1b5f8
testq %rdi, %rdi
je 0xd381
callq 0x4280
movq 0xe280(%rip), %rdi      # 0x1b608
testq %rdi, %rdi
je 0xd392
callq 0x4280
movq 0xe277(%rip), %rdi      # 0x1b610
testq %rdi, %rdi
je 0xd3a3
callq 0x4280
movq 0xe276(%rip), %rdi      # 0x1b620
testq %rdi, %rdi
je 0xd3b4
callq 0x4280
movq 0xe26d(%rip), %rdi      # 0x1b628
testq %rdi, %rdi
je 0xd3c5
callq 0x4280
movq 0xe26c(%rip), %rdi      # 0x1b638
testq %rdi, %rdi
je 0xd3d6
callq 0x4280
movq 0xe263(%rip), %rdi      # 0x1b640
testq %rdi, %rdi
je 0xd3e7
callq 0x4280
movq 0xe262(%rip), %rdi      # 0x1b650
testq %rdi, %rdi
je 0xd3f8
callq 0x4280
movq 0xe259(%rip), %rdi      # 0x1b658
testq %rdi, %rdi
je 0xd409
callq 0x4280
popq %rax
jmp 0xd410
nop
// File: /workspace/github_cpp_makefile_star2_O1/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, 0xe047(%rip)      # 0x1b55c
je 0xd518
retq
pushq %rax
cmpq $0x0, 0xe03f(%rip)      # 0x1b560
jne 0xd534
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, 0xe02c(%rip)      # 0x1b560
cmpq $0x0, 0xe02c(%rip)      # 0x1b568
jne 0xd54f
movl $0x40000, %edi          # imm = 0x40000
callq 0x4040
movq %rax, 0xe019(%rip)      # 0x1b568
movq 0xe00a(%rip), %rax      # 0x1b560
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 0xd564
movl %edx, (%rax,%rcx,4)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xd558
movq 0xdfc5(%rip), %rax      # 0x1b560
movq 0xdfc6(%rip), %rcx      # 0x1b568
xorl %edx, %edx
movl $0x4000, %edi           # imm = 0x4000
xorl %esi, %esi
movl $0x4000, %r8d           # imm = 0x4000
xorl %r9d, %r9d
testl %edx, %edi
setne %r9b
leal (%r9,%rsi,2), %esi
shrl $0x2, %r8d
cmpl $0x4, %edi
movl %r8d, %edi
jae 0xd5b1
movl %esi, %edi
movzwl (%rax,%rdi,4), %edi
movl %esi, %r8d
orl $0x80000000, %r8d       # imm = 0x80000000
cmpq %rdi, %rdx
cmovel %esi, %r8d
movl %r8d, (%rcx,%rdx,4)
incq %rdx
cmpq $0x10000, %rdx          # imm = 0x10000
jne 0xd5a4
movl $0x1, 0xdf61(%rip)      # 0x1b55c
addq $0x8, %rsp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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, 0xddfa(%rip)      # 0x1b588
je 0xd833
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
cmpq $0x0, 0xddeb(%rip)      # 0x1b590
jne 0xd7b8
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, 0xddd8(%rip)      # 0x1b590
cmpq $0x0, 0xddd8(%rip)      # 0x1b598
jne 0xd7d3
movl $0x1000, %edi           # imm = 0x1000
callq 0x4040
movq %rax, 0xddc5(%rip)      # 0x1b598
movq 0xddbe(%rip), %rax      # 0x1b598
xorl %ecx, %ecx
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
incq %rcx
cmpq $0x400, %rcx            # imm = 0x400
jne 0xd7dc
movq 0xdd9a(%rip), %rax      # 0x1b590
movq 0xdd9b(%rip), %rcx      # 0x1b598
xorl %edx, %edx
movl %edx, %esi
shrl $0x4, %esi
movl (%r14,%rsi,4), %esi
movl %edx, %edi
andl $0xf, %edi
shll $0x5, %esi
orl (%r14,%rdi,4), %esi
movl %esi, (%rax,%rdx,4)
movl %edx, (%rcx,%rsi,4)
incq %rdx
cmpq $0x100, %rdx            # imm = 0x100
jne 0xd7ff
movl %ebx, 0xdd5c(%rip)      # 0x1b588
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O1/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, 0xdd66(%rip)      # 0x1b5a0
je 0xd8df
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
cmpq $0x0, 0xdd57(%rip)      # 0x1b5a8
jne 0xd864
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, 0xdd44(%rip)      # 0x1b5a8
cmpq $0x0, 0xdd44(%rip)      # 0x1b5b0
jne 0xd87f
movl $0x1000, %edi           # imm = 0x1000
callq 0x4040
movq %rax, 0xdd31(%rip)      # 0x1b5b0
movq 0xdd2a(%rip), %rax      # 0x1b5b0
xorl %ecx, %ecx
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
incq %rcx
cmpq $0x400, %rcx            # imm = 0x400
jne 0xd888
movq 0xdd06(%rip), %rax      # 0x1b5a8
movq 0xdd07(%rip), %rcx      # 0x1b5b0
xorl %edx, %edx
movl %edx, %esi
shrl $0x4, %esi
movl (%r14,%rsi,4), %esi
movl %edx, %edi
andl $0xf, %edi
shll $0x5, %esi
orl (%r14,%rdi,4), %esi
movl %esi, (%rax,%rdx,4)
movl %edx, (%rcx,%rsi,4)
incq %rdx
cmpq $0x100, %rdx            # imm = 0x100
jne 0xd8ab
movl %ebx, 0xdcc8(%rip)      # 0x1b5a0
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O1/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, 0xdcd1(%rip)      # 0x1b5b8
je 0xd8ea
retq
pushq %rax
cmpq $0x0, 0xdccd(%rip)      # 0x1b5c0
jne 0xd906
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, 0xdcba(%rip)      # 0x1b5c0
cmpq $0x0, 0xdcba(%rip)      # 0x1b5c8
jne 0xd921
movl $0x40000, %edi          # imm = 0x40000
callq 0x4040
movq %rax, 0xdca7(%rip)      # 0x1b5c8
xorl %eax, %eax
movq 0xdc96(%rip), %rcx      # 0x1b5c0
xorl %edx, %edx
movl %edx, %esi
orl %eax, %esi
orl $0xaaaa, %esi           # imm = 0xAAAA
movl %esi, (%rcx,%rdx,4)
incq %rdx
subl $-0x80, %eax
cmpq $0x100, %rdx            # imm = 0x100
jne 0xd92c
movq 0xdc71(%rip), %rax      # 0x1b5c0
movq 0xdc72(%rip), %rcx      # 0x1b5c8
xorl %edx, %edx
movl %edx, %esi
andl $0x55, %esi
movl %edx, %edi
shrl $0x7, %edi
andl $0xaa, %edi
leal (%rdi,%rsi), %r8d
movzwl (%rax,%r8,4), %r9d
cmpq %r9, %rdx
leal -0x80000000(%rdi,%rsi), %esi
cmovel %r8d, %esi
movl %esi, (%rcx,%rdx,4)
incq %rdx
cmpq $0x10000, %rdx          # imm = 0x10000
jne 0xd958
movl $0x1, 0xdc20(%rip)      # 0x1b5b8
addq $0x8, %rsp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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, 0xdc2b(%rip)      # 0x1b5d0
je 0xd9a8
retq
pushq %rbx
movq %rdi, %rbx
cmpq $0x0, 0xdc24(%rip)      # 0x1b5d8
jne 0xd9c7
movl $0x80, %edi
callq 0x4040
movq %rax, 0xdc11(%rip)      # 0x1b5d8
cmpq $0x0, 0xdc11(%rip)      # 0x1b5e0
jne 0xd9e2
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, 0xdbfe(%rip)      # 0x1b5e0
movq 0xdbf7(%rip), %rax      # 0x1b5e0
xorl %ecx, %ecx
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xd9eb
movq 0xdbd3(%rip), %rax      # 0x1b5d8
movq 0xdbd4(%rip), %rcx      # 0x1b5e0
xorl %edx, %edx
movl (%rbx,%rdx,4), %esi
movl %esi, (%rax,%rdx,4)
movl %edx, (%rcx,%rsi,4)
incq %rdx
cmpq $0x20, %rdx
jne 0xda0e
movl $0x1, 0xdba6(%rip)      # 0x1b5d0
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/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, 0xdbb5(%rip)      # 0x1b5e8
je 0xda36
retq
pushq %rbx
movq %rdi, %rbx
cmpq $0x0, 0xdbae(%rip)      # 0x1b5f0
jne 0xda55
movl $0x100, %edi            # imm = 0x100
callq 0x4040
movq %rax, 0xdb9b(%rip)      # 0x1b5f0
cmpq $0x0, 0xdb9b(%rip)      # 0x1b5f8
jne 0xda70
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, 0xdb88(%rip)      # 0x1b5f8
movq 0xdb81(%rip), %rax      # 0x1b5f8
xorl %ecx, %ecx
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xda79
movq 0xdb5d(%rip), %rax      # 0x1b5f0
movq 0xdb5e(%rip), %rcx      # 0x1b5f8
xorl %edx, %edx
movl (%rbx,%rdx,4), %esi
movl %esi, (%rax,%rdx,4)
movl %edx, (%rcx,%rsi,4)
incq %rdx
cmpq $0x40, %rdx
jne 0xda9c
movl $0x1, 0xdb30(%rip)      # 0x1b5e8
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/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, 0xdb3f(%rip)      # 0x1b600
je 0xdac4
retq
pushq %rbx
movq %rdi, %rbx
cmpq $0x0, 0xdb38(%rip)      # 0x1b608
jne 0xdae3
movl $0x100, %edi            # imm = 0x100
callq 0x4040
movq %rax, 0xdb25(%rip)      # 0x1b608
cmpq $0x0, 0xdb25(%rip)      # 0x1b610
jne 0xdafe
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, 0xdb12(%rip)      # 0x1b610
movq 0xdb0b(%rip), %rax      # 0x1b610
xorl %ecx, %ecx
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xdb07
movq 0xdae7(%rip), %rax      # 0x1b608
movq 0xdae8(%rip), %rcx      # 0x1b610
xorl %edx, %edx
movl (%rbx,%rdx,4), %esi
movl %esi, (%rax,%rdx,4)
movl %edx, (%rcx,%rsi,4)
incq %rdx
cmpq $0x40, %rdx
jne 0xdb2a
movl $0x1, 0xdaba(%rip)      # 0x1b600
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/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, 0xd980(%rip)      # 0x1b630
je 0xdd46
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
cmpq $0x0, 0xd971(%rip)      # 0x1b638
jne 0xdcda
movl $0x100, %edi            # imm = 0x100
callq 0x4040
movq %rax, 0xd95e(%rip)      # 0x1b638
cmpq $0x0, 0xd95e(%rip)      # 0x1b640
jne 0xdcf5
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, 0xd94b(%rip)      # 0x1b640
movq 0xd944(%rip), %rax      # 0x1b640
xorl %ecx, %ecx
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xdcfe
movq 0xd920(%rip), %rax      # 0x1b638
movq 0xd921(%rip), %rcx      # 0x1b640
xorl %edx, %edx
movl (%r14,%rdx,4), %esi
testq %rsi, %rsi
je 0xdd30
movl %esi, (%rax,%rdx,4)
movl %edx, (%rcx,%rsi,4)
incq %rdx
cmpq $0x40, %rdx
jne 0xdd21
movl %ebx, 0xd8f1(%rip)      # 0x1b630
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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, 0xd8f9(%rip)      # 0x1b648
je 0xdd52
retq
pushq %rbx
movq %rdi, %rbx
cmpq $0x0, 0xd8f2(%rip)      # 0x1b650
jne 0xdd71
movl $0x40, %edi
callq 0x4040
movq %rax, 0xd8df(%rip)      # 0x1b650
cmpq $0x0, 0xd8df(%rip)      # 0x1b658
jne 0xdd8c
movl $0x400, %edi            # imm = 0x400
callq 0x4040
movq %rax, 0xd8cc(%rip)      # 0x1b658
movq 0xd8c5(%rip), %rax      # 0x1b658
xorl %ecx, %ecx
movl $0x80000000, (%rax,%rcx,4) # imm = 0x80000000
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0xdd95
movq 0xd8a1(%rip), %rax      # 0x1b650
movq 0xd8a2(%rip), %rcx      # 0x1b658
xorl %edx, %edx
movl (%rbx,%rdx,4), %esi
movl %esi, (%rax,%rdx,4)
movl %edx, (%rcx,%rsi,4)
incq %rdx
cmpq $0x10, %rdx
jne 0xddb8
movl $0x1, 0xd874(%rip)      # 0x1b648
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/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
testq %rdi, %rdi
setne %al
testl %esi, %esi
setns %cl
testl %edx, %edx
setg %r11b
andb %cl, %r11b
andb %al, %r11b
testl %r10d, %r8d
setns %al
testb %al, %r11b
je 0xded0
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %r9d, -0x4(%rsp)
movl %esi, %ecx
notb %cl
andb $0x7, %cl
movl $0x1, %r11d
shll %cl, %r11d
movl %esi, %eax
shrl $0x3, %eax
movzbl (%rdi,%rax), %ebp
movl %eax, %ebx
incl %ebx
incl %edx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %r9d, %r9d
xorl %r15d, %r15d
decl %edx
testl %edx, %edx
jle 0xded9
testl %r11d, %r11d
jne 0xde58
movl %ebx, %r11d
incl %ebx
movzbl (%rdi,%r11), %ebp
movl $0x80, %r11d
xorl %r12d, %r12d
testl %r11d, %ebp
setne %r12b
cmpl %r12d, %r14d
jne 0xdea1
testl %r10d, %r10d
sets %r12b
incl %r15d
testl %r14d, %r14d
setne %r13b
cmpl %r10d, %r15d
setl %cl
orb %r12b, %r13b
orb %cl, %r13b
cmpb $0x1, %r13b
jne 0xdeac
testl %r8d, %r8d
js 0xdeb6
testl %r14d, %r14d
je 0xdeb6
cmpl %r8d, %r15d
jge 0xdeac
movl $0x1, %r14d
jmp 0xdeb6
movl %r12d, %r14d
movl $0x1, %r15d
jmp 0xdeb6
cmpl $0x0, -0x4(%rsp)
je 0xdec9
incl %r9d
incl %esi
shrl %r11d
movb $0x1, %r12b
testb %r12b, %r12b
jne 0xde39
jmp 0xdee5
xorl %r12d, %r12d
movl %esi, %eax
jmp 0xdebe
xorl %eax, %eax
cmpl $0x1, %r9d
sbbl %eax, %eax
retq
xorl %eax, %eax
cmpl $0x1, -0x4(%rsp)
sbbl %eax, %eax
orl %r9d, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/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 0xdfb7
cmpb $0x0, (%r15)
je 0xdfb7
testb $0x2, %bl
leaq 0x438c(%rip), %rax      # 0x1230b
leaq 0x4381(%rip), %rcx      # 0x12307
cmoveq %rax, %rcx
testb $0x1, %bl
leaq 0x437b(%rip), %rsi      # 0x1230f
cmovneq %rcx, %rsi
movq %r15, %rdi
callq 0x4250
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0xdfb7
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_O1/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 0xe009
movq %rsi, %r14
movq (%rsi), %rsi
testq %rsi, %rsi
je 0xe009
movl %edx, %ebp
movq %rdi, %r15
xorl %r12d, %r12d
movq %r15, %rdi
movl %ebp, %edx
callq 0xdf50
testl %eax, %eax
je 0xe006
movq 0x8(%r14,%r12,8), %rsi
incq %r12
testq %rsi, %rsi
jne 0xdfe9
jmp 0xe009
movl %r12d, %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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, 0x4(%rsp)
movq %rdx, %r14
testq %rdx, %rdx
sete %dl
testq %rsi, %rsi
sete %cl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
orb %dl, %cl
jne 0xe098
movq %rsi, %r15
movq (%rsi), %rsi
testq %rsi, %rsi
je 0xe098
movq %rdi, %r12
leaq 0x1c(%rdi), %r13
xorl %ebx, %ebx
movl %ecx, %ebp
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 0x4(%rsp), %edx
callq 0xdf50
movl %ebx, %ecx
testl %eax, %eax
cmovnel %ebp, %ecx
je 0xe096
movq 0x8(%r15,%rbx,8), %rsi
incq %rbx
testq %rsi, %rsi
jne 0xe04f
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xe098
movl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0xe0dd
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 0xe0df
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %r15
movq 0x10(%rdi), %rdi
testq %rdi, %rdi
je 0xe133
movq %rdx, %rbx
movq %rsi, %r14
cmpl $0x0, 0x18(%r15)
je 0xe11a
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
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 %rdi, %r15
movq 0x10(%rdi), %rdi
testq %rdi, %rdi
je 0xe154
testb $0x1, 0xc(%r15)
jne 0xe15c
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
movq %rdx, %rbx
movq %rsi, %r14
cmpl $0x1, 0x18(%r15)
je 0xe17d
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_O1/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 0xe245
callq 0x4030
testq %rax, %rax
js 0xe245
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 0xe248
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_O1/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 0xe2e0
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 0xe2a9
cmpl $0x5c, %eax
je 0xe2a9
testl %eax, %eax
jne 0xe2c7
jmp 0xe2d4
movb $0x0, (%rsp,%r15)
movq %r14, %rdi
xorl %esi, %esi
callq 0x4350
cmpl $-0x1, %eax
jne 0xe2c7
movq %r14, %rdi
xorl %esi, %esi
callq 0x4100
movb (%rbx,%r15), %al
movb %al, (%rsp,%r15)
incq %r15
jmp 0xe294
addq $0x210, %rsp            # imm = 0x210
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0xe8f6
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 0xe76e
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_O1/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 0xe885
movq %rdi, %r14
cmpl $0x0, 0xa0(%rdi)
jle 0xe885
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 0xe81a
movl %r15d, %ebp
jmp 0xe872
addq %rcx, %r12
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0xe839
movq (%r14), %rax
movq %r14, %rdi
movq %r12, %rsi
movl 0x4(%rsp), %edx
callq *0x28(%rax)
movl %eax, %ebp
jmp 0xe848
movl $0x2, %ebp
cmpl $0x4, %eax
jne 0xe848
movl $0x1, %ebp
testl %ebx, %ebx
je 0xe856
movq %r12, %rdi
xorl %esi, %esi
callq 0xe8c0
testl %ebp, %ebp
je 0xe815
cmpl $0xe, %ebp
je 0xe864
cmpl $0x1, %ebp
jne 0xe86d
movl 0xa0(%r14), %r13d
jmp 0xe872
movl $0x2, %ebp
incl %r13d
movl %ebp, %r15d
cmpl 0xa0(%r14), %r13d
jl 0xe7fb
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_O1/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 0xe8d3
movq %rdi, %rbx
testl %esi, %esi
jne 0xe8d5
cmpl $0x0, 0x4(%rbx)
je 0xe8d5
popq %rbx
retq
movq $0x0, 0x4(%rbx)
movl $0x0, 0xc(%rbx)
movq %rbx, %rdi
callq 0xedbe
movq %rbx, %rdi
popq %rbx
jmp 0xee74
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0xe94e
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
cmpl $0x0, 0xa0(%rdi)
jle 0xe943
movl %esi, %ebx
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0xb0(%r14), %rdi
addq %r15, %rdi
movl %ebx, %esi
callq 0xe8c0
incq %r12
movslq 0xa0(%r14), %rax
addq $0x148, %r15            # imm = 0x148
cmpq %rax, %r12
jl 0xe91c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0xe9aa
movl 0x10(%rbx), %esi
movl 0x14(%rbx), %edx
movq %r14, %rdi
callq 0xe9f8
testq %rax, %rax
je 0xe99c
movl $0x148, %edx            # imm = 0x148
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4190
movq %r14, %rdi
movq %rbx, %rsi
callq 0xeb82
xorl %eax, %eax
jmp 0xe9a1
movl $0x3, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0xe9e7
xorl %ebx, %ebx
movl %edx, %r8d
orl %esi, %r8d
js 0xe9e9
cmpl %esi, 0xa4(%rdi)
jle 0xe9e9
movl 0xa8(%rdi), %edi
cmpl %edx, %edi
jle 0xe9e7
imull %esi, %edi
addl %edx, %edi
imulq $0x148, %rdi, %rdx      # imm = 0x148
addq %rdx, %rax
movq %rax, %rbx
jmp 0xe9e9
xorl %ebx, %ebx
movq %rbx, %rdi
movl %ecx, %esi
callq 0xe8c0
movq %rbx, %rax
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/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:
cmpl $0x10000, %esi          # imm = 0x10000
setae %al
cmpl $0x2, %edx
setae %cl
orb %al, %cl
je 0xea0e
xorl %eax, %eax
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
movq 0xb0(%rdi), %r15
xorl %eax, %eax
testq %r15, %r15
je 0xea59
cmpl %r14d, 0xa4(%rbx)
jle 0xea59
movl 0xa8(%rbx), %eax
cmpl %ebp, %eax
jle 0xea57
imull %r14d, %eax
addl %ebp, %eax
imulq $0x148, %rax, %rax      # imm = 0x148
addq %r15, %rax
jmp 0xea59
xorl %eax, %eax
testq %rax, %rax
jne 0xeb72
testq %r15, %r15
je 0xeb0c
movslq 0xa0(%rbx), %rax
movq %rax, 0x8(%rsp)
movl 0xa8(%rbx), %eax
imull %r14d, %eax
leal 0x7ff(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $0xfffff800, %ecx       # imm = 0xFFFFF800
addl $0x800, %ecx            # imm = 0x800
movl %ecx, 0xa0(%rbx)
movslq %ecx, %r12
sarl %ecx
movl %ecx, 0xa4(%rbx)
movl $0x148, %ecx            # imm = 0x148
movq %r12, %rax
mulq %rcx
movq $-0x1, %rdi
cmovnoq %rax, %rdi
callq 0x4040
movq %rax, %r13
movq %rax, 0xb0(%rbx)
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
jmp 0xeb56
movl $0x2, 0xa8(%rbx)
movl %r14d, %eax
andl $0xfc00, %eax           # imm = 0xFC00
leal 0x800(,%rax,2), %eax
movl %eax, 0xa0(%rbx)
imull $0x148, %eax, %r15d     # imm = 0x148
shrl %eax
movl %eax, 0xa4(%rbx)
movq %r15, %rdi
callq 0x4040
movq %rax, 0xb0(%rbx)
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x4140
imull 0xa8(%rbx), %r14d
addl %ebp, %r14d
movslq %r14d, %rax
imulq $0x148, %rax, %rax      # imm = 0x148
addq 0xb0(%rbx), %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/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 0xebaf
cmpl 0x20(%rdi), %eax
jge 0xeb93
movl %eax, 0x20(%rdi)
cmpl 0x24(%rdi), %eax
jle 0xeb9b
movl %eax, 0x24(%rdi)
movl 0x14(%rsi), %eax
cmpl 0x28(%rdi), %eax
jge 0xeba6
movl %eax, 0x28(%rdi)
cmpl 0x2c(%rdi), %eax
jle 0xebae
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_O1/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), %rax
testq %rax, %rax
je 0xec4e
xorl %r14d, %r14d
movl %edx, %ecx
orl %esi, %ecx
js 0xec51
cmpl %esi, 0xa4(%rbx)
jle 0xec51
movl 0xa8(%rbx), %ecx
cmpl %edx, %ecx
jle 0xec4e
imull %esi, %ecx
addl %edx, %ecx
imulq $0x148, %rcx, %rcx      # imm = 0x148
addq %rcx, %rax
movq %rax, %r14
jmp 0xec51
xorl %r14d, %r14d
movl $0x2, %eax
testq %r14, %r14
je 0xec80
movl (%r14), %ecx
leal -0x2(%rcx), %edx
cmpl $0x2, %edx
jae 0xec76
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq *0x28(%rax)
jmp 0xec80
cmpl $0x4, %ecx
jne 0xec80
movl $0x1, %eax
movl %eax, 0xc(%rbx)
btl $0xd, %ebp
jb 0xec94
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
// File: /workspace/github_cpp_makefile_star2_O1/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 0xece6
xorl %r14d, %r14d
movl %edx, %edi
orl %esi, %edi
js 0xece9
cmpl %esi, 0xa4(%rbx)
jle 0xece9
movl 0xa8(%rbx), %edi
cmpl %edx, %edi
jle 0xece6
imull %esi, %edi
addl %edx, %edi
imulq $0x148, %rdi, %rdx      # imm = 0x148
addq %rdx, %rax
movq %rax, %r14
jmp 0xece9
xorl %r14d, %r14d
movl %r8d, 0xc8(%r14)
movl %r9d, 0xcc(%r14)
movl $0x2, %eax
testq %r14, %r14
je 0xed2c
movl (%r14), %edx
leal -0x2(%rdx), %esi
cmpl $0x2, %esi
jae 0xed22
orl $0x80000000, %ecx       # imm = 0x80000000
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
movl %ecx, %edx
callq *0x28(%rax)
jmp 0xed2c
cmpl $0x4, %edx
jne 0xed2c
movl $0x1, %eax
movl %eax, 0xc(%rbx)
xorl %ecx, %ecx
testl %eax, %eax
cmoveq %r14, %rcx
movq %rcx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O1/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 0xedbd
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebp
movq %rdi, %rbx
callq 0xedbe
testl %ebp, %ebp
je 0xeda8
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