LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcSetTiming(CapsFdc*)
void FdcSetTiming(PCAPSFDC pc)
{
	// drive specific values
	for (int drv=0; drv < pc->drivecnt; drv++) {
		PCAPSDRIVE pd=pc->drive+drv;

		// clock cycles per revolution
		pd->clockrev=UDWORD(((UQUAD)pc->clockfrq*60)/pd->rpm);

		// clock cycles for index pulse hold
		pd->clockip=UDWORD(((UQUAD)pc->clockfrq*pc->iptime)/1000000);
	}

	// clock cycles for stepping rates
	for (int drv=0; drv < 4; drv++)
		pc->clockstep[drv]=UDWORD(((UQUAD)pc->clockfrq*pc->steptime[drv])/1000000);

	// clock cycles for head settling
	pc->clockhs=UDWORD(((UQUAD)pc->clockfrq*pc->hstime)/1000000);

	// clock cycles for short operations (some SR updates)
	pc->clockupdate=UDWORD(((UQUAD)pc->clockfrq*pc->updatetime)/1000000);
}

// Assembly:
pushq %rbx
movslq 0xec(%rdi), %rcx
movabsq $0x2c, %rsi
xorl %r8d, %r8d
movl $0xf4240, %r9d          # imm = 0xF4240
cmpq %rcx, %r8
jge 0x5e40
movq 0x108(%rdi), %r10
movl 0x14(%rdi), %r11d
imulq $0x3c, %r11, %rax
movl -0x28(%r10,%rsi), %ebx
xorl %edx, %edx
divq %rbx
movl %eax, -0x4(%r10,%rsi)
movl 0xe0(%rdi), %eax
imulq %r11, %rax
xorl %edx, %edx
divq %r9
movl %eax, (%r10,%rsi)
incq %r8
addq $0x78, %rsi
jmp 0x5e01
movl 0x14(%rdi), %esi
movabsq $-0x10, %rcx
movl $0xf4240, %r8d          # imm = 0xF4240
testq %rcx, %rcx
je 0x5e75
movl 0xc8(%rdi,%rcx), %eax
imulq %rsi, %rax
xorl %edx, %edx
divq %r8
movl %eax, 0xd8(%rdi,%rcx)
addq $0x4, %rcx
jmp 0x5e53
movl 0xd8(%rdi), %eax
movl 0xe4(%rdi), %ecx
imulq %rsi, %rax
movl $0xf4240, %r8d          # imm = 0xF4240
xorl %edx, %edx
divq %r8
movl %eax, 0xdc(%rdi)
imulq %rsi, %rcx
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movl %eax, 0xe8(%rdi)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcInit(CapsFdc*)
void FdcInit(PCAPSFDC pc)
{
	// reset drives, no disk inserted
	for (int drv=0; drv < pc->drivecnt; drv++) {
		PCAPSDRIVE pd=pc->drive+drv;
		pd->track=0;
		pd->buftrack=-1;
		pd->side=0;
		pd->bufside=-1;
		pd->newside=0;
		pd->diskattr=CAPSDRIVE_DA_WP;
		pd->idistance=0;
		pd->ipcnt=0;
		pd->ovlact=0;
		pd->nact=0;
		pd->nseed=0x87654321;

		// no track data
		FdcClearTrackData(pd);
	}

	// reset internal state
	FdcResetState(pc);

	// all output lines are clear, without callbacks from init
	pc->dataline=0;
	pc->lineout=0;

	// forced update
	pc->drivesel=pc->drivenew-1;
	FdcUpdateDrive(pc, 0);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
pushq $0x5c
popq %rax
xorl %ecx, %ecx
movaps 0x9296(%rip), %xmm0     # 0xf150
movabsq $0x200000000, %rdx      # imm = 0x200000000
xorps %xmm1, %xmm1
movaps 0x9292(%rip), %xmm2     # 0xf160
movaps 0x929b(%rip), %xmm3     # 0xf170
movslq 0xec(%rbx), %rsi
cmpq %rsi, %rcx
jge 0x5f19
movq 0x108(%rbx), %rsi
movups %xmm0, -0x50(%rsi,%rax)
movq %rdx, -0x40(%rsi,%rax)
andl $0x0, -0x38(%rsi,%rax)
andl $0x0, -0x2c(%rsi,%rax)
movups %xmm1, -0x28(%rsi,%rax)
andq $0x0, -0x18(%rsi,%rax)
movups %xmm2, -0x10(%rsi,%rax)
movups %xmm3, (%rsi,%rax)
incq %rcx
addq $0x78, %rax
jmp 0x5ed5
movq %rbx, %rdi
callq 0x6326
andl $0x0, 0x1c(%rbx)
andl $0x0, 0x24(%rbx)
movl 0xf4(%rbx), %eax
decl %eax
movl %eax, 0xf8(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
jmp 0x6032
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcReset(CapsFdc*)
void FdcReset(PCAPSFDC pc)
{
	// reset internal state
	FdcResetState(pc);

	// all output lines are clear
	pc->dataline=0;
	FdcSetLine(pc, 0);

	// forced update
	pc->drivesel=pc->drivenew-1;
	FdcUpdateDrive(pc, 0);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
callq 0x6326
andl $0x0, 0x1c(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x61aa
movl 0xf4(%rbx), %eax
decl %eax
movl %eax, 0xf8(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
jmp 0x6032
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: CAPSFdcEmulate(CapsFdc*, unsigned int)
void __cdecl CAPSFdcEmulate(PCAPSFDC pc, UDWORD cyclecnt)
{
	// no cycles done
	pc->clockact=0;

	// requested cycles
	pc->clockreq=cyclecnt;

	// no end request
	pc->endrequest=0;

	// run fdc for selected clock cycles
	if (pc->clockreq) {
		FDCCALL *fc=fdccall[pc->runmode];

		// process requested cycles
		while (!pc->endrequest && pc->clockact<pc->clockreq)
			fc[pc->runstate](pc);

		// stop processing after end request
		if (pc->endrequest)
			FdcComEnd(pc);
	}

	// update only if all cycles are complete
	if (pc->clockact >= pc->clockreq)
		FdcUpdateDrive(pc, pc->clockreq);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl %esi, 0x10(%rdi)
andq $0x0, 0x8(%rdi)
testl %esi, %esi
je 0x5fc4
movl 0x28(%rbx), %eax
leaq 0x115ff(%rip), %rcx     # 0x175a0
movq (%rcx,%rax,8), %r14
xorl %eax, %eax
testl %eax, %eax
jne 0x5fc8
movl 0xc(%rbx), %eax
movl 0x10(%rbx), %esi
cmpl %esi, %eax
jae 0x5fd6
movl 0x2c(%rbx), %eax
movq %rbx, %rdi
callq *(%r14,%rax,8)
movl 0x8(%rbx), %eax
jmp 0x5fa7
xorl %esi, %esi
jmp 0x5fe2
movq %rbx, %rdi
callq 0x5ff1
movl 0xc(%rbx), %eax
movl 0x10(%rbx), %esi
cmpl %esi, %eax
jae 0x5fe2
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x6032
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcSetLine(CapsFdc*, unsigned int)
void FdcSetLine(PCAPSFDC pc, UDWORD lineout)
{
	// forced interrupt keeps intrq set
	if (lineout & CAPSFDC_LO_INTFRC)
		lineout|=CAPSFDC_LO_INTRQ;

	// get old line state
	UDWORD oldline=pc->lineout;

	// check for drq set
	if (lineout & CAPSFDC_LO_DRQSET) {
		lineout&=~CAPSFDC_LO_DRQSET;
		lineout|=CAPSFDC_LO_DRQ;

		// data lost, if trying to set drq and drq is already set
		if (oldline & CAPSFDC_LO_DRQ)
			pc->r_st1|=CAPSFDC_SR_TR0_LD;
	}

	// changed bits are 1
	UDWORD chgmask=oldline ^ lineout;

	// set new line state
	pc->lineout=lineout;

	// drq change
	if (chgmask & CAPSFDC_LO_DRQ) {
		UDWORD setting=lineout & CAPSFDC_LO_DRQ;
		if (setting)
			pc->r_st1|=CAPSFDC_SR_IP_DRQ;
		else
			pc->r_st1&=~CAPSFDC_SR_IP_DRQ;
		pc->cbdrq(pc, setting);
	}

	// irq change
	if (chgmask & CAPSFDC_LO_INTRQ)
		pc->cbirq(pc, lineout & CAPSFDC_LO_INTRQ);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl %esi, %ebp
shrl %ebp
andl $0x2, %ebp
orl %esi, %ebp
movl 0x24(%rdi), %r14d
testb $0x40, %sil
je 0x61d3
andl $-0x42, %ebp
incl %ebp
testb $0x1, %r14b
je 0x61d3
orb $0x4, 0x34(%rbx)
xorl %ebp, %r14d
movl %ebp, 0x24(%rbx)
testb $0x1, %r14b
je 0x61f9
movl %ebp, %esi
andl $0x1, %esi
movl 0x34(%rbx), %eax
andl $-0x3, %eax
leal (%rax,%rsi,2), %eax
movl %eax, 0x34(%rbx)
movq %rbx, %rdi
callq *0x118(%rbx)
testb $0x2, %r14b
jne 0x6204
popq %rbx
popq %r14
popq %rbp
retq
movq 0x110(%rbx), %rax
andl $0x2, %ebp
movq %rbx, %rdi
movl %ebp, %esi
popq %rbx
popq %r14
popq %rbp
jmpq *%rax
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: CAPSFdcInvalidateTrack(CapsFdc*, int)
SDWORD __cdecl CAPSFdcInvalidateTrack(PCAPSFDC pc, SDWORD drive)
{
	if (!pc)
		return imgeGeneric;

	if (drive<0 || drive>=pc->drivecnt)
		return imgeOutOfRange;

	PCAPSDRIVE pd=pc->drive+drive;
	pd->buftrack=-1;
	pd->bufside=-1;

	return imgeOk;
}

// Assembly:
testq %rdi, %rdi
je 0x6306
pushq $0x3
popq %rax
testl %esi, %esi
js 0x6309
cmpl %esi, 0xec(%rdi)
jle 0x6309
movq 0x108(%rdi), %rax
movl %esi, %ecx
imulq $0x78, %rcx, %rcx
orl $-0x1, 0x10(%rax,%rcx)
orl $-0x1, 0x18(%rax,%rcx)
xorl %eax, %eax
retq
pushq $0x2
popq %rax
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComIdle(CapsFdc*, unsigned int)
UDWORD FdcComIdle(PCAPSFDC pc, UDWORD cyc)
{
	// wait state cancelled if end requested
	if (pc->endrequest & CAPSFDC_ER_REQEND)
		return 0;

	// process all drives
	for (int drv=0; drv < pc->drivemax; drv++) {
		// get drive
		PCAPSDRIVE pd=pc->drive+drv;

		// if motor off no distance change and no index signals to count
		if (!(pd->diskattr & CAPSDRIVE_DA_MO))
			continue;

		// motor on, advance distance
		UDWORD dist=pd->idistance+cyc;

		// restart distance count on new revolution
		if (dist >= pd->clockrev) {
			dist-=pd->clockrev;

			// process disk index
			pd->idistance=0;
			FdcIndex(pc, drv);
		}

		// set distance
		pd->idistance=dist;
	}

	// !!!
	pc->clockact+=cyc;
	return cyc;
}

// Assembly:
xorl %eax, %eax
testb $0x2, 0x8(%rdi)
jne 0x6448
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
pushq $0x28
popq %r12
xorl %r15d, %r15d
movslq 0xf0(%r14), %rax
cmpq %rax, %r15
jge 0x6434
movq 0x108(%r14), %r13
testb $0x4, -0x8(%r13,%r12)
je 0x642b
movl -0x4(%r13,%r12), %eax
addl %ebx, %eax
movl %eax, %ebp
subl (%r13,%r12), %ebp
jb 0x6426
andl $0x0, -0x4(%r13,%r12)
movq %r14, %rdi
movl %r15d, %esi
callq 0x65f0
movl %ebp, %eax
movl %eax, -0x4(%r13,%r12)
incq %r15
addq $0x78, %r12
jmp 0x63e8
addl %ebx, 0xc(%r14)
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcResetAm(CapsFdc*, int)
void FdcResetAm(PCAPSFDC pc, int keepphase)
{
	pc->aminfo|=CAPSFDC_AI_AMDETENABLE|CAPSFDC_AI_CRCENABLE;
	pc->aminfo&=~(CAPSFDC_AI_CRCACTIVE|CAPSFDC_AI_AMACTIVE);
	pc->amisigmask=CAPSFDC_AI_DSRAM;
	if (!keepphase) {
		pc->dataphase=0;
		pc->datapcnt=0;
	}
}

// Assembly:
movl 0x60(%rdi), %eax
andl $-0x10, %eax
orl $0x3, %eax
movl %eax, 0x60(%rdi)
movl $0x200, 0x64(%rdi)      # imm = 0x200
testl %esi, %esi
je 0x6569
retq
andq $0x0, 0x8c(%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComIdleOther(CapsFdc*, unsigned int)
void FdcComIdleOther(PCAPSFDC pc, UDWORD cyc)
{
	// process all drives
	for (int drv=0; drv < pc->drivemax; drv++) {
		// skip active drive
		if (drv == pc->driveact)
			continue;

		// get drive
		PCAPSDRIVE pd=pc->drive+drv;

		// if motor off no distance change
		if (!(pd->diskattr & CAPSDRIVE_DA_MO))
			continue;

		// motor on, advance distance
		UDWORD dist=pd->idistance+cyc;

		// restart distance count on new revolution
		if (dist >= pd->clockrev) {
			dist-=pd->clockrev;

			// process disk index
			pd->idistance=0;
			FdcIndex(pc, drv);
		}

		// set distance
		pd->idistance=dist;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
pushq $0x28
popq %r12
xorl %r15d, %r15d
movslq 0xf0(%r14), %rax
cmpq %rax, %r15
jge 0x65e1
movl 0xfc(%r14), %eax
cmpq %rax, %r15
je 0x65d8
movq 0x108(%r14), %r13
testb $0x4, -0x8(%r13,%r12)
je 0x65d8
movl -0x4(%r13,%r12), %eax
addl %ebx, %eax
movl %eax, %ebp
subl (%r13,%r12), %ebp
jb 0x65d3
andl $0x0, -0x4(%r13,%r12)
movq %r14, %rdi
movl %r15d, %esi
callq 0x65f0
movl %ebp, %eax
movl %eax, -0x4(%r13,%r12)
incq %r15
addq $0x78, %r12
jmp 0x6589
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcIndex(CapsFdc*, int)
void FdcIndex(PCAPSFDC pc, int drive)
{
	// must be valid drive
	if (drive < 0)
		return;

	// get selected drive
	PCAPSDRIVE pd=pc->drive+drive;

	// if drive empty, no index signal, stop
	if (!(pd->diskattr & CAPSDRIVE_DA_IN))
		return;

	// start index pulse
	pd->ipcnt=-1;

	// if track is changing, request new track data
	if ((pd->ttype & CTIT_FLAG_FLAKEY))
		pc->cbtrk(pc, drive);

	// update track parameters
	FdcUpdateTrack(pc, drive);

	// if drive not selected, index signal not routed, stop
	if (drive != pc->driveact)
		return;

	// set index signal
	pc->r_st0|=CAPSFDC_SR_IP_DRQ;

	// increment index pulse counter
	pc->indexcount++;

	// if index abort allowed and limit reached set end and disable abort
	if (pc->indexlimit>=0 && pc->indexcount>=pc->indexlimit) {
		pc->endrequest|=CAPSFDC_ER_COMEND;
		pc->indexlimit=-1;
	}

	// set spin-up flag if limit reached
	if (pc->spinupcnt>=pc->spinuplimit || ++pc->spinupcnt>=pc->spinuplimit)
		pc->r_st0|=CAPSFDC_SR_SU_RT;

	// if fdc is not busy turn motor off once idle limit reached, apparently SR spin-up is not reset
	if (!(pc->r_st0 & CAPSFDC_SR_BUSY)) {
		if (pc->idlecnt>=pc->idlelimit || ++pc->idlecnt>=pc->idlelimit) {
			pc->lineout&=~CAPSFDC_LO_MO;
			pd->diskattr&=~CAPSDRIVE_DA_MO;
			pc->r_st0&=~CAPSFDC_SR_MO;
			pc->spinupcnt=0;
		}
	}

	// set index pulse interrupt if enabled
	if (pc->lineout & CAPSFDC_LO_INTIP)
		FdcSetLine(pc, pc->lineout | CAPSFDC_LO_INTRQ);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
testl %esi, %esi
js 0x66e9
movl %esi, %ebp
movq %rdi, %rbx
movq 0x108(%rdi), %r14
movl %esi, %eax
imulq $0x78, %rax, %rax
testb $0x1, 0x20(%r14,%rax)
je 0x66e9
addq %rax, %r14
orl $-0x1, 0x30(%r14)
cmpl $0x0, 0x34(%r14)
jns 0x6634
movq %rbx, %rdi
movl %ebp, %esi
callq *0x120(%rbx)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x678b
cmpl %ebp, 0xfc(%rbx)
jne 0x66e9
movl 0x30(%rbx), %ecx
movl 0x94(%rbx), %edx
movl %ecx, %eax
orl $0x2, %eax
movl %eax, 0x30(%rbx)
incl %edx
movl %edx, 0x94(%rbx)
movl 0x98(%rbx), %esi
testl %esi, %esi
sets %dil
cmpl %esi, %edx
setl %dl
orb %dil, %dl
jne 0x6684
orb $0x1, 0x8(%rbx)
orl $-0x1, 0x98(%rbx)
movl 0xa4(%rbx), %edx
movl 0xa8(%rbx), %esi
cmpl %esi, %edx
jge 0x66a0
incl %edx
movl %edx, 0xa4(%rbx)
cmpl %esi, %edx
jl 0x66a8
orl $0x22, %ecx
movl %ecx, 0x30(%rbx)
movl %ecx, %eax
testb $0x1, %al
jne 0x66e0
movl 0xac(%rbx), %ecx
movl 0xb0(%rbx), %edx
cmpl %edx, %ecx
jge 0x66c8
incl %ecx
movl %ecx, 0xac(%rbx)
cmpl %edx, %ecx
jl 0x66e0
andb $-0x9, 0x24(%rbx)
andb $-0x5, 0x20(%r14)
andl $0xffffff7e, %eax       # imm = 0xFFFFFF7E
movl %eax, 0x30(%rbx)
andl $0x0, 0xa4(%rbx)
movl 0x24(%rbx), %esi
testb $0x20, %sil
jne 0x66ee
popq %rbx
popq %r14
popq %rbp
retq
orl $0x2, %esi
movq %rbx, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x61aa
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcLockData(CapsFdc*)
void FdcLockData(PCAPSFDC pc)
{
	// get selected drive
	PCAPSDRIVE pd=pc->driveprc;

	// check input available
	if (!pd || !(pd->diskattr & CAPSDRIVE_DA_IN)) {
		// if no input read 0 on reference clock
		pc->datamode=cfdcdmNoline;

		// lock onto reference clock 2us mfm*(8clock+8data)
		pc->datalock=UDWORD(((UQUAD)pc->clockfrq*2*16)/1000000);
		pc->datacycle=0;
		return;
	}

	// true if track data is defined
	int dat=pd->trackbuf && pd->tracklen;

	// density map is only used when track data is available
	if (pd->timebuf && dat) {
		pc->datamode=cfdcdmDMap;
		FdcLockTime(pc);
		return;
	}

	// noise or data input read
	pc->datamode=dat ? cfdcdmData : cfdcdmNoise;

	// lock onto bit in progress at the drive cycle
	pc->datalock=UDWORD(((UQUAD)pd->idistance*pd->trackbits)/pd->clockrev);
	pc->datacycle=0;
}

// Assembly:
movq 0x100(%rdi), %rax
testq %rax, %rax
je 0x670f
testb $0x1, 0x20(%rax)
jne 0x672a
andq $0x0, 0x84(%rdi)
movl 0x14(%rdi), %eax
movl $0x7a12, %ecx           # imm = 0x7A12
xorl %edx, %edx
divl %ecx
movl %eax, 0x80(%rdi)
retq
cmpq $0x0, 0x38(%rax)
je 0x6756
movl 0x48(%rax), %ecx
testl %ecx, %ecx
sete %dl
cmpq $0x0, 0x40(%rax)
sete %sil
orb %dl, %sil
jne 0x675b
movl $0x3, 0x84(%rdi)
jmp 0x6847
pushq $0x1
popq %rcx
jmp 0x6764
cmpl $0x1, %ecx
pushq $0x1
popq %rcx
sbbl $-0x1, %ecx
movl %ecx, 0x84(%rdi)
movl 0x24(%rax), %ecx
movl 0x28(%rax), %esi
movslq 0x50(%rax), %rax
imulq %rcx, %rax
xorl %edx, %edx
divq %rsi
movl %eax, 0x80(%rdi)
andl $0x0, 0x88(%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcUpdateTrack(CapsFdc*, int)
void FdcUpdateTrack(PCAPSFDC pc, int drive)
{
	// must be valid drive
	if (drive < 0)
		return;

	// get selected drive
	PCAPSDRIVE pd=pc->drive+drive;

	// no disk inserted, no input
	if (!(pd->diskattr & CAPSDRIVE_DA_IN))
		return;

	// get base track length in bits
	if (!pd->trackbuf || !pd->tracklen) {
		// generate different track size on track updates
		PSDWORD ns=fdcddnoise;
		pd->trackbits=ns[pd->nact++]<<3;
		if (ns[pd->nact] < 0)
			pd->nact=0;
		pd->overlap=0;
	} else
		pd->trackbits=pd->tracklen<<3;

	// if overlap position exists
	int rb;
	if (pd->overlap >= 0) {
		// rob bit count, updated on track updates
		rb=fdcrobbit[pd->ovlact++];
		if (fdcrobbit[pd->ovlact] < 0)
			pd->ovlact=0;
	} else
		rb=0;

	pd->ovlcnt=rb;

	// set bits to remove and their start if any
	if (rb) {
		pd->ovlmin=((pd->overlap+1)<<3)-rb;
		pd->ovlmax=pd->ovlmin+rb-1;
	} else {
		pd->ovlmin=-1;
		pd->ovlmax=-1;
	}
}

// Assembly:
testl %esi, %esi
js 0x6846
movq 0x108(%rdi), %rax
movl %esi, %ecx
imulq $0x78, %rcx, %rcx
testb $0x1, 0x20(%rax,%rcx)
je 0x6846
addq %rcx, %rax
cmpq $0x0, 0x38(%rax)
je 0x67ce
movl 0x48(%rax), %ecx
testl %ecx, %ecx
je 0x67ce
shll $0x3, %ecx
movl %ecx, 0x50(%rax)
cmpl $0x0, 0x4c(%rax)
jns 0x67f8
andl $0x0, 0x5c(%rax)
jmp 0x683c
movslq 0x64(%rax), %rcx
leaq 0x1(%rcx), %rdx
movl %edx, 0x64(%rax)
leaq 0x10a80(%rip), %rdx     # 0x17260
movl (%rdx,%rcx,4), %esi
shll $0x3, %esi
movl %esi, 0x50(%rax)
cmpl $0x0, 0x4(%rdx,%rcx,4)
jns 0x67f4
andl $0x0, 0x64(%rax)
andl $0x0, 0x4c(%rax)
movslq 0x60(%rax), %rcx
leaq 0x1(%rcx), %rdx
movl %edx, 0x60(%rax)
leaq 0x10a36(%rip), %rsi     # 0x17240
xorl %edi, %edi
cmpl $0x0, 0x4(%rsi,%rcx,4)
cmovnsl %edx, %edi
movl (%rsi,%rcx,4), %ecx
movl %edi, 0x60(%rax)
movl %ecx, 0x5c(%rax)
testl %ecx, %ecx
je 0x683c
movl 0x4c(%rax), %edx
leal (,%rdx,8), %esi
subl %ecx, %esi
addl $0x8, %esi
movl %esi, 0x54(%rax)
leal 0x7(,%rdx,8), %ecx
jmp 0x6843
orl $-0x1, 0x54(%rax)
pushq $-0x1
popq %rcx
movl %ecx, 0x58(%rax)
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcLockTime(CapsFdc*)
void FdcLockTime(PCAPSFDC pc)
{
	PCAPSDRIVE pd=pc->driveprc;
	int lo=0;
	int hi=pd->tracklen-1;
	UDWORD sum=pd->timebuf[hi];

	// binary search for the nearest item to the actual clock distance
	while (lo <= hi) {
		int mid=(lo+hi)/2;
		UDWORD atm=UDWORD(((UQUAD)pd->timebuf[mid]*pd->clockrev)/sum);

		if (atm <= pd->idistance)
			lo=mid+1;
		else
			hi=mid-1;
	}

	// safety check can only happen if distance was >= clockrev
	if ((unsigned)lo >= pd->tracklen)
		lo=pd->tracklen-1;

	UDWORD base=lo ? pd->timebuf[lo-1] : 0;
	UDWORD diff=pd->timebuf[lo]-base;

	// linear search for nearest distance
	for (hi=1; hi < 8; hi++) {
		UDWORD atm=UDWORD(((UQUAD)(base+(hi*diff)/8)*pd->clockrev)/sum);
		if (pd->idistance < atm)
			break;
	}

	pc->datalock=lo*8+hi-1;
	pc->datacycle=base;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq 0x100(%rdi), %rsi
movl 0x48(%rsi), %r10d
leal -0x1(%r10), %ecx
movq 0x40(%rsi), %r9
movslq %ecx, %rax
movl (%r9,%rax,4), %r8d
xorl %r11d, %r11d
movl %ecx, %ebx
cmpl %ebx, %r11d
jg 0x689d
leal (%r11,%rbx), %r14d
shrl %r14d
movl (%r9,%r14,4), %edx
movl 0x24(%rsi), %ebp
movl 0x28(%rsi), %eax
imulq %rdx, %rax
xorl %edx, %edx
divq %r8
cmpl %eax, %ebp
jb 0x6895
incl %r14d
movl %r14d, %r11d
jmp 0x686a
decl %r14d
movl %r14d, %ebx
jmp 0x686a
cmpl %r10d, %r11d
cmovbl %r11d, %ecx
xorl %r10d, %r10d
testl %ecx, %ecx
je 0x68b5
movslq %ecx, %rax
movl -0x4(%r9,%rax,4), %r11d
jmp 0x68ba
xorl %eax, %eax
xorl %r11d, %r11d
movl (%r9,%rax,4), %r9d
subl %r11d, %r9d
movl %r9d, %ebx
cmpl $-0x7, %r10d
je 0x68ed
movl %ebx, %edx
shrl $0x3, %edx
addl %r11d, %edx
movl 0x24(%rsi), %ebp
movl 0x28(%rsi), %eax
imulq %rdx, %rax
xorl %edx, %edx
divq %r8
cmpl %eax, %ebp
jb 0x68ed
decl %r10d
addl %r9d, %ebx
jmp 0x68c4
shll $0x3, %ecx
subl %r10d, %ecx
movl %ecx, 0x80(%rdi)
movl %r11d, 0x88(%rdi)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComReadNoise(CapsFdc*)
int FdcComReadNoise(PCAPSFDC pc)
{
	// clear dsr signals
	pc->aminfo&=~(CAPSFDC_AI_DSRREADY|CAPSFDC_AI_DSRAM|CAPSFDC_AI_DSRMA1);

	// get selected drive
	PCAPSDRIVE pd=pc->driveprc;

	// all cycles possibly advanced this time
	UDWORD dist=pd->idistance+(pc->clockreq-pc->clockact);

	// next bit complete divident, increased by clockrev
	UQUAD nextccn=(UQUAD)(pc->datalock+1)*pd->clockrev;

	// process until broken
	while (true) {
		// next bit is complete at this disk cycle
		UDWORD nextcyc=UDWORD(nextccn/pd->trackbits);

		// if not enough time to read bit, return
		if (dist < nextcyc) {
			pd->idistance=dist;
			pc->clockact=pc->clockreq;
			return 0;
		}

		// read bit into shifter
		FdcShiftBit(pc);

		// next bit
		pc->datalock++;
		nextccn+=pd->clockrev;

		// if index reached
		if (nextcyc >= pd->clockrev) {
			// adjust to index position
			dist-=pd->clockrev;
			pc->clockact+=pd->clockrev-pd->idistance;
			pd->idistance=0;
			pc->datalock=0;
			nextccn=pd->clockrev;

			// process disk index
			FdcIndex(pc, pc->driveact);

			// we read a complete byte exactly at index, set flag
			if (pc->aminfo & pc->amisigmask)
				return 1;

			// stop on end
			if (pc->endrequest)
				return 0;
		}

		// if a byte is complete, break and signal new byte
		if (pc->aminfo & pc->amisigmask) {
			int dst=pd->idistance;
			pd->idistance=nextcyc;
			pc->clockact+=nextcyc-dst;
			return 1;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
andb $-0x8, 0x61(%rdi)
movq 0x100(%rdi), %r12
movl 0x10(%rdi), %r13d
addl 0x24(%r12), %r13d
subl 0xc(%rdi), %r13d
movslq 0x80(%rdi), %rax
incq %rax
movl 0x28(%r12), %ebp
imulq %rax, %rbp
movq %rbp, %r14
movslq 0x50(%r12), %rcx
movq %r14, %rax
xorl %edx, %edx
divq %rcx
movq %rax, %r15
cmpl %r15d, %r13d
jb 0x69f9
movq %rbx, %rdi
callq 0x6c99
incl 0x80(%rbx)
movl 0x28(%r12), %ebp
cmpl %r15d, %ebp
jbe 0x69bd
addq %rbp, %r14
movl 0x64(%rbx), %eax
testl %eax, 0x60(%rbx)
je 0x6983
jmp 0x6a05
movl 0x24(%r12), %eax
movl %ebp, %ecx
subl %eax, %ecx
addl %ecx, 0xc(%rbx)
andl $0x0, 0x24(%r12)
andl $0x0, 0x80(%rbx)
movl 0xfc(%rbx), %esi
movq %rbx, %rdi
callq 0x65f0
movl 0x64(%rbx), %eax
testl %eax, 0x60(%rbx)
jne 0x6a2a
subl %ebp, %r13d
cmpl $0x0, 0x8(%rbx)
je 0x6980
xorl %eax, %eax
jmp 0x6a1b
movl %r13d, 0x24(%r12)
movl 0x10(%rbx), %ecx
xorl %eax, %eax
jmp 0x6a18
movl %r15d, %ecx
subl 0x24(%r12), %ecx
movl %r15d, 0x24(%r12)
addl 0xc(%rbx), %ecx
pushq $0x1
popq %rax
movl %ecx, 0xc(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rax
jmp 0x6a1b
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcReadBit(CapsFdc*)
int FdcReadBit(PCAPSFDC pc)
{
	// get selected drive
	PCAPSDRIVE pd=pc->driveprc;

	// get current position
	int lock=pc->datalock;

	// bit position in track buffer
	PUBYTE trk=pd->trackbuf+(lock>>3);
	UBYTE msk=1<<((lock&7)^7);

	return *trk & msk;
}

// Assembly:
movq 0x100(%rdi), %rax
movl 0x80(%rdi), %ecx
movq 0x38(%rax), %rax
movl %ecx, %edx
sarl $0x3, %edx
notb %cl
andb $0x7, %cl
pushq $0x1
popq %rsi
shll %cl, %esi
movslq %edx, %rcx
movzbl (%rax,%rcx), %eax
andl %esi, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFile.cpp
// Function: CCapsFile::Close()
int CCapsFile::Close()
{
	int res=0;

	if (file) {
		res = file->Close();
		delete file;
		file = NULL;
	}

	return res;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
testq %rdi, %rdi
je 0x6f67
movq (%rdi), %rax
callq *0x10(%rax)
movl %eax, %ebp
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x6f60
movq (%rdi), %rax
callq *0x8(%rax)
andq $0x0, 0x8(%rbx)
jmp 0x6f69
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFile.cpp
// Function: CCapsFile::Open(CapsFile*)
int CCapsFile::Open(PCAPSFILE pcf)
{
	int res=true;

	Close();

	if (!pcf)
		return res;

	if (pcf->flag & CFF_MEMMAP) {
		PCMEMORYFILE f = new CMemoryFile();
		file = f;
		int mode = (pcf->flag & CFF_MEMREF) ? 0 : BFFLAG_CREATE;
		res=f->Open(pcf->memmap, pcf->size, mode);
	}	else {
		PCDISKFILE f = new CDiskFile();
		file = f;
		int fm = (pcf->flag & CFF_WRITE) ? BFFLAG_WRITE : 0;
		if (pcf->flag & CFF_CREATE)
			fm |= BFFLAG_CREATE;
		res = f->Open(pcf->name, fm);
	}

	return res;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
callq 0x6f3a
testq %rbx, %rbx
je 0x6fdc
testb $0x2, 0x10(%rbx)
jne 0x6fe5
movl $0x228, %edi            # imm = 0x228
callq 0x31e0
movq %rax, %r15
movq %rax, %rdi
callq 0xbe7c
movq %r15, 0x8(%r14)
movl 0x10(%rbx), %edx
movl %edx, %eax
andl $0x1, %eax
shrl $0x2, %edx
andl $0x2, %edx
orl %eax, %edx
movq (%rbx), %rsi
movq %r15, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0xbed6
pushq $0x1
popq %rax
popq %rbx
popq %r14
popq %r15
retq
pushq $0x48
popq %rdi
callq 0x31e0
movq %rax, %r15
movq %rax, %rdi
callq 0xd334
movq %r15, 0x8(%r14)
movl 0x10(%rbx), %ecx
notl %ecx
shrl %ecx
andl $0x2, %ecx
movq 0x8(%rbx), %rsi
movslq 0x14(%rbx), %rdx
movq %r15, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0xd3e2
movq %rax, %rbx
pushq $0x48
popq %rsi
jmp 0x702b
movq %rax, %rbx
movl $0x228, %esi            # imm = 0x228
movq %r15, %rdi
callq 0x31f0
movq %rbx, %rdi
callq 0x3380
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFormatMFM.cpp
// Function: CAPSFormatDataToMFM(void*, unsigned int)
SDWORD __cdecl CAPSFormatDataToMFM(PVOID pformattrack, UDWORD flag)
{
	if (!pformattrack)
		return imgeGeneric;

	// structure revision is zero, unless newer one requested
	unsigned rev=0;
	if (flag & DI_LOCK_TYPE)
		rev=*(PUDWORD)pformattrack;

	// if unsupported type set the highest supported version
	if (rev > 0) {
		*(PUDWORD)pformattrack=0;
		return imgeUnsupportedType;
	}

	PCAPSFORMATTRACK pf=(PCAPSFORMATTRACK)pformattrack;

	// if buffer not set, return the required buffer size
	if (!pf->trackbuf || !pf->tracklen || !pf->buflen)
		return FmfmGetSize(pf);

	// track buffer should not exceed allocated memory
	if (pf->tracklen > pf->buflen)
		return imgeBufferShort;

	// calculate track size and check descriptors
	int res=FmfmGetSize(pf);

	// cancel if track definition error
	if (res != imgeOk)
		return res;

	// cancel if track size too short
	if (pf->tracklen < pf->bufreq)
		return imgeBufferShort;

	// error if data start position is invalid
	if (pf->startpos >= pf->tracklen)
		return imgeBadDataStart;

	// convert the data
	return FmfmConvert(pf);
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x70d1
movq %rdi, %rbx
btl $0x9, %esi
jae 0x70b1
cmpl $0x0, (%rbx)
je 0x70b1
andl $0x0, (%rbx)
pushq $0xf
jmp 0x70d3
cmpq $0x0, 0x10(%rbx)
je 0x70db
movl 0x18(%rbx), %eax
testl %eax, %eax
je 0x70db
movl 0x1c(%rbx), %ecx
testl %ecx, %ecx
je 0x70db
pushq $0x13
popq %rbp
cmpl %ecx, %eax
jbe 0x70e9
movl %ebp, %eax
jmp 0x70d4
pushq $0x2
popq %rax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x7114
movq %rbx, %rdi
callq 0x7114
testl %eax, %eax
jne 0x70d4
movl 0x18(%rbx), %ecx
movl %ebp, %eax
cmpl 0x20(%rbx), %ecx
jb 0x70d4
cmpl %ecx, 0x24(%rbx)
jae 0x7110
movq %rbx, %rdi
callq 0x71bd
xorl %eax, %eax
jmp 0x70d4
pushq $0x12
jmp 0x70d3
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFormatMFM.cpp
// Function: FmfmGetSize(CapsFormatTrack*)
int FmfmGetSize(PCAPSFORMATTRACK pf)
{
	// reset track size
	UDWORD len=0;
	pf->bufreq=0;

	// first gap size
	len+=pf->gapacnt;

	// cancel if invalid blocks
	if (pf->blockcnt && !pf->block)
		return imgeGeneric;

	// add length for each block
	for (int blk=0; blk < pf->blockcnt; blk++) {
		// get block
		PCAPSFORMATBLOCK pb=pf->block+blk;

		// add gap sizes
		len+=pb->gapacnt;
		len+=pb->gapbcnt;
		len+=pb->gapccnt;
		len+=pb->gapdcnt;

		// sum block data
		int sv=false;
		switch (pb->blocktype) {
			// index block; 3am, fc
			case cfrmbtIndex:
				len+=4;
				break;

			// data block; 3am, fe, 4hdr, 2crc, 3am, fb, data, 2crc
			case cfrmbtData:
				len+=16;
				len+=pb->sectorlen;
				sv=true;
				break;

			default:
				return imgeBadBlockType;
		}

		// if sector length used check its validity
		if (sv && FmfmSectorLength(pb->sectorlen)<0)
			return imgeBadBlockSize;
	}

	// set requested size in mfm
	pf->bufreq=len*2;

	return imgeOk;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
andl $0x0, 0x20(%rdi)
movl 0x4(%rdi), %r15d
movl 0x28(%rdi), %r12d
testl %r12d, %r12d
je 0x713a
cmpq $0x0, 0x2c(%rbx)
je 0x71a5
xorl %r13d, %r13d
testl %r12d, %r12d
cmovlel %r13d, %r12d
shlq $0x6, %r12
pushq $0x10
popq %rbp
cmpq %r13, %r12
je 0x719a
movq 0x2c(%rbx), %rax
addl (%rax,%r13), %r15d
addl 0x8(%rax,%r13), %r15d
addl 0x10(%rax,%r13), %r15d
addl 0x18(%rax,%r13), %r15d
movl 0x20(%rax,%r13), %ecx
cmpl $0x2, %ecx
je 0x717c
cmpl $0x1, %ecx
jne 0x71ac
addl $0x4, %r15d
jmp 0x7194
movl 0x30(%rax,%r13), %r14d
movl %r14d, %edi
callq 0x723f
testl %eax, %eax
js 0x71a9
addl %r14d, %r15d
addl $0x10, %r15d
addq $0x40, %r13
jmp 0x714b
addl %r15d, %r15d
movl %r15d, 0x20(%rbx)
xorl %ebp, %ebp
jmp 0x71ac
pushq $0x2
jmp 0x71ab
pushq $0x11
popq %rbp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFormatMFM.cpp
// Function: FmfmConvert(CapsFormatTrack*)
int FmfmConvert(PCAPSFORMATTRACK pf)
{
	// reset size
	pf->size=0;

	// reset size counter and mfm state
	UDWORD state=(0)<<15 ^ 0xffff;

	// write index gap
	state=FmfmWriteDataByte(pf, state, pf->gapavalue, pf->gapacnt);

	// process all blocks
	for (int blk=0; blk < pf->blockcnt; blk++) {
		// get block
		PCAPSFORMATBLOCK pb=pf->block+blk;

		// write block data
		switch (pb->blocktype) {
			// index block; 3am, fc,gap
			case cfrmbtIndex:
				state=FmfmWriteBlockIndex(pf, state, pb);
				break;

			// data block; 3am, fe, 4hdr, 2crc, 3am, fb, data, 2crc
			case cfrmbtData:
				state=FmfmWriteBlockData(pf, state, pb);
				break;
		}
	}

	// write gap size before index
	int gapbcnt=(pf->tracklen-pf->size)/2;
	if (gapbcnt > 0)
		state=FmfmWriteDataByte(pf, state, pf->gapbvalue, gapbcnt);

	return imgeOk;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
andl $0x0, 0x34(%rdi)
movl 0x4(%rdi), %ecx
movl 0x8(%rdi), %edx
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x725b
xorl %r14d, %r14d
xorl %r15d, %r15d
movslq 0x28(%rbx), %rcx
cmpq %rcx, %r15
jge 0x721d
movq 0x2c(%rbx), %rdx
movl 0x20(%rdx,%r14), %ecx
addq %r14, %rdx
cmpl $0x2, %ecx
je 0x720a
cmpl $0x1, %ecx
jne 0x7214
movq %rbx, %rdi
movl %eax, %esi
callq 0x72ba
jmp 0x7214
movq %rbx, %rdi
movl %eax, %esi
callq 0x7307
incq %r15
addq $0x40, %r14
jmp 0x71df
movl 0x18(%rbx), %ecx
subl 0x34(%rbx), %ecx
cmpl $0x2, %ecx
jb 0x7237
shrl %ecx
movl 0xc(%rbx), %edx
movq %rbx, %rdi
movl %eax, %esi
callq 0x725b
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFormatMFM.cpp
// Function: FmfmWriteDataByte(CapsFormatTrack*, unsigned int, unsigned int, int)
UDWORD FmfmWriteDataByte(PCAPSFORMATTRACK pf, UDWORD state, UDWORD value, int count)
{
	pf->size+=count*2;
	UDWORD pos=pf->startpos;

	// write mfm bytes
	while (count--) {
		UDWORD val=CDiskEncoding::mfmcode[value & 0xff] & state;
		state=(val & 1)<<15 ^ 0xffff;

		pf->trackbuf[pos++]=UBYTE(val>>8);
		if (pos >= pf->tracklen)
			pos=0;

		pf->trackbuf[pos++]=(UBYTE)val;
		if (pos >= pf->tracklen)
			pos=0;
	}

	pf->startpos=pos;

	return state;
}

// Assembly:
pushq %rbp
pushq %rbx
movl %esi, %eax
leal (%rcx,%rcx), %esi
addl %esi, 0x34(%rdi)
movl 0x24(%rdi), %esi
movzbl %dl, %edx
leaq 0x12306(%rip), %r8      # 0x19578
xorl %r9d, %r9d
subl $0x1, %ecx
jb 0x72b4
movq (%r8), %r10
andl (%r10,%rdx,4), %eax
movl %eax, %r10d
shll $0xf, %r10d
notl %r10d
movq 0x10(%rdi), %rbx
movl %esi, %ebp
incl %esi
movb %ah, (%rbx,%rbp)
cmpl 0x18(%rdi), %esi
cmovael %r9d, %esi
movq 0x10(%rdi), %r11
movb %al, (%r11,%rsi)
movzwl %r10w, %eax
incl %esi
cmpl 0x18(%rdi), %esi
cmovael %r9d, %esi
jmp 0x7275
movl %esi, 0x24(%rdi)
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFormatMFM.cpp
// Function: FmfmWriteBlockIndex(CapsFormatTrack*, unsigned int, CapsFormatBlock*)
UDWORD FmfmWriteBlockIndex(PCAPSFORMATTRACK pf, UDWORD state, PCAPSFORMATBLOCK pb)
{
	// gap before first am
	state=FmfmWriteDataByte(pf, state, pb->gapavalue, pb->gapacnt);

	// 3 am c2/5224
	state=FmfmWriteMarkByte(pf, state, 0x5224, 3);

	// fc
	state=FmfmWriteDataByte(pf, state, 0xfc, 1);

	// gap after first am
	state=FmfmWriteDataByte(pf, state, pb->gapbvalue, pb->gapbcnt);

	return state;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rdi, %r14
movl (%rdx), %ecx
movl 0x4(%rdx), %edx
callq 0x725b
pushq $0x3
popq %rcx
movq %r14, %rdi
movl $0x5224, %edx           # imm = 0x5224
callq 0x754d
pushq $0x1
popq %rcx
movq %r14, %rdi
movl %eax, %esi
movl $0xfc, %edx
callq 0x725b
movl 0x8(%rbx), %ecx
movl 0xc(%rbx), %edx
movq %r14, %rdi
movl %eax, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x725b
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFormatMFM.cpp
// Function: FmfmWriteMarkByte(CapsFormatTrack*, unsigned int, unsigned int, int)
UDWORD FmfmWriteMarkByte(PCAPSFORMATTRACK pf, UDWORD state, UDWORD value, int count)
{
	pf->size+=count*2;
	UDWORD pos=pf->startpos;
	UDWORD val=value & 0xffff;
	state=(val & 1)<<15 ^ 0xffff;

	// write mfm bytes
	while (count--) {
		pf->trackbuf[pos++]=UBYTE(val>>8);
		if (pos >= pf->tracklen)
			pos=0;

		pf->trackbuf[pos++]=(UBYTE)val;
		if (pos >= pf->tracklen)
			pos=0;
	}

	pf->startpos=pos;

	return state;
}

// Assembly:
leal (%rcx,%rcx), %eax
addl %eax, 0x34(%rdi)
movl 0x24(%rdi), %esi
movl %edx, %eax
shrl $0x8, %eax
xorl %r8d, %r8d
subl $0x1, %ecx
jb 0x758a
movq 0x10(%rdi), %r9
movl %esi, %r10d
incl %esi
movb %al, (%r9,%r10)
cmpl 0x18(%rdi), %esi
cmovael %r8d, %esi
movq 0x10(%rdi), %r9
movb %dl, (%r9,%rsi)
incl %esi
cmpl 0x18(%rdi), %esi
cmovael %r8d, %esi
jmp 0x755e
shll $0xf, %edx
notl %edx
movzwl %dx, %eax
movl %esi, 0x24(%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFormatMFM.cpp
// Function: FmfmCrc(unsigned short, unsigned int, int)
UWORD FmfmCrc(UWORD crc, UDWORD value, int count)
{
	value&=0xff;

	while (count--)
		crc=crctab_ccitt[value^(crc>>8)] ^ (crc << 8);

	return crc;
}

// Assembly:
movl %edi, %eax
movzbl %sil, %ecx
leaq 0x10b4d(%rip), %rsi     # 0x180f0
subl $0x1, %edx
jb 0x75b9
movzwl %ax, %edi
shrl $0x8, %edi
xorl %ecx, %edi
shll $0x8, %eax
xorw (%rsi,%rdi,2), %ax
jmp 0x75a3
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImage.cpp
// Function: CCapsImage::CompareImage()
int CCapsImage::CompareImage()
{
	PDISKTRACKINFO pti=di.pdt;

	int res=imgeOk;

	// default track size
	pti->tracklen=pti->ci.trksize;

	// generate 1 revolution
	pti->trackcnt=1;

	// unformatted track ignored
	if (pti->ci.dentype == cpdenNoise)
		pti->trackcnt=0;

	pti->tracklen*=pti->trackcnt;

	// allocate and set buffer
	if (pti->tracklen) {
		pti->trackbuf=new UBYTE[pti->tracklen];
		memset(pti->trackbuf, 0, pti->tracklen);
	}

	// set track size and pointer
	pti->trackdata[0]=pti->trackbuf;
	pti->tracksize[0]=0;
	pti->trackstart[0]=0;

	// decoder start position is always 0
	pti->comppos=0;
	pti->sdpos=0;

	// decode blocks
	if (pti->trackcnt) {
		int eblk=pti->compeblk;
		if (eblk < 0)
			eblk=pti->ci.blkcnt;
		else
			eblk++;

		for (int blk=pti->compsblk; blk < eblk; blk++)
			if ((res=CompareBlock(blk)) != imgeOk)
				return res;
	}

	pti->tracksize[0]=pti->comppos;
	return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x210(%rdi), %r12
movl 0x108(%r12), %r13d
xorl %eax, %eax
xorl %ecx, %ecx
cmpl $0x1, %r13d
setne %cl
movl %ecx, 0x28(%r12)
je 0x75f3
movl 0x110(%r12), %eax
movl %eax, 0x50(%r12)
testl %eax, %eax
je 0x761e
movslq %eax, %r15
movq %r15, %rdi
callq 0x3040
movq %rax, %r14
movq %rax, 0x48(%r12)
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x3110
jmp 0x7623
movq 0x48(%r12), %r14
andl $0x0, 0x80(%r12)
andl $0x0, 0x94(%r12)
andq $0x0, 0xbc(%r12)
xorl %ebp, %ebp
movq %r14, 0x58(%r12)
movl $0x0, %eax
cmpl $0x1, %r13d
je 0x7695
movl 0xcc(%r12), %r15d
testl %r15d, %r15d
js 0x7662
incl %r15d
jmp 0x766a
movl 0x128(%r12), %r15d
movl 0xc8(%r12), %r14d
cmpl %r15d, %r14d
jge 0x768d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x76ae
incl %r14d
testl %eax, %eax
je 0x7672
movl %eax, %ebp
jmp 0x769d
movl 0xbc(%r12), %eax
movl %eax, 0x80(%r12)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImage.cpp
// Function: CCapsImage::DecompressDump()
int CCapsImage::DecompressDump()
{
	// raw images can't be: compared, 16 bit aligned
	if (di.flag & (DI_LOCK_COMP | DI_LOCK_ALIGN))
		return imgeUnsupported;

	PDISKTRACKINFO pti = di.pdt;
	uint8_t *buf=di.data;

	CCTRawCodec ctr;

	// decompress data
	int res=ctr.DecompressDump(buf, pti->datasize);
	if (res == imgeOk) {
		ConvertDumpInfo(ctr.GetInfo());
	} else
		pti->type=dtitError;

	return res;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xc8, %rsp
testl $0x80000002, 0x208(%rdi) # imm = 0x80000002
je 0x794f
pushq $0x1
popq %rbx
jmp 0x79a4
movq %rdi, %r14
movq 0x1e8(%rdi), %rbx
movq 0x210(%rdi), %r12
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x4030
movl 0x24(%r12), %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4174
movl %eax, %ebx
testl %eax, %eax
je 0x798d
movl $0x1, (%r12)
jmp 0x799a
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x79ca
leaq 0x8(%rsp), %rdi
callq 0x405a
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x405a
movq %rbx, %rdi
callq 0x3380
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImage.cpp
// Function: CCapsImage::InitFirstBitTables()
void CCapsImage::InitFirstBitTables()
{
	// stop if already initialized
	if (fb_init)
		return;

	// initialize only once
	fb_init = 1;

	// process all positions
	for (int startbit = 0; startbit < 8; startbit++) {
		// position#0 is bit#7...position#7 is bit#0
		int bitmask = 1 << (7-startbit);

		// process all values
		for (int value = 0; value < 256; value++) {

			// find the first 0 bit starting with the current position
			int bitpos = startbit;
			for (int bm = bitmask; bm; bm >>= 1, bitpos++) {
				if (!(value & bm))
					break;
			}

			// store the position; 8 means not found
			f0b_table[startbit][value] = bitpos;

			// find the first 1 bit starting with the current position
			bitpos = startbit;
			for (int bm = bitmask; bm; bm >>= 1, bitpos++) {
				if (value & bm)
					break;
			}

			// store the position; 8 means not found
			f1b_table[startbit][value] = bitpos;
		}
	}
}

// Assembly:
cmpl $0x0, 0x109f1(%rip)     # 0x18544
je 0x7b56
retq
pushq %rbp
pushq %rbx
movl $0x1, 0x109e2(%rip)     # 0x18544
xorl %eax, %eax
movl $0x1, %edx
leaq 0x109e0(%rip), %rsi     # 0x18550
leaq 0x111d9(%rip), %rdi     # 0x18d50
cmpq $0x8, %rax
je 0x7bdd
movb $0x7, %cl
subb %al, %cl
movl %edx, %r8d
shll %cl, %r8d
movq %rax, %rcx
shlq $0x8, %rcx
leaq (%rsi,%rcx), %r9
addq %rdi, %rcx
xorl %r10d, %r10d
cmpq $0x100, %r10            # imm = 0x100
je 0x7bd8
movl %eax, %r11d
movl %r8d, %ebx
testl %r10d, %ebx
je 0x7bb3
shrl %ebx
incb %r11b
jmp 0x7ba7
movb %r11b, (%r10,%r9)
movl %eax, %r11d
movl %r8d, %ebx
testl %ebx, %ebx
je 0x7bcf
movl %ebx, %ebp
andl %r10d, %ebp
jne 0x7bcf
shrl %ebx
incb %r11b
jmp 0x7bbd
movb %r11b, (%r10,%rcx)
incq %r10
jmp 0x7b98
incq %rax
jmp 0x7b77
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImage.cpp
// Function: CCapsImage::UpdateDump()
int CCapsImage::UpdateDump()
{
	PDISKTRACKINFO pti = di.pdt;

	// get actual revolution number, restart after the last revolution
	int rev = dii.nextrev % pti->rawtrackcnt;

	// true if all the available revolutions should be returned
	int allrev = (pti->trackcnt == pti->rawtrackcnt);

	// if all revolutions used the used data must be revolution#0
	if (allrev)
		rev = 0;

	// save the real revolution number
	dii.realrev = rev;

	// set data buffer
	pti->trackbuf = pti->trackdata[rev];
	pti->tracklen = allrev ? pti->rawlen : pti->tracksize[rev];
	pti->trackbc = pti->tracklen << 3;
	pti->singletrackbc = pti->trackbc;

	// timing information is the same size as the current data, rev#0 for all revolutions
	pti->timecnt = pti->tracksize[rev];

	// the real size of the sampled timings
	int rawsize = pti->rawtimecnt;

	// the amount of timing to be copied track size or real size - whichever is shorter
	int tsize = std::min(rawsize, pti->timecnt);

	// copy the timing
	memcpy(pti->timebuf, pti->rawtimebuf, tsize*sizeof(UDWORD));

	// If sampled timing is shorter, fill the remaining area with 1000, default value
	// This does not change the average, since the previous data adds up to an average of 1000
	int pos;
	for (pos = tsize; pos < pti->timecnt; pos++) {
			pti->timebuf[pos] = 1000;
	}

	// reset alternate density
	pti->timebuf[pos] = 0;

	// density map conversion
	if (di.flag & DI_LOCK_DENALT)
		ConvertDensity(pti);

	UpdateImage(rev);

	return imgeOk;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x210(%rdi), %r14
movl 0x3c(%rdi), %eax
movl 0x28(%r14), %ecx
movl 0x2c(%r14), %esi
cltd
idivl %esi
leaq 0x30(%r14), %rax
xorl %ebp, %ebp
cmpl %esi, %ecx
cmovnel %edx, %ebp
movl %ebp, 0x44(%rdi)
movslq %ebp, %rcx
movq 0x58(%r14,%rcx,8), %rdx
leaq 0x80(%r14,%rcx,4), %rcx
cmovneq %rcx, %rax
movq %rdx, 0x48(%r14)
movl (%rax), %eax
movl %eax, 0x50(%r14)
shll $0x3, %eax
movl %eax, 0xe8(%r14)
movl %eax, 0xec(%r14)
movl (%rcx), %eax
movl %eax, 0xa8(%r14)
movl 0x34(%r14), %ecx
cmpl %ecx, %eax
cmovll %eax, %ecx
movq 0xb0(%r14), %rdi
movq 0x38(%r14), %rsi
movslq %ecx, %r15
leaq (,%r15,4), %rdx
callq 0x3160
movq 0xb0(%r14), %rax
movq %r15, %rcx
shlq $0x20, %rcx
movabsq $0x100000000, %rdx      # imm = 0x100000000
movslq 0xa8(%r14), %rsi
cmpq %rsi, %r15
jge 0x7e0f
movl $0x3e8, (%rax,%r15,4)   # imm = 0x3E8
incq %r15
addq %rdx, %rcx
jmp 0x7df3
sarq $0x1e, %rcx
andl $0x0, (%rax,%rcx)
testb $0x4, 0x209(%rbx)
je 0x7e2b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x953e
movq %rbx, %rdi
movl %ebp, %esi
callq 0x8472
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImage.cpp
// Function: CCapsImage::AddWeakBitArea(int, int, int)
void CCapsImage::AddWeakBitArea(int group, int bitpos, int size)
{
	DiskDataMark ddm;
	ddm.group = group;
	ddm.position = bitpos;
	ddm.size = size;
	AddFD(di.pdt, &ddm, 1, (CAPS_MTRS * DEF_CTRAW_FDALLOC));
}

// Assembly:
subq $0x18, %rsp
leaq 0xc(%rsp), %rax
movl %esi, (%rax)
movl %edx, 0x4(%rax)
movl %ecx, 0x8(%rax)
movq 0x210(%rdi), %rdi
pushq $0x1
popq %rdx
movq %rax, %rsi
movl $0x140, %ecx            # imm = 0x140
callq 0xce3e
addq $0x18, %rsp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::InitSystem()
void CCapsImageStd::InitSystem()
{
	// set bitfield write length supported
	maxwritelen = MAX_BITBUFFER_LEN;

	// keep number of bits to read at maximum supported by streaming for raw encoding
	rawreadlen=MAX_STREAMBIT;

	// initialize mfm encoding tables
	CDiskEncoding::InitMFM(0x10000);

	// keep number of bits to read at maximum supported by mfm encoding
	mfmreadlen=CDiskEncoding::mfmcodebit;

	// mfm encoding table index mask
	mfmindexmask=(1 << mfmreadlen)-1;

	// the mfm encoding table assumes the last bit to be 0, correct encoding if it's 1
	// 1: 1-01 -> 1-01 unchanged after AND, msb already 0
	// 0: 1-10 -> 1-00 AND clears msb
	mfmmsbclear=(1 << ((mfmreadlen*2)-1))-1;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movabsq $0x2000000020, %rax     # imm = 0x2000000020
movq %rax, 0x218(%rdi)
movl $0x10000, %edi          # imm = 0x10000
callq 0xb600
leaq 0x11644(%rip), %rax     # 0x19574
movl (%rax), %ecx
pushq $-0x1
popq %rax
movl %eax, %edx
shll %cl, %edx
movl %ecx, 0x220(%rbx)
addl %ecx, %ecx
decb %cl
shll %cl, %eax
notl %edx
movl %edx, 0x224(%rbx)
notl %eax
movl %eax, 0x228(%rbx)
popq %rbx
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::Lock(CapsFile*)
int CCapsImageStd::Lock(PCAPSFILE pcf)
{
	// release image data
	Unlock();

	// try to lock
	switch (loader.Lock(pcf)) {
		// file open error
		case CCapsLoader::ccidErrFile:
			return imgeOpen;

		// not a caps file
		case CCapsLoader::ccidErrType:
			return imgeType;

		// yes, caps file
		case CCapsLoader::ccidCaps:
			break;

		// unknown problem
		default:
			return imgeGeneric;
	}

	// store open mode
	dii.readonly=(pcf->flag & CFF_WRITE) ? 0 : 1;

	// scan whole file for information
	int res=ScanImage();
	if (res != imgeOk)
		return res;

	return CheckEncoder(dii.ci.encoder, dii.ci.encrev);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rax
callq *0x18(%rax)
leaq 0xd0(%rbx), %rdi
movq %r14, %rsi
callq 0xae86
testl %eax, %eax
je 0x803f
cmpl $0x1, %eax
je 0x803b
cmpl $0x2, %eax
jne 0x806c
pushq $0x6
jmp 0x806e
pushq $0x5
jmp 0x806e
movl 0x10(%r14), %eax
notl %eax
andl $0x1, %eax
movl %eax, 0x14(%rbx)
movq %rbx, %rdi
callq 0x8078
testl %eax, %eax
jne 0x806f
movl 0x50(%rbx), %esi
movl 0x54(%rbx), %edx
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x8336
pushq $0x2
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::LoadTrack(DiskTrackInfo*, unsigned int)
int CCapsImageStd::LoadTrack(PDISKTRACKINFO pti, UDWORD flag)
{
	// set lock flags
	di.pdt=pti;
	di.flag=flag;

	int res = imgeOk;

	// update the track image if already available
	if (pti->trackcnt) {
		switch (pti->type) {
			case dtitCapsDump:
				res = UpdateDump();
				break;

			case dtitCapsImage:
				res = UpdateImage(0);
				break;

			default:
				res = imgeGeneric;
				break;
		}

		return res;
	}

	// process stored track data or generate data
	if (pti->datasize) {
		// load data, check data header
		loader.SetPosition(pti->datapos);
		if (loader.ReadChunk() == CCapsLoader::ccidData) {
			// allocate data buffer if needed
			AllocDiskData(pti->datasize);
			di.datacount=pti->datasize;

			// load and decode data
			if (loader.ReadData(di.data) == pti->datasize) {
				switch (pti->type) {
					case dtitCapsDump:
						res=DecompressDump();
						break;

					case dtitCapsImage:
						res=DecodeImage();
						break;

					default:
						res=imgeGeneric;
						break;
				}
			} else
				res=imgeGeneric;
		} else
			res=imgeGeneric;
	} else {
		// generate data
		switch (pti->type) {
			case dtitCapsImage:
				di.datacount=0;
				res=DecodeImage();
				break;

			default:
				res=imgeGeneric;
				break;
		}
	}

	return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, 0x210(%rdi)
movl %edx, 0x208(%rdi)
cmpl $0x0, 0x28(%rsi)
je 0x83be
movl (%r14), %eax
cmpl $0x3, %eax
je 0x8435
cmpl $0x2, %eax
jne 0x8462
movq (%rbx), %rax
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmpq *0x40(%rax)
cmpl $0x0, 0x24(%r14)
je 0x8443
leaq 0xd0(%rbx), %r15
movl 0x20(%r14), %esi
movq %r15, %rdi
callq 0xb1dc
movq %r15, %rdi
xorl %esi, %esi
callq 0xaef0
pushq $0x2
popq %rbp
cmpl $0xa, %eax
jne 0x8465
movl 0x24(%r14), %esi
movq %rbx, %rdi
callq 0x84fc
movl 0x24(%r14), %eax
movl %eax, 0x1f4(%rbx)
movq 0x1e8(%rbx), %rsi
movq %r15, %rdi
callq 0xb0f6
cmpl 0x24(%r14), %eax
jne 0x8465
movl (%r14), %eax
cmpl $0x3, %eax
je 0x8450
cmpl $0x2, %eax
jne 0x8465
movq (%rbx), %rax
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmpq *0x38(%rax)
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8472
jmp 0x8465
cmpl $0x3, (%r14)
jne 0x8462
andl $0x0, 0x1f4(%rbx)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x8530
pushq $0x2
popq %rbp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq