// File: /workspace/github_c_makefile_star2_O3/excess-c64[P]lib1541img/src/lib/1541img/cbmdosfs.c
// Function: nextTrack
static uint8_t nextTrack(const CbmdosFsOptions *opts, uint8_t trackno)
{
    if (opts->flags & CFF_TALLOC_TRACKLOAD)
    {
	if (trackno >= 40 && !(opts->flags & CFF_42TRACK))
	{
	    return 0;
	}
	if (trackno >= 35 &&
		!(opts->flags & (CFF_40TRACK | CFF_42TRACK)))
	{
	    return 0;
	}
	if (trackno == 42) return 0;
	if (trackno == 17)
	{
	    if ((opts->flags & CFF_FILESONDIRTRACK) &&
		    !(opts->flags & CFF_TALLOC_PREFDIRTRACK))
	    {
		return 18;
	    }
	    return 19;
	}
	if (trackno == 18
		&& (opts->flags & CFF_FILESONDIRTRACK)
		&& (opts->flags & CFF_TALLOC_PREFDIRTRACK))
	{
	    return 1;
	}
	return trackno + 1;
    }
    else if (opts->flags & CFF_TALLOC_SIMPLE)
    {
	if (trackno == 42)
	{
	    if ((opts->flags & CFF_FILESONDIRTRACK) &&
		    !(opts->flags & CFF_TALLOC_PREFDIRTRACK))
	    {
		return 18;
	    }
	    return 0;
	}
	if (trackno == 40 || (trackno == 35 && !(opts->flags &
			(CFF_40TRACK | CFF_42TRACK))))
	{
	    return 1;
	}
	if (trackno == 17)
	{
	    if (opts->flags & CFF_42TRACK)
	    {
		return 41;
	    }
	    if ((opts->flags & CFF_FILESONDIRTRACK) &&
		    !(opts->flags & CFF_TALLOC_PREFDIRTRACK))
	    {
		return 18;
	    }
	    return 0;
	}
	if (trackno == 18)
	{
	    if ((opts->flags & CFF_FILESONDIRTRACK)
		    && (opts->flags & CFF_TALLOC_PREFDIRTRACK))
	    {
		return 19;
	    }
	    return 0;
	}
	return trackno + 1;
    }
    else
    {
	if (trackno >= 40 && !(opts->flags & CFF_42TRACK))
	{
	    return 0;
	}
	if (trackno >= 35 &&
		!(opts->flags & (CFF_40TRACK | CFF_42TRACK)))
	{
	    return 0;
	}
	if (trackno == 42) return 0;
	if (trackno == 1) return 0;
	if (trackno == 18)
	{
	    if ((opts->flags & CFF_FILESONDIRTRACK)
		    && (opts->flags & CFF_TALLOC_PREFDIRTRACK))
	    {
		return 17;
	    }
	    return 0;
	}
	if (trackno < 18) return trackno - 1;
	return trackno + 1;
    }
}

// Assembly:
btl $0xa, %edi
jb 0xaedc
btl $0xb, %edi
jb 0xaf03
cmpb $0x28, %sil
setae %al
testb $0x8, %dil
sete %cl
testb %cl, %al
jne 0xaf00
cmpb $0x23, %sil
setae %al
testb $0xc, %dil
sete %cl
testb %cl, %al
jne 0xaf00
xorl %eax, %eax
cmpb $0x1, %sil
je 0xaf02
movzbl %sil, %ecx
cmpl $0x2a, %ecx
je 0xaf02
cmpl $0x12, %ecx
jne 0xaf92
notl %edi
xorl %ecx, %ecx
testl $0x1002, %edi           # imm = 0x1002
movl $0x11, %eax
jmp 0xaf7d
cmpb $0x28, %sil
setae %al
testb $0x8, %dil
sete %cl
testb %cl, %al
jne 0xaf00
cmpb $0x23, %sil
setae %al
testb $0xc, %dil
sete %cl
testb %cl, %al
je 0xaf1f
xorl %eax, %eax
retq
movzbl %sil, %ecx
cmpl $0x22, %ecx
jle 0xaf42
movb $0x1, %al
cmpl $0x23, %ecx
je 0xaf5d
cmpl $0x28, %ecx
je 0xaf02
cmpl $0x2a, %ecx
je 0xaf6d
jmp 0xaf9d
cmpb $0x2a, %sil
je 0xaf00
movzbl %sil, %eax
cmpl $0x12, %eax
je 0xaf81
cmpl $0x11, %eax
jne 0xaf9d
andl $0x1002, %edi           # imm = 0x1002
cmpl $0x2, %edi
sete %al
xorb $0x13, %al
retq
cmpl $0x11, %ecx
je 0xaf65
cmpl $0x12, %ecx
jne 0xaf9d
notl %edi
xorl %ecx, %ecx
testl $0x1002, %edi           # imm = 0x1002
movl $0x13, %eax
jmp 0xaf7d
testb $0xc, %dil
jne 0xaf9d
jmp 0xaf02
movb $0x29, %al
testb $0x8, %dil
jne 0xaf02
andl $0x1002, %edi           # imm = 0x1002
xorl %ecx, %ecx
cmpl $0x2, %edi
movl $0x12, %eax
cmovnel %ecx, %eax
retq
notl %edi
movb $0x1, %al
testl $0x1002, %edi           # imm = 0x1002
jne 0xaf9d
jmp 0xaf02
cmpb $0x11, %sil
ja 0xaf9d
decb %sil
jmp 0xafa0
incb %sil
movl %esi, %eax
retq