LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/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 0xc22a
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 0xc1f3
cmpl $0x5c, %eax
je 0xc1f3
testl %eax, %eax
jne 0xc211
jmp 0xc21e
movb $0x0, (%rsp,%r15)
movq %r14, %rdi
xorl %esi, %esi
callq 0x3350
cmpl $-0x1, %eax
jne 0xc211
movq %r14, %rdi
xorl %esi, %esi
callq 0x30d0
movb (%rbx,%r15), %al
movb %al, (%rsp,%r15)
incq %r15
jmp 0xc1de
addq $0x210, %rsp            # imm = 0x210
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x1
popq %rbp
movl %ebp, %esi
callq 0xc750
leaq 0x8(%rbx), %rdi
movl $0x98, %edx
xorl %esi, %esi
callq 0x3110
movl %ebp, 0x14(%rbx)
movl %ebp, 0x1c(%rbx)
andl $0x0, 0xa0(%rbx)
movq 0xb0(%rbx), %rdi
testq %rdi, %rdi
je 0xc60e
callq 0x3250
andq $0x0, 0xb0(%rbx)
andq $0x0, 0xa4(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 %edx, 0x4(%rsp)
cmpq $0x0, 0xb0(%rdi)
je 0xc6e4
movl %esi, %ebp
movq %rdi, %r14
xorl %ebx, %ebx
xorl %r15d, %r15d
cmpl 0xa0(%r14), %ebx
jge 0xc6e7
movq 0xb0(%r14), %r13
movslq %ebx, %rax
imulq $0x148, %rax, %rax      # imm = 0x148
cmpl $0x2, (%r13,%rax)
jb 0xc6e0
addq %rax, %r13
movq %r14, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0xc6fa
movl %eax, %r12d
cmpl $0x0, 0x4(%rsp)
je 0xc6bf
movq %r13, %rdi
xorl %esi, %esi
callq 0xc720
testl %r12d, %r12d
je 0xc6e0
cmpl $0xe, %r12d
je 0xc6d0
cmpl $0x1, %r12d
jne 0xc6dc
movl 0xa0(%r14), %ebx
movl %r12d, %r15d
jmp 0xc6e0
pushq $0x2
popq %r15
incl %ebx
jmp 0xc679
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/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 0xc733
movq %rdi, %rbx
testl %esi, %esi
jne 0xc735
cmpl $0x0, 0x4(%rbx)
je 0xc735
popq %rbx
retq
andq $0x0, 0x4(%rbx)
andl $0x0, 0xc(%rbx)
movq %rbx, %rdi
callq 0xcb16
movq %rbx, %rdi
popq %rbx
jmp 0xcb8a
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 0xc7a1
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
xorl %r15d, %r15d
xorl %r12d, %r12d
movslq 0xa0(%r14), %rax
cmpq %rax, %r12
jge 0xc796
movq 0xb0(%r14), %rdi
addq %r15, %rdi
movl %ebx, %esi
callq 0xc720
incq %r12
addq $0x148, %r15            # imm = 0x148
jmp 0xc76d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x1
popq %rcx
callq 0xc7f8
movl 0x10(%rbx), %esi
movl 0x14(%rbx), %edx
movq %r14, %rdi
callq 0xc81c
testq %rax, %rax
je 0xc7ec
movl $0x148, %edx            # imm = 0x148
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3160
movq %r14, %rdi
movq %rbx, %rsi
callq 0xc980
xorl %eax, %eax
jmp 0xc7ef
pushq $0x3
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/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 0xc832
xorl %eax, %eax
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r14
callq 0xc9c4
testq %rax, %rax
jne 0xc970
movq 0xb0(%r14), %rsi
testq %rsi, %rsi
je 0xc90d
movslq 0xa0(%r14), %rax
movq %rax, 0x10(%rsp)
movl 0xa8(%r14), %eax
imull %ebp, %eax
movl $0x800, %ecx            # imm = 0x800
cltd
idivl %ecx
shll $0xb, %eax
addl %ecx, %eax
movl %eax, 0xa0(%r14)
movslq %eax, %r12
sarl %eax
movl %eax, 0xa4(%r14)
movl $0x148, %ecx            # imm = 0x148
movq %r12, %rax
mulq %rcx
movq %rsi, 0x8(%rsp)
pushq $-0x1
popq %rdi
cmovnoq %rax, %rdi
callq 0x3040
movq %rax, %r13
movq %rax, 0xb0(%r14)
imulq $0x148, 0x10(%rsp), %r15 # imm = 0x148
movq %rax, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x3160
addq %r15, %r13
subq 0x10(%rsp), %r12
imulq $0x148, %r12, %rdx      # imm = 0x148
movq %r13, %rdi
xorl %esi, %esi
callq 0x3110
movq 0x8(%rsp), %rdi
callq 0x3250
movq 0xb0(%r14), %r15
movl 0xa8(%r14), %eax
jmp 0xc95f
movl $0x2, 0xa8(%r14)
movl %ebp, %eax
andl $0xfc00, %eax           # imm = 0xFC00
leal 0x800(,%rax,2), %eax
movl %eax, 0xa0(%r14)
imull $0x148, %eax, %r12d     # imm = 0x148
shrl %eax
movl %eax, 0xa4(%r14)
movq %r12, %rdi
callq 0x3040
movq %rax, %r15
movq %rax, 0xb0(%r14)
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x3110
pushq $0x2
popq %rax
imull %ebp, %eax
addl %ebx, %eax
cltq
imulq $0x148, %rax, %rax      # imm = 0x148
addq %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_O2/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 0xc9ad
cmpl 0x20(%rdi), %eax
jge 0xc991
movl %eax, 0x20(%rdi)
cmpl 0x24(%rdi), %eax
jle 0xc999
movl %eax, 0x24(%rdi)
movl 0x14(%rsi), %eax
cmpl 0x28(%rdi), %eax
jge 0xc9a4
movl %eax, 0x28(%rdi)
cmpl 0x2c(%rdi), %eax
jle 0xc9ac
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_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::GetTrack(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:
movq 0xb0(%rdi), %rcx
testq %rcx, %rcx
je 0xc9ff
xorl %eax, %eax
movl %edx, %r8d
orl %esi, %r8d
js 0xc9fe
cmpl %esi, 0xa4(%rdi)
jle 0xc9fe
movl 0xa8(%rdi), %eax
cmpl %edx, %eax
jle 0xc9ff
imull %esi, %eax
addl %edx, %eax
imulq $0x148, %rax, %rax      # imm = 0x148
addq %rax, %rcx
movq %rcx, %rax
retq
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O2/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)
callq 0xc9c4
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movl %ebp, %edx
callq 0xc6fa
movl %eax, 0xc(%rbx)
btl $0xd, %ebp
jb 0xca3a
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_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %r9d, %ebx
movl %r8d, %ebp
movl %ecx, %r14d
movq %rdi, %r15
callq 0xc9c4
movq %rax, %r12
movl %ebp, 0xc8(%rax)
movl %ebx, 0xcc(%rax)
orl $0x80000000, %r14d      # imm = 0x80000000
movq %r15, %rdi
movq %rax, %rsi
movl %r14d, %edx
callq 0xc6fa
movl %eax, 0xc(%r15)
xorl %ecx, %ecx
testl %eax, %eax
cmoveq %r12, %rcx
movq %rcx, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/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
je 0xcab9
pushq $0x2
popq %rax
retq
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebp
movq %rdi, %rbx
callq 0xcb16
testl %ebp, %ebp
je 0xcb02
movl $0x1, 0x28(%rbx)
movl %ebp, 0x50(%rbx)
movl %ebp, %r14d
movq %r14, %rdi
callq 0x3040
movq %rax, 0x48(%rbx)
movq %rax, 0x58(%rbx)
movl %ebp, 0x80(%rbx)
andl $0x0, 0x94(%rbx)
movq %rax, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x3110
movq $0x1, 0x4(%rbx)
andl $0x0, 0xc(%rbx)
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::FreeTrackData(DiskTrackInfo*)
void CDiskImage::FreeTrackData(PDISKTRACKINFO pti)
{
	// cancel if invalid track data
	if (!pti)
		return;

	if (pti->rawdump)
		delete[] pti->trackdata[0];

	// clear track data
	for (int trk=0; trk < CAPS_MTRS; trk++) {
		pti->trackdata[trk]=NULL;
		pti->tracksize[trk]=0;
	}

	// free track buffer
	pti->trackcnt=0;

	if (!pti->rawdump)
		delete[] pti->trackbuf;

	pti->trackbuf=NULL;
	pti->tracklen=0;

	// free data specific buffers
	FreeTrackFD(pti);
	FreeTrackSI(pti);
}

// Assembly:
testq %rdi, %rdi
je 0xcb80
pushq %rbx
movq %rdi, %rbx
cmpl $0x0, 0x44(%rdi)
je 0xcb33
movq 0x58(%rbx), %rdi
testq %rdi, %rdi
je 0xcb33
callq 0x3250
pushq $0x20
popq %rax
cmpq $0x25, %rax
je 0xcb4e
andq $0x0, -0xa8(%rbx,%rax,8)
andl $0x0, (%rbx,%rax,4)
incq %rax
jmp 0xcb36
andl $0x0, 0x28(%rbx)
cmpl $0x0, 0x44(%rbx)
jne 0xcb66
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0xcb66
callq 0x3250
andq $0x0, 0x48(%rbx)
andl $0x0, 0x50(%rbx)
movq %rbx, %rdi
callq 0xcbcc
movq %rbx, %rdi
popq %rbx
jmp 0xcbf8
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::FreeTrackTiming(DiskTrackInfo*)
void CDiskImage::FreeTrackTiming(PDISKTRACKINFO pti)
{
	// cancel if invalid track data
	if (!pti)
		return;

	// free timing buffer
	pti->timecnt=0;
	delete [] pti->timebuf;
	pti->timebuf=NULL;

	// free raw timing buffer
	pti->rawtimecnt = 0;
	delete[] pti->rawtimebuf;
	pti->rawtimebuf = NULL;
}

// Assembly:
testq %rdi, %rdi
je 0xcbcb
pushq %rbx
movq %rdi, %rbx
andl $0x0, 0xa8(%rdi)
movq 0xb0(%rdi), %rdi
testq %rdi, %rdi
je 0xcbab
callq 0x3250
andq $0x0, 0xb0(%rbx)
andl $0x0, 0x34(%rbx)
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0xcbc5
callq 0x3250
andq $0x0, 0x38(%rbx)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::FreeTrackFD(DiskTrackInfo*)
void CDiskImage::FreeTrackFD(PDISKTRACKINFO pti)
{
	// cancel if invalid track data
	if (!pti)
		return;

	// free flakey buffer
	pti->fdpsize=0;
	pti->fdpmax=0;
	delete [] pti->fdp;
	pti->fdp=NULL;
}

// Assembly:
testq %rdi, %rdi
je 0xcbf7
pushq %rbx
movq %rdi, %rbx
andq $0x0, 0xd0(%rdi)
movq 0xd8(%rdi), %rdi
testq %rdi, %rdi
je 0xcbee
callq 0x3250
andq $0x0, 0xd8(%rbx)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::FreeTrackSI(DiskTrackInfo*)
void CDiskImage::FreeTrackSI(PDISKTRACKINFO pti)
{
	// cancel if invalid track data
	if (!pti)
		return;

	// free sector info buffer
	pti->sipsize=0;
	delete [] pti->sip;
	pti->sip=NULL;
}

// Assembly:
testq %rdi, %rdi
je 0xcc22
pushq %rbx
movq %rdi, %rbx
andl $0x0, 0xf4(%rdi)
movq 0xf8(%rdi), %rdi
testq %rdi, %rdi
je 0xcc19
callq 0x3250
andq $0x0, 0xf8(%rbx)
popq %rbx
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::CreateDateTime(CapsDateTime*)
void CDiskImage::CreateDateTime(PCAPSDATETIME pcd)
{
	// cancel on error
	if (!pcd)
		return;

	// read OS time, since time_t won't work in a few decades... :)
	SYSTEMTIME st;
	GetLocalTime(&st);

	// create date
	UDWORD t=0;
	t+=st.wYear*10000;
	t+=st.wMonth*100;
	t+=st.wDay;
	pcd->date=t;

	// create time
	t=0;
	t+=st.wHour*10000000;
	t+=st.wMinute*100000;
	t+=st.wSecond*1000;
	t+=st.wMilliseconds%1000;
	pcd->time=t;
}

// Assembly:
testq %rdi, %rdi
je 0xcc9f
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0xea8b
movzwl (%r14), %eax
imull $0x2710, %eax, %eax     # imm = 0x2710
movzwl 0x2(%r14), %ecx
imull $0x64, %ecx, %ecx
addl %eax, %ecx
movzwl 0x6(%r14), %eax
addl %ecx, %eax
movl %eax, (%rbx)
movzwl 0x8(%r14), %eax
imull $0x989680, %eax, %eax   # imm = 0x989680
movzwl 0xa(%r14), %ecx
imull $0x186a0, %ecx, %ecx    # imm = 0x186A0
addl %eax, %ecx
movzwl 0xc(%r14), %eax
imull $0x3e8, %eax, %esi      # imm = 0x3E8
movzwl 0xe(%r14), %eax
movw $0x3e8, %di             # imm = 0x3E8
xorl %edx, %edx
divw %di
movzwl %dx, %eax
addl %esi, %eax
addl %ecx, %eax
movl %eax, 0x4(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::DecodeDateTime(CapsDateTimeExt*, CapsDateTime*)
void CDiskImage::DecodeDateTime(PCAPSDATETIMEEXT dec, PCAPSDATETIME pcd)
{
	// cancel if no result buffer
	if (!dec)
		return;

	// clear result
	memset(dec, 0, sizeof(CapsDateTimeExt));

	// cancel if no source
	if (!pcd)
		return;

	// decode date
	UDWORD t=pcd->date;
	dec->year=t/10000;
	t%=10000;
	dec->month=t/100;
	t%=100;
	dec->day=t;

	// decode time;
	t=pcd->time;
	dec->hour=t/10000000;
	t%=10000000;
	dec->min=t/100000;
	t%=100000;
	dec->sec=t/1000;
	t%=1000;
	dec->tick=t;
}

// Assembly:
testq %rdi, %rdi
je 0xcd06
xorps %xmm0, %xmm0
movups %xmm0, 0xc(%rdi)
movups %xmm0, (%rdi)
testq %rsi, %rsi
je 0xcd06
movl (%rsi), %eax
movl $0x2710, %ecx           # imm = 0x2710
xorl %edx, %edx
divl %ecx
movl %eax, (%rdi)
movw $0x64, %cx
movl %edx, %eax
xorl %edx, %edx
divw %cx
movzwl %ax, %eax
movl %eax, 0x4(%rdi)
movzwl %dx, %eax
movl %eax, 0x8(%rdi)
movl 0x4(%rsi), %eax
movl $0x989680, %ecx         # imm = 0x989680
xorl %edx, %edx
divl %ecx
movl %eax, 0xc(%rdi)
movl $0x186a0, %ecx          # imm = 0x186A0
movl %edx, %eax
xorl %edx, %edx
divl %ecx
movl %eax, 0x10(%rdi)
movl $0x3e8, %ecx            # imm = 0x3E8
movl %edx, %eax
xorl %edx, %edx
divl %ecx
movl %eax, 0x14(%rdi)
movl %edx, 0x18(%rdi)
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::CrcFile(CapsFile*)
UDWORD CDiskImage::CrcFile(PCAPSFILE pcf)
{
	UDWORD crc=0;

	// shortcut for memory files
	if (pcf->flag & CFF_MEMMAP) {
		if (!pcf->memmap || pcf->size<0)
			return crc;

		return CalcCRC(pcf->memmap, pcf->size);
	}

	// open file
	CCapsFile file;
	if (file.Open(pcf))
		return crc;

	int len=file.GetSize();

	if (len) {
		int bufsize=DEF_CRCBUF;
		PUBYTE buf=new UBYTE[bufsize];

		// calculate CRC32 on file
		while (len) {
			int size=len > bufsize ? bufsize : len;
			if (file.Read(buf, size) != size) {
				crc=0;
				break;
			}

			crc=CalcCRC32(buf, size, crc);
			len-=size;
		}

		delete [] buf;
	}

	return crc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
testb $0x2, 0x10(%rdi)
jne 0xcdc1
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x6f10
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6f88
xorl %ebx, %ebx
testl %eax, %eax
jne 0xcdf1
leaq 0x8(%rsp), %rdi
callq 0x707e
movl %eax, %ebp
testl %eax, %eax
je 0xcdf1
movl $0x10000, %edi          # imm = 0x10000
callq 0x3040
movq %rax, %r14
xorl %ebx, %ebx
movl $0x10000, %r13d         # imm = 0x10000
leaq 0x8(%rsp), %r15
testl %ebp, %ebp
je 0xcde9
cmpl %r13d, %ebp
movl $0x10000, %r12d         # imm = 0x10000
cmovll %ebp, %r12d
movq %r15, %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x703c
cmpl %r12d, %eax
jne 0xcde7
movq %r14, %rdi
movl %r12d, %esi
movl %ebx, %edx
callq 0x3f6e
movl %eax, %ebx
subl %r12d, %ebp
jmp 0xcd89
movq 0x8(%r14), %rdi
xorl %ebx, %ebx
testq %rdi, %rdi
je 0xcdfb
movl 0x14(%r14), %esi
testl %esi, %esi
js 0xcdfb
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3f42
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x3250
leaq 0x8(%rsp), %rdi
callq 0x6f20
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xce12
jmp 0xce12
jmp 0xce12
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x6f20
movq %rbx, %rdi
callq 0x3380
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::ReadValue(unsigned char*, int)
UDWORD CDiskImage::ReadValue(PUBYTE buf, int cnt)
{
	UDWORD val;

	for (val=0; cnt > 0; cnt--) {
		val<<=8;
		val|=*buf++;
	}

	return val;
}

// Assembly:
xorl %eax, %eax
testl %esi, %esi
jle 0xce3d
shll $0x8, %eax
movzbl (%rdi), %ecx
incq %rdi
orl %ecx, %eax
decl %esi
jmp 0xce2a
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::AddFD(DiskTrackInfo*, DiskDataMark*, int, int)
PDISKDATAMARK CDiskImage::AddFD(PDISKTRACKINFO pti, PDISKDATAMARK src, int size, int units)
{
	// cancel if nothing to add
	if (!src || size<=0)
		return NULL;

	// allocate and copy to buffer
	PDISKDATAMARK alloc=AllocFD(pti, size, units);
	if (alloc)
		memcpy(alloc, src, size*sizeof(DiskDataMark));

	return alloc;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %edx, %ebp
testq %rsi, %rsi
sete %al
testl %edx, %edx
setle %dl
orb %al, %dl
jne 0xce7a
movq %rsi, %rbx
movl %ebp, %esi
movl %ecx, %edx
callq 0xce84
testq %rax, %rax
je 0xce7a
movl %ebp, %ecx
imulq $0xc, %rcx, %rdx
movq %rax, %rdi
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x3160
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::AllocFD(DiskTrackInfo*, int, int)
PDISKDATAMARK CDiskImage::AllocFD(PDISKTRACKINFO pti, int size, int units)
{
	// cancel if invalid allocation
	if (!pti)
		return NULL;

	// get buffer mark
	if (size <= 0)
		return pti->fdp+pti->fdpsize;

	// grow buffer if necessary
	if (pti->fdpsize+size > pti->fdpmax) {
		units+=pti->fdpsize+size;
		PDISKDATAMARK fdp=pti->fdp;
		pti->fdp=new DiskDataMark[units];
		if (pti->fdpsize)
			memcpy(pti->fdp, fdp, pti->fdpsize*sizeof(DiskDataMark));
		delete [] fdp;
		pti->fdpmax=units;
	}

	// allocate new data
	PDISKDATAMARK alloc=pti->fdp+pti->fdpsize;
	memset(alloc, 0, size*sizeof(DiskDataMark));
	pti->fdpsize+=size;
	return alloc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testq %rdi, %rdi
je 0xcf34
movl %esi, %r14d
movq %rdi, %rbx
testl %esi, %esi
jle 0xcf39
movl 0xd0(%rbx), %r12d
leal (%r12,%r14), %ebp
cmpl 0xd4(%rbx), %ebp
jle 0xcf0c
addl %edx, %ebp
movq 0xd8(%rbx), %r15
movslq %ebp, %rax
pushq $0xc
popq %rcx
mulq %rcx
pushq $-0x1
popq %rdi
cmovnoq %rax, %rdi
callq 0x3040
movq %rax, 0xd8(%rbx)
testl %r12d, %r12d
je 0xcef2
movslq %r12d, %rcx
imulq $0xc, %rcx, %rdx
movq %rax, %rdi
movq %r15, %rsi
callq 0x3160
testq %r15, %r15
je 0xcf06
movq %r15, %rdi
callq 0x3250
movl 0xd0(%rbx), %r12d
movl %ebp, 0xd4(%rbx)
movslq %r12d, %rax
imulq $0xc, %rax, %r15
addq 0xd8(%rbx), %r15
movl %r14d, %eax
imulq $0xc, %rax, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x3110
addl %r14d, 0xd0(%rbx)
jmp 0xcf4b
xorl %r15d, %r15d
jmp 0xcf4b
movslq 0xd0(%rbx), %rax
imulq $0xc, %rax, %r15
addq 0xd8(%rbx), %r15
movq %r15, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::AllocTrackSI(DiskTrackInfo*)
void CDiskImage::AllocTrackSI(PDISKTRACKINFO pti)
{
	// cancel if invalid allocation
	if (!pti)
		return;

	FreeTrackSI(pti);

	// allocate buffer if needed
	if (pti->sectorcnt > 0) {
		int size=pti->sectorcnt;
		pti->sip=new DiskSectorInfo[size];
		pti->sipsize=size;
		memset(pti->sip, 0, size*sizeof(DiskSectorInfo));
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
testq %rdi, %rdi
je 0xcf9f
movq %rdi, %rbx
callq 0xcbf8
movslq 0x18(%rbx), %r15
testq %r15, %r15
jle 0xcf9f
imulq $0x30, %r15, %r14
movq %r14, %rdi
callq 0x3040
movq %rax, 0xf8(%rbx)
movl %r15d, 0xf4(%rbx)
movq %rax, %rdi
xorl %esi, %esi
movq %r14, %rdx
popq %rbx
popq %r14
popq %r15
jmp 0x3110
popq %rbx
popq %r14
popq %r15
retq
nopl (%rax)
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImageFactory.cpp
// Function: CDiskImageFactory::GetImageType(CapsFile*)
int CDiskImageFactory::GetImageType(PCAPSFILE pcf)
{
	// error if file cannot be opened
	CCapsFile file;
	if (file.Open(pcf))
		return citError;

	// check IPF or CT Raw
	int type = IsCAPSImage(pcf);
	if (type != citUnknown)
		return type;

	// check KryoFlux stream cue
	type = IsKFStreamCue(pcf);
	if (type != citUnknown)
		return type;

	// check KryoFlux stream
	type = IsKFStream(pcf);
	if (type != citUnknown)
		return type;

	// at this point it's none of the supported image types
	return citUnknown;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movq %rsp, %r14
movq %r14, %rdi
callq 0x6f10
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6f88
xorl %ebp, %ebp
testl %eax, %eax
jne 0xd02f
movq %rbx, %rdi
callq 0xd058
movl %eax, %ebp
cmpl $0x1, %eax
jne 0xd02f
movq %rbx, %rdi
callq 0xd0d4
movl %eax, %ebp
cmpl $0x1, %eax
jne 0xd02f
movq %rbx, %rdi
callq 0xd17a
movl %eax, %ebp
movq %rsp, %rdi
callq 0x6f20
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0xd044
movq %rax, %rbx
movq %rsp, %rdi
callq 0x6f20
movq %rbx, %rdi
callq 0x3380
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImageFactory.cpp
// Function: CDiskImageFactory::IsCAPSImage(CapsFile*)
int CDiskImageFactory::IsCAPSImage(PCAPSFILE pcf)
{
	// try to parse CT Raw or IPF
	CCapsLoader cload;
	int res = cload.Lock(pcf);

	// parser succeeded, check type in more detail
	if (res == CCapsLoader::ccidCaps) {
		for (int run = 1; run;) {
			// read the next chunk after the header
			int type = cload.ReadChunk();

			switch (type) {
				// end of file or error
				case CCapsLoader::ccidEof:
				case CCapsLoader::ccidErrFile:
				case CCapsLoader::ccidErrType:
				case CCapsLoader::ccidErrShort:
				case CCapsLoader::ccidErrHeader:
				case CCapsLoader::ccidErrData:
					run = 0;
					continue;

				// track header is used by CT Raw
				case CCapsLoader::ccidTrck:
					return citCTRaw;

				// track image is used by IPF
				case CCapsLoader::ccidImge:
					return citIPF;

				// ignore other types
				default:
					continue;
			}
		}
	}

	// unknown or unsupported image type
	return citUnknown;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0xe8, %rsp
movq %rdi, %rbx
movq %rsp, %r14
movq %r14, %rdi
callq 0xaddc
movq %r14, %rdi
movq %rbx, %rsi
callq 0xae86
pushq $0x1
popq %rbx
testl %eax, %eax
je 0xd097
movq %rsp, %rdi
callq 0xae46
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r14
retq
movq %rsp, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0xaef0
leal -0x1(%rax), %ecx
cmpl $0x6, %ecx
jb 0xd082
cmpl $0xb, %eax
je 0xd0ba
cmpl $0xd, %eax
jne 0xd09a
pushq $0x2
jmp 0xd0bc
pushq $0x3
popq %rbx
jmp 0xd082
jmp 0xd0c1
movq %rax, %rbx
movq %rsp, %rdi
callq 0xae46
movq %rbx, %rdi
callq 0x3380
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImageFactory.cpp
// Function: CDiskImageFactory::IsKFStreamCue(CapsFile*)
int CDiskImageFactory::IsKFStreamCue(PCAPSFILE pcf)
{
	// error if file can't be opened
	CCapsFile file;
	if (file.Open(pcf))
		return citError;

	// the ID string must be within this area from the beginning of the file
	uint8_t buf[256];

	// remaining file size
	int frem = file.GetSize();

	// buffer allowed, with room for terminating 0
	int bufmax = sizeof(buf)-1;

	int readsize = std::min(frem, bufmax);

	// read from the beginning of the file, stop on error
	if (file.Read(buf, readsize) != readsize)
		return citError;

	// add terminating 0
	buf[readsize] = 0;

	// success, if ID text found in info
	if (strstr((char *)buf, KF_STREAM_CUE_ID))
		return citKFStreamCue;

	// unknown or unsupported image type
	return citUnknown;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x110, %rsp            # imm = 0x110
movq %rdi, %rbx
movq %rsp, %r14
movq %r14, %rdi
callq 0x6f10
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6f88
xorl %ebp, %ebp
testl %eax, %eax
jne 0xd14d
movq %rsp, %rdi
callq 0x707e
movl $0xff, %ebx
cmpl %ebx, %eax
cmovll %eax, %ebx
movq %rsp, %rdi
leaq 0x10(%rsp), %rsi
movl %ebx, %edx
callq 0x703c
xorl %ebp, %ebp
cmpl %ebx, %eax
jne 0xd14d
movslq %ebx, %rax
movb $0x0, 0x10(%rsp,%rax)
leaq 0x228d(%rip), %rsi      # 0xf3c1
leaq 0x10(%rsp), %rdi
callq 0x3070
xorl %ecx, %ecx
testq %rax, %rax
setne %cl
leal 0x1(,%rcx,4), %ebp
movq %rsp, %rdi
callq 0x6f20
movl %ebp, %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbx
popq %r14
popq %rbp
retq
jmp 0xd167
jmp 0xd167
movq %rax, %rbx
movq %rsp, %rdi
callq 0x6f20
movq %rbx, %rdi
callq 0x3380
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImageFactory.cpp
// Function: CDiskImageFactory::IsKFStream(CapsFile*)
int CDiskImageFactory::IsKFStream(PCAPSFILE pcf)
{
	// error if file can't be opened
	CCapsFile file;
	if (file.Open(pcf))
		return citError;

	C2OOBHdr oob;
	uint8_t buf[512];

	// remaining file size
	int frem = file.GetSize();

	// process the file as long as the data read is an OOB info area
	while (true) {
		// stop if OOB header is longer than the remaining file size
		int rlen = sizeof(oob);
		if (rlen > frem)
			break;

		// read OOB header, stop on error
		if (file.Read((PUBYTE)&oob, rlen) != rlen)
			return citError;

		// update the remaining file size
		frem -= rlen;

		// check that OOB is Info
		if (oob.sign != c2eOOB || oob.type != c2otInfo)
			break;

		// read info size value as little-endian
		uint8_t *po = (uint8_t *)&oob;
		int so = offsetof(C2OOBHdr, size);
		int infosize = po[so+1] << 8 | po[so];

		// stop if info size is 0 or larger than remaining file size or larger than the buffer
		if (!infosize || infosize > frem || infosize > sizeof(buf))
			break;
		
		// read info, stop on error
		if (file.Read(buf, infosize) != infosize)
			return citError;

		// update the remaining file size
		frem -= infosize;

		// success, if KryoFlux text found in info
		if (strstr((char *)buf, "KryoFlux"))
			return citKFStream;
	}

	// file reading stopped somewhere, type is unknown
	return citUnknown;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdi, %rbx
movq %rsp, %r14
movq %r14, %rdi
callq 0x6f10
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6f88
xorl %ebp, %ebp
testl %eax, %eax
jne 0xd238
movq %rsp, %rdi
callq 0x707e
movl %eax, %ebx
movq %rsp, %r14
pushq $0x10
popq %r12
leaq 0x20(%rsp), %r13
xorl %ebp, %ebp
cmpl $0x10, %ebx
jl 0xd235
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
movl %r12d, %edx
callq 0x703c
cmpl $0x10, %eax
jne 0xd238
cmpb $0xd, 0x10(%rsp)
jne 0xd235
cmpb $0x4, 0x11(%rsp)
jne 0xd235
movzwl 0x12(%rsp), %r15d
testl %r15d, %r15d
je 0xd235
addl $-0x10, %ebx
subl %r15d, %ebx
jb 0xd235
cmpl $0x200, %r15d           # imm = 0x200
ja 0xd235
movq %r14, %rdi
movq %r13, %rsi
movl %r15d, %edx
callq 0x703c
cmpl %r15d, %eax
jne 0xd238
movq %r13, %rdi
leaq 0x2191(%rip), %rsi      # 0xf3b8
callq 0x3070
testq %rax, %rax
je 0xd1c6
pushq $0x4
jmp 0xd237
pushq $0x1
popq %rbp
movq %rsp, %rdi
callq 0x6f20
movl %ebp, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xd25a
jmp 0xd25a
jmp 0xd25a
movq %rax, %rbx
movq %rsp, %rdi
callq 0x6f20
movq %rbx, %rdi
callq 0x3380
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImageFactory.cpp
// Function: CDiskImageFactory::CreateImage(int)
PCDISKIMAGE CDiskImageFactory::CreateImage(int diftype)
{
	PCDISKIMAGE pdi = NULL;

	// create the image class required
	switch (diftype) {
		case citIPF:
			pdi = new CCapsImageStd;
			break;

		case citCTRaw:
			pdi = new CCapsImage;
			break;

		case citKFStream:
			pdi = new CStreamImage;
			break;

		case citKFStreamCue:
			pdi = new CStreamCueImage;
			break;
	}

	return pdi;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
addl $-0x2, %edi
cmpl $0x3, %edi
ja 0xd2e6
leaq 0x2113(%rip), %rax      # 0xf394
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl $0x230, %edi            # imm = 0x230
callq 0x31e0
movq %rax, %rbx
movq %rax, %rdi
callq 0x7e88
jmp 0xd2e8
movl $0xb8, %edi
callq 0x31e0
movq %rax, %rbx
movq %rax, %rdi
callq 0xe814
jmp 0xd2e8
movl $0xb8, %edi
callq 0x31e0
movq %rax, %rbx
movq %rax, %rdi
callq 0xe7d8
jmp 0xd2e8
movl $0x230, %edi            # imm = 0x230
callq 0x31e0
movq %rax, %rbx
movq %rax, %rdi
callq 0xd31a
jmp 0xd2e8
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
jmp 0xd2f5
movq %rax, %r14
movl $0x230, %esi            # imm = 0x230
jmp 0xd309
jmp 0xd301
movq %rax, %r14
movl $0xb8, %esi
movq %rbx, %rdi
callq 0x31f0
movq %r14, %rdi
callq 0x3380
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/MemoryFile.cpp
// Function: CMemoryFile::Open(void*, unsigned long, unsigned int)
int CMemoryFile::Open(void *buf, size_t size, unsigned int mode)
{
	// reset buffers
	Clear(0);

	// create new buffer or reference user supplied buffer
	if (mode & BFFLAG_CREATE) {
		// create new buffer
		if (size) {
			// allocate initial buffer with the size specified when opening the file
			AllocBuffer(size);

			// copy buffer content if specified
			if (buf) {
				memcpy(filebuf[mtAlloc], buf, size*sizeof(uint8_t));
				filecount=size;
			}
		}

		// set class owned buffer
		filemt=mtAlloc;
	} else {
		// reference user supplied buffer
		if (size) {
			// error if buffer size is defined, but area is not
			if (!buf)
				return 1;
		} else
			buf=NULL;

		// set user buffer reference
		filemt=mtUser;
		filebuf[mtUser]=(uint8_t *)buf;
		filesize[mtUser]=size;
		filecount=size;
	}

	// rewind stream position
	filepos=0;

	// success
	fileopen=1;
	filemode=mode;

	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
xorl %esi, %esi
callq 0xd370
testb $0x2, %bl
jne 0xd410
testq %r15, %r15
je 0xd43f
testq %r12, %r12
jne 0xd442
pushq $0x1
popq %rax
jmp 0xd469
testq %r15, %r15
je 0xd438
movq %r14, %rdi
movq %r15, %rsi
callq 0xd476
testq %r12, %r12
je 0xd438
movq 0x18(%r14), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x3160
movq %r15, 0x38(%r14)
andl $0x0, 0x10(%r14)
jmp 0xd456
xorl %r12d, %r12d
movl $0x1, 0x10(%r14)
movq %r12, 0x20(%r14)
movq %r15, 0x30(%r14)
movq %r15, 0x38(%r14)
andq $0x0, 0x40(%r14)
movl $0x1, 0x8(%r14)
movl %ebx, 0xc(%r14)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/MemoryFile.cpp
// Function: CMemoryFile::AllocBuffer(unsigned long)
void CMemoryFile::AllocBuffer(size_t maxsize)
{
	if (filesize[mtAlloc] < maxsize) {
		maxsize+=DEF_MEMORYFILEALLOC;
		uint8_t *newfile=new uint8_t[maxsize];
		size_t oldcount=filecount;
		size_t oldpos=filepos;

		if (oldcount)
			memcpy(newfile, filebuf[mtAlloc], oldcount*sizeof(uint8_t));

		FreeBuffer();

		filebuf[mtAlloc]=newfile;
		filesize[mtAlloc]=maxsize;
		filecount=oldcount;
		filepos=oldpos;
	}
}

// Assembly:
cmpq %rsi, 0x28(%rdi)
jae 0xd4dd
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
addq $0x200, %rbx            # imm = 0x200
movq %rbx, %rdi
callq 0x3040
movq %rax, %r15
movups 0x38(%r14), %xmm0
movaps %xmm0, (%rsp)
movq 0x38(%r14), %rdx
testq %rdx, %rdx
je 0xd4bb
movq 0x18(%r14), %rsi
movq %r15, %rdi
callq 0x3160
movq %r14, %rdi
callq 0xd4f8
movq %r15, 0x18(%r14)
movq %rbx, 0x28(%r14)
movaps (%rsp), %xmm0
movups %xmm0, 0x38(%r14)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/MemoryFile.cpp
// Function: CMemoryFile::Close()
int CMemoryFile::Close()
{
	// reset buffers, free resources if already closed
	if (filemt == mtLast)
		Free();
	else
		Clear(0);

	return 0;
}

// Assembly:
pushq %rax
cmpl $0x2, 0x10(%rdi)
jne 0xd4ec
callq 0xd3b6
jmp 0xd4f3
xorl %esi, %esi
callq 0xd370
xorl %eax, %eax
popq %rcx
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/MemoryFile.cpp
// Function: CMemoryFile::FreeBuffer()
void CMemoryFile::FreeBuffer()
{
	filesize[mtAlloc]=0;
	filecount=0;
	filepos=0;

	delete [] filebuf[mtAlloc];
	filebuf[mtAlloc]=NULL;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
andq $0x0, 0x28(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%rdi)
movq 0x18(%rdi), %rdi
testq %rdi, %rdi
je 0xd516
callq 0x3250
andq $0x0, 0x18(%rbx)
popq %rbx
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/MemoryFile.cpp
// Function: CMemoryFile::Read(void*, unsigned long)
size_t CMemoryFile::Read(void *buf, size_t size)
{
	// stop if: nothing to read; buffer is invalid; file is not open
	if (!buf || !size || filemt == mtLast)
		return 0;

	// limit readable size to remaining valid content
	if (filecount-filepos < size)
		size=filecount-filepos;

	// read from file, update stream position
	if (size) {
		memcpy(buf, filebuf[filemt]+filepos, size);
		filepos+=size;
	}

	return size;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
testq %rsi, %rsi
sete %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
jne 0xd54f
movq %rdi, %r14
movslq 0x10(%rdi), %rcx
cmpq $0x2, %rcx
je 0xd54f
movq %rdx, %rbx
movq 0x38(%r14), %rdx
movq 0x40(%r14), %rax
subq %rax, %rdx
jne 0xd55c
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
cmpq %rbx, %rdx
cmovbq %rdx, %rbx
addq 0x18(%r14,%rcx,8), %rax
movq %rsi, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x3160
addq %rbx, 0x40(%r14)
jmp 0xd551
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/Core/MemoryFile.cpp
// Function: CMemoryFile::Write(void*, unsigned long)
size_t CMemoryFile::Write(void *buf, size_t size)
{
	// stop if: nothing to write; buffer is invalid; file is not open; file is read-only
	if (!buf || !size || filemt == mtLast || !(filemode & BFFLAG_WRITE))
		return 0;

	// grow class owned file buffer if needed
	if (filemt == mtAlloc)
		AllocBuffer(filepos+size);

	// limit writeable size to buffer size
	if (filesize[filemt]-filepos < size)
		size=filesize[filemt]-filepos;

	// write into file, update stream position
	if (size) {
		memcpy(filebuf[filemt]+filepos, buf, size);
		filepos+=size;

		// update valid content count if wrote past the current file size
		if (filepos > filecount)
			filecount=filepos;
	}

	return size;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
testq %rsi, %rsi
sete %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
jne 0xd5de
movq %rdi, %rbx
movl 0x10(%rdi), %eax
cmpl $0x2, %eax
je 0xd5de
testb $0x1, 0xc(%rbx)
je 0xd5de
movq %rdx, %r12
movq %rsi, %r14
testl %eax, %eax
jne 0xd5c1
movq 0x40(%rbx), %rsi
addq %r12, %rsi
movq %rbx, %rdi
callq 0xd476
movl 0x10(%rbx), %eax
cltq
movq 0x28(%rbx,%rax,8), %rcx
movq 0x40(%rbx), %rdi
movq %rcx, %r15
subq %rdi, %r15
cmpq %r12, %r15
cmovaeq %r12, %r15
cmpq %rdi, %rcx
jne 0xd5f0
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
addq 0x18(%rbx,%rax,8), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3160
movq 0x40(%rbx), %rax
addq %r15, %rax
movq %rax, 0x40(%rbx)
cmpq 0x38(%rbx), %rax
jbe 0xd5e1
movq %rax, 0x38(%rbx)
jmp 0xd5e1
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/SOS_Unpacker.cpp
// Function: trackbuffer_shift_bits(unsigned char**, int, int)
void trackbuffer_shift_bits(UBYTE **pBuffer, int d0, int d1) {
    d0 -= 1;
    if (d0 >= 0) {
        UBYTE *buffer = *pBuffer;
        buffer += d1; buffer += d1;
        d1 -= 2;

        do {
            UWORD *a3 = (UWORD*)buffer;
            int	 d2 = d1;
            bool extend = false;

            --a3;
            if (*a3 & 0x8000)
                extend = true;
            *a3 <<= 1;

            do {
                bool extend2 = false;
                --a3;
                if (*a3 & 0x8000)
                    extend2 = true;
                *a3 <<= 1;

                if (extend)
                    *a3 |= 0x01;
                extend = extend2;
            } while (--d2 >= 0);

        } while (--d0 >= 0);
    }

    // Skip past SYNC marker
    while (readLEWord(*pBuffer) == gTrackSyncMarker)
        *pBuffer += 2;
}

// Assembly:
pushq %rbp
pushq %rbx
movq (%rdi), %rax
testl %esi, %esi
jle 0xd6fc
movslq %edx, %rcx
leaq (%rax,%rcx), %rdx
leaq (%rax,%rcx,2), %r8
addq $-0x4, %r8
leal -0x1(%rcx), %r9d
movzwl -0x2(%rdx,%rcx), %ebx
movl %ebx, %r10d
addl %ebx, %r10d
movw %r10w, -0x2(%rdx,%rcx)
movl %r9d, %r10d
movq %r8, %r11
movzwl (%r11), %ebp
shrdw $0xf, %bp, %bx
movw %bx, (%r11)
addq $-0x2, %r11
decl %r10d
movl %ebp, %ebx
testl %r10d, %r10d
jg 0xd6d0
leal -0x1(%rsi), %r10d
cmpl $0x1, %esi
movl %r10d, %esi
jg 0xd6b9
jmp 0xd6fc
movq %rax, (%rdi)
addq $0x2, %rax
cmpw $0x4489, -0x2(%rax)     # imm = 0x4489
je 0xd6f9
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/SOS_Unpacker.cpp
// Function: sectorFindSync(unsigned char**, unsigned char*)
int sectorFindSync(UBYTE **pBuffer, UBYTE *pBufferEnd) {
    UDWORD	bits_shifted = 0;
    bool	found = false;

    for (; *pBuffer < pBufferEnd && !found; *pBuffer += 2) {
        UDWORD current = swapDWord(readLEDWord(*pBuffer));

        for (bits_shifted = 0; bits_shifted < 16; ++bits_shifted) {
            if (gTrackSyncMarker == (current & 0xFFFF)) {
                found = true;
                break;
            }
            current >>= 1;
        }
    }

    if (*pBuffer >= pBufferEnd)
        return -1;

    // track begins on next word boundry
    if (!bits_shifted)
        *pBuffer += 2;

    // Calculate number of bits shifted
    return (16 - bits_shifted);
}

// Assembly:
movq (%rdi), %rax
xorl %ecx, %ecx
xorl %r8d, %r8d
cmpq %rsi, %rax
jae 0xd74a
testb $0x1, %r8b
jne 0xd74a
movl (%rax), %edx
roll $0x10, %edx
xorl %ecx, %ecx
cmpl $0x10, %ecx
setne %r8b
je 0xd741
movzwl %dx, %r9d
cmpl $0x4489, %r9d           # imm = 0x4489
je 0xd741
shrl %edx
incl %ecx
jmp 0xd725
addq $0x2, %rax
movq %rax, (%rdi)
jmp 0xd713
cmpq %rsi, %rax
jae 0xd760
testl %ecx, %ecx
jne 0xd75a
addq $0x2, %rax
movq %rax, (%rdi)
pushq $0x10
popq %rax
subl %ecx, %eax
retq
pushq $-0x1
popq %rax
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/stdafx.cpp
// Function: file_select(dirent const*)
int file_select(const struct dirent *entry) {
    std::string name = entry->d_name;

    std::transform(name.begin(), name.end(), name.begin(), ::toupper);

    if (name.find(findType) == std::string::npos)
        return false;

    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x28, %rsp
leaq 0x13(%rdi), %rsi
leaq 0x8(%rsp), %rbx
leaq 0x7(%rsp), %rdx
movq %rbx, %rdi
callq 0x30a0
movq (%rbx), %r14
movq 0x8(%rbx), %rbx
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0xe896
movsbl (%r14,%r15), %edi
callq 0x33a0
movb %al, (%r14,%r15)
incq %r15
jmp 0xe87e
leaq 0xadd3(%rip), %rsi      # 0x19670
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x33e0
xorl %ebp, %ebp
cmpq $-0x1, %rax
setne %bpl
movq %rbx, %rdi
callq 0x33f8
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/stdafx.cpp
// Function: GetLocalTime
void GetLocalTime(LPSYSTEMTIME lpSystemTime)
{
    time_t t = time(NULL);
    struct tm *tp = localtime(&t);

    lpSystemTime->wYear = tp->tm_year + 1900;
    lpSystemTime->wMonth = tp->tm_mon + 1;
    lpSystemTime->wDayOfWeek = tp->tm_wday;
    lpSystemTime->wDay = tp->tm_mday;
    lpSystemTime->wHour = tp->tm_hour;
    lpSystemTime->wMinute = tp->tm_min;
    lpSystemTime->wSecond = tp->tm_sec;
    // we don't have milliseconds in struct tm
    lpSystemTime->wMilliseconds = 0;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
xorl %edi, %edi
callq 0x31a0
leaq 0x8(%rsp), %rdi
movq %rax, (%rdi)
callq 0x3140
movq 0x10(%rax), %xmm0
pshuflw $0xe2, %xmm0, %xmm0     # xmm0 = xmm0[2,0,2,3,4,5,6,7]
paddw 0xb47(%rip), %xmm0      # 0xf600
movd %xmm0, (%rbx)
movzwl 0x18(%rax), %ecx
movw %cx, 0x4(%rbx)
movdqu (%rax), %xmm0
pshuflw $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3,4,5,6,7]
pshufhw $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,1,2,3,4,6,6,7]
pshufd $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3]
pshuflw $0x1b, %xmm0, %xmm0     # xmm0 = xmm0[3,2,1,0,4,5,6,7]
movq %xmm0, 0x6(%rbx)
andw $0x0, 0xe(%rbx)
addq $0x10, %rsp
popq %rbx
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/TooruAkagi[P]GCIS_Index/gcis_nep_locate.cpp
// Function: alldr(unsigned int*, int*, int*, int, int)
void alldr(unsigned int *D,int *D_2,int *D_3,int i,int round){
    //for(int i=0;i<60;i++){
    int rofs = 0;if(round>1){rofs=dc2s[round-1];}
        printf("\n%d > %d[%d(%d)]:",round,i,D_2[i],D_3[i]);
        for(int j=D_2[i];j<D_2[i+1];j++){printf("%d(%d) ",D[j]+rofs,D[j]);printf("(+%d)",D_3[D[j]+rofs]);
            //if(round>0){alldr(D,D_2,D_3,D[j]+rofs,round-1);}
        }
    //}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r8d, %eax
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
xorl %r13d, %r13d
cmpl $0x2, %r8d
jl 0x134a
leal -0x1(%rax), %edx
leaq 0x835a(%rip), %rsi      # 0x96a0
movl (%rsi,%rdx,4), %r13d
movslq %ecx, %r12
movl (%r14,%r12,4), %ecx
movl (%rbx,%r12,4), %r8d
leaq 0x3ce4(%rip), %rdi      # 0x5040
movl %eax, %esi
movl %r12d, %edx
xorl %eax, %eax
callq 0x1030
movslq (%r14,%r12,4), %rbp
movslq 0x4(%r14,%r12,4), %rax
cmpq %rax, %rbp
jge 0x13a9
movl (%r15,%rbp,4), %edx
leal (%rdx,%r13), %esi
leaq 0x3ccd(%rip), %rdi      # 0x5052
xorl %eax, %eax
callq 0x1030
movl (%r15,%rbp,4), %eax
addl %r13d, %eax
movl (%rbx,%rax,4), %esi
leaq 0x3cbd(%rip), %rdi      # 0x505a
xorl %eax, %eax
callq 0x1030
incq %rbp
jmp 0x136c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq