LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x1c(%rbp)
cmpq $0x0, 0xb0(%rax)
jne 0x17c96
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x17d54
movl $0x0, -0x20(%rbp)
movq -0x38(%rbp), %rcx
movl -0x20(%rbp), %eax
cmpl 0xa0(%rcx), %eax
jge 0x17d4e
movq -0x38(%rbp), %rax
movq 0xb0(%rax), %rax
movslq -0x20(%rbp), %rcx
imulq $0x148, %rcx, %rcx      # imm = 0x148
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
subl $0x1, %eax
ja 0x17cdc
jmp 0x17cda
jmp 0x17d40
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x17d60
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x17d00
movq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x17de0
movl -0x2c(%rbp), %eax
movl %eax, -0x3c(%rbp)
testl %eax, %eax
je 0x17d35
jmp 0x17d0c
movl -0x3c(%rbp), %eax
subl $0x1, %eax
je 0x17d20
jmp 0x17d16
movl -0x3c(%rbp), %eax
subl $0xe, %eax
jne 0x17d37
jmp 0x17d20
movq -0x38(%rbp), %rax
movl 0xa0(%rax), %eax
movl %eax, -0x20(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x17d40
jmp 0x17d3e
movl $0x2, -0x1c(%rbp)
jmp 0x17d40
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x17c9d
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)
// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/DiskImage.cpp
// Function: CDiskImage::AllocTrack(DiskTrackInfo*, unsigned int)
int CDiskImage::AllocTrack(PDISKTRACKINFO pti, UDWORD flag)
{
	// cancel if bad track
	if (!pti)
		return imgeGeneric;

	// track type support
	switch (pti->type) {
		// load known formats
		case dtitCapsDump:
		case dtitCapsImage:
			return LoadTrack(pti, flag);

		// plain format is generic
		case dtitPlain:
			return LoadPlain(pti);

		// any other state is undefined
		default:
			return imgeGeneric;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x17d8b
movl $0x2, -0x4(%rbp)
jmp 0x17dd7
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
addl $-0x2, %eax
subl $0x2, %eax
jb 0x17da8
jmp 0x17d9e
movl -0x2c(%rbp), %eax
subl $0x4, %eax
je 0x17dbe
jmp 0x17dd0
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq (%rdi), %rax
callq *0x28(%rax)
movl %eax, -0x4(%rbp)
jmp 0x17dd7
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x186a0
movl %eax, -0x4(%rbp)
jmp 0x17dd7
movl $0x2, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
// File: 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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x17df8
jmp 0x17e3d
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x17e0a
cmpl $0x0, -0xc(%rbp)
jne 0x17e0a
jmp 0x17e3d
movq -0x8(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x8(%rbp), %rdi
callq 0x185a0
movq -0x8(%rbp), %rdi
callq 0x186c0
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, 0xb0(%rax)
jne 0x17e73
jmp 0x17eb5
movl $0x0, -0x10(%rbp)
movq -0x18(%rbp), %rcx
movl -0x10(%rbp), %eax
cmpl 0xa0(%rcx), %eax
jge 0x17eb5
movq -0x18(%rbp), %rax
movq 0xb0(%rax), %rdi
movslq -0x10(%rbp), %rax
imulq $0x148, %rax, %rax      # imm = 0x148
addq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x17de0
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x17e7a
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: 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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %esi
movq -0x18(%rbp), %rax
movl 0x14(%rax), %edx
movl $0x1, %ecx
callq 0x17f50
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %esi
movq -0x18(%rbp), %rax
movl 0x14(%rax), %edx
callq 0x17f90
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x17f1b
movl $0x3, -0x4(%rbp)
jmp 0x17f41
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdi
movl $0x148, %edx            # imm = 0x148
callq 0x41a0
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x181e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: 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:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpl $0x0, 0x8(%rax)
jne 0x1822f
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
movl %ecx, 0x2c(%rax)
movl $0x1, 0x8(%rax)
jmp 0x182a9
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
cmpl 0x20(%rcx), %eax
jge 0x1824d
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
movl %ecx, 0x20(%rax)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
cmpl 0x24(%rcx), %eax
jle 0x1826b
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
movl %ecx, 0x24(%rax)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
cmpl 0x28(%rcx), %eax
jge 0x18289
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
movl %ecx, 0x28(%rax)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
cmpl 0x2c(%rcx), %eax
jle 0x182a7
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
movl %ecx, 0x2c(%rax)
jmp 0x182a9
popq %rbp
retq
nopl (%rax,%rax)
// File: 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:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, 0xb0(%rax)
jne 0x182da
movq $0x0, -0x8(%rbp)
jmp 0x18341
cmpl $0x0, -0x14(%rbp)
jl 0x182ef
movq -0x20(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0xa4(%rcx), %eax
jl 0x182f9
movq $0x0, -0x8(%rbp)
jmp 0x18341
cmpl $0x0, -0x18(%rbp)
jl 0x1830e
movq -0x20(%rbp), %rcx
movl -0x18(%rbp), %eax
cmpl 0xa8(%rcx), %eax
jl 0x18318
movq $0x0, -0x8(%rbp)
jmp 0x18341
movq -0x20(%rbp), %rdx
movq 0xb0(%rdx), %rax
movl -0x14(%rbp), %ecx
imull 0xa8(%rdx), %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x148, %rcx, %rcx      # imm = 0x148
addq %rcx, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
popq %rbp
retq
nopw (%rax,%rax)
// File: 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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x28(%rbp)
movl 0x3c(%rdi), %eax
movl %eax, 0x40(%rdi)
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x182b0
movq -0x28(%rbp), %rdi
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x17d60
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x14(%rbp), %eax
andq $0x2000, %rax           # imm = 0x2000
cmpq $0x0, %rax
jne 0x183bd
movq -0x28(%rbp), %rax
movl 0x3c(%rax), %ecx
addl $0x1, %ecx
andl $0xff, %ecx
movl %ecx, 0x3c(%rax)
movq -0x28(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x183d1
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x183d9
xorl %eax, %eax
movq %rax, -0x30(%rbp)
jmp 0x183d9
movq -0x30(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x30(%rbp)
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x182b0
movq -0x30(%rbp), %rdi
movq %rax, -0x28(%rbp)
movl -0x18(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc8(%rax)
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xcc(%rax)
movl -0x14(%rbp), %eax
movabsq $0x80000000, %rcx       # imm = 0x80000000
orq %rcx, %rax
movl %eax, -0x14(%rbp)
movq -0x28(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x17d60
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
cmpl $0x0, 0xc(%rax)
jne 0x1847a
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x18482
xorl %eax, %eax
movq %rax, -0x38(%rbp)
jmp 0x18482
movq -0x38(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)
// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x184dc
cmpl $0x0, -0x14(%rbp)
jge 0x184e8
movl $0x2, -0x4(%rbp)
jmp 0x18592
movq -0x10(%rbp), %rdi
callq 0x185a0
cmpl $0x0, -0x14(%rbp)
je 0x1856a
movq -0x10(%rbp), %rax
movl $0x1, 0x28(%rax)
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x10(%rbp), %rax
movslq 0x50(%rax), %rdi
callq 0x4040
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x10(%rbp), %rax
movl 0x50(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x80(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x94(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x50(%rax), %rdx
xorl %esi, %esi
callq 0x4140
movq -0x10(%rbp), %rax
movl $0x1, 0x4(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0xc(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x185b8
jmp 0x18676
movq -0x8(%rbp), %rax
cmpl $0x0, 0x44(%rax)
je 0x185df
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x185dd
movq -0x18(%rbp), %rdi
callq 0x42e0
jmp 0x185df
movl $0x0, -0xc(%rbp)
cmpl $0x5, -0xc(%rbp)
jge 0x1861b
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq $0x0, 0x58(%rax,%rcx,8)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movl $0x0, 0x80(%rax,%rcx,4)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x185e6
movq -0x8(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x44(%rax)
jne 0x1864d
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x1864b
movq -0x20(%rbp), %rdi
callq 0x42e0
jmp 0x1864d
movq -0x8(%rbp), %rax
movq $0x0, 0x48(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x50(%rax)
movq -0x8(%rbp), %rdi
callq 0x18750
movq -0x8(%rbp), %rdi
callq 0x187c0
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)
// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x186d5
jmp 0x18742
movq -0x8(%rbp), %rax
movl $0x0, 0xa8(%rax)
movq -0x8(%rbp), %rax
movq 0xb0(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
je 0x18701
movq -0x10(%rbp), %rdi
callq 0x42e0
movq -0x8(%rbp), %rax
movq $0x0, 0xb0(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x34(%rax)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x18736
movq -0x18(%rbp), %rdi
callq 0x42e0
movq -0x8(%rbp), %rax
movq $0x0, 0x38(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x18765
jmp 0x187ae
movq -0x8(%rbp), %rax
movl $0x0, 0xd0(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xd4(%rax)
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
je 0x1879f
movq -0x10(%rbp), %rdi
callq 0x42e0
movq -0x8(%rbp), %rax
movq $0x0, 0xd8(%rax)
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x187d5
jmp 0x18810
movq -0x8(%rbp), %rax
movl $0x0, 0xf4(%rax)
movq -0x8(%rbp), %rax
movq 0xf8(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
je 0x18801
movq -0x10(%rbp), %rdi
callq 0x42e0
movq -0x8(%rbp), %rax
movq $0x0, 0xf8(%rax)
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x18838
jmp 0x188cb
leaq -0x18(%rbp), %rdi
callq 0x1d940
movl $0x0, -0x1c(%rbp)
movzwl -0x18(%rbp), %eax
imull $0x2710, %eax, %eax     # imm = 0x2710
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movzwl -0x16(%rbp), %eax
imull $0x64, %eax, %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movzwl -0x12(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x1c(%rbp)
movzwl -0x10(%rbp), %eax
imull $0x989680, %eax, %eax   # imm = 0x989680
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movzwl -0xe(%rbp), %eax
imull $0x186a0, %eax, %eax    # imm = 0x186A0
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movzwl -0xc(%rbp), %eax
imull $0x3e8, %eax, %eax      # imm = 0x3E8
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movzwl -0xa(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
addl -0x1c(%rbp), %edx
movl %edx, -0x1c(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x188fc
jmp 0x189f2
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x4140
cmpq $0x0, -0x10(%rbp)
jne 0x18918
jmp 0x189f2
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl $0x2710, %ecx           # imm = 0x2710
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movl -0x14(%rbp), %eax
movl $0x2710, %ecx           # imm = 0x2710
xorl %edx, %edx
divl %ecx
movl %edx, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl $0x64, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x14(%rbp), %eax
movl $0x64, %ecx
xorl %edx, %edx
divl %ecx
movl %edx, -0x14(%rbp)
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl $0x989680, %ecx         # imm = 0x989680
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x14(%rbp), %eax
movl $0x989680, %ecx         # imm = 0x989680
xorl %edx, %edx
divl %ecx
movl %edx, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl $0x186a0, %ecx          # imm = 0x186A0
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x14(%rbp), %eax
movl $0x186a0, %ecx          # imm = 0x186A0
xorl %edx, %edx
divl %ecx
movl %edx, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x14(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %edx, -0x14(%rbp)
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x18(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
andq $0x2, %rax
cmpq $0x0, %rax
je 0x18aa3
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x18a7c
movq -0x10(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jge 0x18a87
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x18bd0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x14(%rax), %esi
callq 0x5890
movl %eax, -0x4(%rbp)
jmp 0x18bd0
leaq -0x28(%rbp), %rdi
movq %rdi, -0x58(%rbp)
callq 0xc450
movq -0x58(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xc550
movl %eax, -0x50(%rbp)
jmp 0x18ac2
movl -0x50(%rbp), %eax
cmpl $0x0, %eax
je 0x18af6
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x38(%rbp)
jmp 0x18bc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xc480
jmp 0x18bdc
leaq -0x28(%rbp), %rdi
callq 0xc7b0
movl %eax, -0x5c(%rbp)
jmp 0x18b04
movl -0x5c(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x18bba
movl $0x10000, -0x40(%rbp)   # imm = 0x10000
movslq -0x40(%rbp), %rdi
callq 0x4040
movq %rax, -0x68(%rbp)
jmp 0x18b2a
movq -0x68(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x18ba1
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jle 0x18b48
movl -0x40(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x18b4e
movl -0x3c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x48(%rbp), %rsi
movl -0x4c(%rbp), %edx
leaq -0x28(%rbp), %rdi
callq 0xc6e0
movl %eax, -0x70(%rbp)
jmp 0x18b69
movl -0x70(%rbp), %eax
cmpl -0x4c(%rbp), %eax
je 0x18b7a
movl $0x0, -0x14(%rbp)
jmp 0x18ba1
movq -0x48(%rbp), %rdi
movl -0x4c(%rbp), %esi
movl -0x14(%rbp), %edx
callq 0x5900
movl %eax, -0x74(%rbp)
jmp 0x18b8e
movl -0x74(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x4c(%rbp), %ecx
movl -0x3c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x3c(%rbp)
jmp 0x18b32
movq -0x48(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
je 0x18bb8
movq -0x80(%rbp), %rdi
callq 0x42e0
jmp 0x18bba
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x38(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xc480
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x4420
nopw %cs:(%rax,%rax)
// File: 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:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
cmpl $0x0, -0xc(%rbp)
jle 0x18c34
movl -0x10(%rbp), %eax
shll $0x8, %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x8(%rbp)
movzbl (%rax), %eax
orl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x18c02
movl -0x10(%rbp), %eax
popq %rbp
retq
nopl (%rax)
// File: 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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x18c63
cmpl $0x0, -0x1c(%rbp)
jg 0x18c6d
movq $0x0, -0x8(%rbp)
jmp 0x18ca4
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0x18cb0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x18c9c
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rax
imulq $0xc, %rax, %rdx
callq 0x41a0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nop
// File: 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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x18cd6
movq $0x0, -0x8(%rbp)
jmp 0x18e17
cmpl $0x0, -0x14(%rbp)
jg 0x18d02
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0xd0(%rcx), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x8(%rbp)
jmp 0x18e17
movq -0x10(%rbp), %rax
movl 0xd0(%rax), %eax
addl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xd4(%rcx), %eax
jle 0x18dc8
movq -0x10(%rbp), %rax
movl 0xd0(%rax), %eax
addl -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rax
movq %rax, -0x20(%rbp)
movslq -0x18(%rbp), %rax
movl $0xc, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4040
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0xd8(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xd0(%rax)
je 0x18da4
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movslq 0xd0(%rax), %rax
imulq $0xc, %rax, %rdx
callq 0x41a0
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x18dbb
movq -0x30(%rbp), %rdi
callq 0x42e0
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xd4(%rax)
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0xd0(%rcx), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movslq -0x14(%rbp), %rax
imulq $0xc, %rax, %rdx
xorl %esi, %esi
callq 0x4140
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0xd0(%rax), %ecx
movl %ecx, 0xd0(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: 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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x18e45
jmp 0x18ebc
movq -0x8(%rbp), %rdi
callq 0x187c0
movq -0x8(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jle 0x18ebc
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0xc(%rbp)
movslq -0xc(%rbp), %rax
movl $0x30, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x4040
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xf8(%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xf4(%rax)
movq -0x8(%rbp), %rax
movq 0xf8(%rax), %rdi
movslq -0xc(%rbp), %rax
imulq $0x30, %rax, %rdx
xorl %esi, %esi
callq 0x4140
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)
// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
leaq -0x20(%rbp), %rdi
movq %rdi, -0x40(%rbp)
callq 0xc450
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xc550
movl %eax, -0x38(%rbp)
jmp 0x18f8b
movl -0x38(%rbp), %eax
cmpl $0x0, %eax
je 0x18fc0
movl $0x0, -0x4(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x19049
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x20(%rbp), %rdi
callq 0xc480
jmp 0x1905b
movq -0x10(%rbp), %rdi
callq 0x19070
movl %eax, -0x44(%rbp)
jmp 0x18fce
movl -0x44(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x1, -0x34(%rbp)
je 0x18fe9
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x19049
movq -0x10(%rbp), %rdi
callq 0x191c0
movl %eax, -0x48(%rbp)
jmp 0x18ff7
movl -0x48(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x1, -0x34(%rbp)
je 0x19012
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x19049
movq -0x10(%rbp), %rdi
callq 0x19330
movl %eax, -0x4c(%rbp)
jmp 0x19020
movl -0x4c(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x1, -0x34(%rbp)
je 0x1903b
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x19049
movl $0x1, -0x4(%rbp)
movl $0x1, -0x30(%rbp)
leaq -0x20(%rbp), %rdi
callq 0xc480
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x4420
nopw %cs:(%rax,%rax)
// File: 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 %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x10(%rbp)
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x151b0
movq -0x128(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x152d0
movl %eax, -0x11c(%rbp)
jmp 0x190aa
movl -0x11c(%rbp), %eax
movl %eax, -0xfc(%rbp)
cmpl $0x0, -0xfc(%rbp)
jne 0x19187
movl $0x1, -0x110(%rbp)
cmpl $0x0, -0x110(%rbp)
je 0x19185
leaq -0xf8(%rbp), %rdi
xorl %esi, %esi
callq 0x15380
movl %eax, -0x12c(%rbp)
jmp 0x190f0
movl -0x12c(%rbp), %eax
movl %eax, -0x114(%rbp)
movl -0x114(%rbp), %eax
movl %eax, -0x130(%rbp)
decl %eax
subl $0x6, %eax
jb 0x1914b
jmp 0x19111
movl -0x130(%rbp), %eax
subl $0xb, %eax
je 0x1915a
jmp 0x1911e
movl -0x130(%rbp), %eax
subl $0xd, %eax
je 0x1916d
jmp 0x19180
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x15260
jmp 0x191b0
movl $0x0, -0x110(%rbp)
jmp 0x190cd
movl $0x3, -0x4(%rbp)
movl $0x1, -0x118(%rbp)
jmp 0x19198
movl $0x2, -0x4(%rbp)
movl $0x1, -0x118(%rbp)
jmp 0x19198
jmp 0x190cd
jmp 0x19187
movl $0x1, -0x4(%rbp)
movl $0x1, -0x118(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x15260
movl -0x4(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x108(%rbp), %rdi
callq 0x4420
nopl (%rax)
// File: 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
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x10(%rbp)
leaq -0x20(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0xc450
movq -0x148(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xc550
movl %eax, -0x140(%rbp)
jmp 0x191f7
movl -0x140(%rbp), %eax
cmpl $0x0, %eax
je 0x1922f
movl $0x0, -0x4(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x19303
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x20(%rbp), %rdi
callq 0xc480
jmp 0x19318
leaq -0x20(%rbp), %rdi
callq 0xc7b0
movl %eax, -0x14c(%rbp)
jmp 0x19240
movl -0x14c(%rbp), %eax
movl %eax, -0x134(%rbp)
movl $0xff, -0x138(%rbp)
leaq -0x134(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0xe0c0
movq %rax, -0x158(%rbp)
jmp 0x19272
movq -0x158(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x13c(%rbp)
movl -0x13c(%rbp), %edx
leaq -0x20(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0xc6e0
movl %eax, -0x15c(%rbp)
jmp 0x1929f
movl -0x15c(%rbp), %eax
cmpl -0x13c(%rbp), %eax
je 0x192bd
movl $0x0, -0x4(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x19303
movslq -0x13c(%rbp), %rax
movb $0x0, -0x130(%rbp,%rax)
leaq -0x130(%rbp), %rdi
leaq 0x505b(%rip), %rsi      # 0x1e335
callq 0x4090
cmpq $0x0, %rax
je 0x192f5
movl $0x5, -0x4(%rbp)
movl $0x1, -0x30(%rbp)
jmp 0x19303
movl $0x1, -0x4(%rbp)
movl $0x1, -0x30(%rbp)
leaq -0x20(%rbp), %rdi
callq 0xc480
movl -0x4(%rbp), %eax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x4420
nopw %cs:(%rax,%rax)
// File: 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 %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x4(%rbp)
movq $0x0, -0x10(%rbp)
movl -0x4(%rbp), %eax
addl $-0x2, %eax
movl %eax, %ecx
movq %rcx, -0x28(%rbp)
subl $0x3, %eax
ja 0x196ac
movq -0x28(%rbp), %rax
leaq 0x4d75(%rip), %rcx      # 0x1e308
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x230, %edi            # imm = 0x230
callq 0x4240
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x30(%rbp)
callq 0xe150
jmp 0x195b7
movq -0x30(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x196ac
movq -0x30(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x230, %esi            # imm = 0x230
callq 0x4250
jmp 0x196b6
movl $0x230, %edi            # imm = 0x230
callq 0x4240
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x38(%rbp)
callq 0x196c0
jmp 0x195fe
movq -0x38(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x196ac
movq -0x38(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x230, %esi            # imm = 0x230
callq 0x4250
jmp 0x196b6
movl $0xb8, %edi
callq 0x4240
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x40(%rbp)
callq 0x1d380
jmp 0x19645
movq -0x40(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x196ac
movq -0x40(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0xb8, %esi
callq 0x4250
jmp 0x196b6
movl $0xb8, %edi
callq 0x4240
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x48(%rbp)
callq 0x1d2d0
jmp 0x19686
movq -0x48(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x196ac
movq -0x48(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0xb8, %esi
callq 0x4250
jmp 0x196b6
movq -0x10(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x4420
nop
// File: OpenFodder[P]SOS_Unpacker/capsimg/Core/MemoryFile.cpp
// Function: CMemoryFile::Clear(int)
void CMemoryFile::Clear(int clbuf)
{
	if (clbuf) {
		filebuf[mtAlloc]=NULL;
		filesize[mtAlloc]=0;

		filebuf[mtUser]=NULL;
		filesize[mtUser]=0;
	}

	filecount=0;
	filepos=0;

	filemt=mtLast;

	CBaseFile::Clear();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x197a1
movq -0x18(%rbp), %rax
movq $0x0, 0x18(%rax)
movq $0x0, 0x28(%rax)
movq $0x0, 0x20(%rax)
movq $0x0, 0x30(%rax)
movq -0x18(%rbp), %rdi
movq $0x0, 0x38(%rdi)
movq $0x0, 0x40(%rdi)
movl $0x2, 0x10(%rdi)
callq 0x4bd0
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: 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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x30(%rbp)
xorl %esi, %esi
callq 0x19760
movl -0x24(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x198f0
cmpq $0x0, -0x20(%rbp)
je 0x198e3
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x19960
cmpq $0x0, -0x18(%rbp)
je 0x198e1
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
shlq $0x0, %rdx
callq 0x41a0
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
movq %rcx, 0x38(%rax)
jmp 0x198e3
movq -0x30(%rbp), %rax
movl $0x0, 0x10(%rax)
jmp 0x19934
cmpq $0x0, -0x20(%rbp)
je 0x19909
cmpq $0x0, -0x18(%rbp)
jne 0x19907
movl $0x1, -0x4(%rbp)
jmp 0x19954
jmp 0x19911
movq $0x0, -0x18(%rbp)
movq -0x30(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x18(%rbp), %rcx
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x38(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x40(%rax)
movl $0x1, 0x8(%rax)
movl -0x24(%rbp), %ecx
movl %ecx, 0xc(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)
// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq 0x28(%rax), %rax
cmpq -0x10(%rbp), %rax
jae 0x19a01
movq -0x10(%rbp), %rax
addq $0x200, %rax            # imm = 0x200
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4040
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, -0x18(%rbp)
movq 0x38(%rax), %rcx
movq %rcx, -0x20(%rbp)
movq 0x40(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x199d4
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rdi
movq 0x18(%rax), %rsi
movq -0x20(%rbp), %rdx
shlq $0x0, %rdx
callq 0x41a0
movq -0x30(%rbp), %rdi
callq 0x19a50
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rcx
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rcx
movq %rcx, 0x38(%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x40(%rax)
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: 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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
cmpl $0x2, 0x10(%rax)
jne 0x19a35
movq -0x10(%rbp), %rdi
callq 0x19810
jmp 0x19a40
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x19760
xorl %eax, %eax
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: 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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq $0x0, 0x28(%rax)
movq $0x0, 0x38(%rax)
movq $0x0, 0x40(%rax)
movq 0x18(%rax), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
je 0x19a93
movq -0x10(%rbp), %rdi
callq 0x42e0
movq -0x18(%rbp), %rax
movq $0x0, 0x18(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: 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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x19ae4
cmpq $0x0, -0x20(%rbp)
je 0x19ae4
movq -0x28(%rbp), %rax
cmpl $0x2, 0x10(%rax)
jne 0x19aee
movq $0x0, -0x8(%rbp)
jmp 0x19b4d
movq -0x28(%rbp), %rcx
movq 0x38(%rcx), %rax
subq 0x40(%rcx), %rax
cmpq -0x20(%rbp), %rax
jae 0x19b10
movq -0x28(%rbp), %rcx
movq 0x38(%rcx), %rax
subq 0x40(%rcx), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x19b45
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rdi
movslq 0x10(%rax), %rcx
movq 0x18(%rax,%rcx,8), %rsi
addq 0x40(%rax), %rsi
movq -0x20(%rbp), %rdx
callq 0x41a0
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
addq 0x40(%rax), %rcx
movq %rcx, 0x40(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)