// File: /workspace/github_c_makefile_star2_O1/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:
movl (%rdi), %ecx
btl $0xa, %ecx
jb 0xa2a5
btl $0xb, %ecx
jb 0xa2ca
cmpb $0x28, %sil
setae %al
testb $0x8, %cl
sete %dl
testb %dl, %al
jne 0xa2c7
cmpb $0x23, %sil
setae %al
testb $0xc, %cl
sete %dl
testb %dl, %al
jne 0xa2c7
xorl %eax, %eax
cmpb $0x1, %sil
je 0xa2c9
movzbl %sil, %edx
cmpl $0x2a, %edx
je 0xa2c9
cmpl $0x12, %edx
jne 0xa364
notl %ecx
xorl %edx, %edx
testl $0x1002, %ecx           # imm = 0x1002
movl $0x11, %eax
jmp 0xa34e
cmpb $0x28, %sil
setae %al
testb $0x8, %cl
sete %dl
testb %dl, %al
jne 0xa2c7
cmpb $0x23, %sil
setae %al
testb $0xc, %cl
sete %dl
testb %dl, %al
je 0xa2e9
xorl %eax, %eax
retq
movzbl %sil, %edx
cmpl $0x22, %edx
jle 0xa30c
movb $0x1, %al
cmpl $0x23, %edx
je 0xa327
cmpl $0x28, %edx
je 0xa2c9
cmpl $0x2a, %edx
je 0xa33e
jmp 0xa36f
cmpb $0x2a, %sil
je 0xa2c7
movzbl %sil, %eax
cmpl $0x12, %eax
je 0xa352
cmpl $0x11, %eax
jne 0xa36f
andl $0x1002, %ecx           # imm = 0x1002
cmpl $0x2, %ecx
sete %al
xorb $0x13, %al
retq
cmpl $0x11, %edx
je 0xa337
cmpl $0x12, %edx
jne 0xa36f
notl %ecx
xorl %edx, %edx
testl $0x1002, %ecx           # imm = 0x1002
movl $0x13, %eax
jmp 0xa34e
testb $0xc, %cl
je 0xa2c9
cmpb $0x12, %sil
je 0xa316
cmpl $0x11, %edx
jne 0xa36f
movb $0x29, %al
testb $0x8, %cl
jne 0xa2c9
andl $0x1002, %ecx           # imm = 0x1002
xorl %edx, %edx
cmpl $0x2, %ecx
movl $0x12, %eax
cmovnel %edx, %eax
retq
notl %ecx
movb $0x1, %al
testl $0x1002, %ecx           # imm = 0x1002
je 0xa2c9
jmp 0xa36f
cmpb $0x11, %sil
ja 0xa36f
decb %sil
jmp 0xa372
incb %sil
movl %esi, %eax
retq