// File: /workspace/github_c_makefile_star2_O2/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 0xaab9
btl $0xb, %ecx
jb 0xaade
cmpb $0x28, %sil
setae %al
testb $0x8, %cl
sete %dl
testb %dl, %al
jne 0xaadb
cmpb $0x23, %sil
setae %al
testb $0xc, %cl
sete %dl
testb %dl, %al
jne 0xaadb
xorl %eax, %eax
cmpb $0x1, %sil
je 0xaadd
movzbl %sil, %edx
cmpl $0x2a, %edx
je 0xaadd
cmpl $0x12, %edx
jne 0xab5d
notl %ecx
xorl %edx, %edx
testw $0x1002, %cx            # imm = 0x1002
pushq $0x11
jmp 0xab4b
cmpb $0x28, %sil
setae %al
testb $0x8, %cl
sete %dl
testb %dl, %al
jne 0xaadb
cmpb $0x23, %sil
setae %al
testb $0xc, %cl
sete %dl
testb %dl, %al
je 0xab00
xorl %eax, %eax
retq
cmpb $0x11, %sil
je 0xab37
movzbl %sil, %edx
cmpl $0x12, %edx
je 0xab23
movb $0x1, %al
cmpl $0x23, %edx
je 0xab30
cmpl $0x28, %edx
je 0xaadd
cmpl $0x2a, %edx
je 0xab3e
jmp 0xab68
cmpb $0x2a, %sil
je 0xaadb
movzbl %sil, %eax
cmpl $0x12, %eax
je 0xab50
cmpl $0x11, %eax
jne 0xab68
andl $0x1002, %ecx           # imm = 0x1002
cmpl $0x2, %ecx
sete %al
xorb $0x13, %al
retq
notl %ecx
xorl %edx, %edx
testw $0x1002, %cx            # imm = 0x1002
pushq $0x13
jmp 0xab4b
testb $0xc, %cl
jne 0xab68
jmp 0xaadd
movb $0x29, %al
testb $0x8, %cl
jne 0xaadd
andl $0x1002, %ecx           # imm = 0x1002
xorl %edx, %edx
cmpl $0x2, %ecx
pushq $0x12
popq %rax
cmovnel %edx, %eax
retq
notl %ecx
movb $0x1, %al
testw $0x1002, %cx            # imm = 0x1002
jne 0xab68
jmp 0xaadd
cmpb $0x11, %sil
ja 0xab68
decb %sil
jmp 0xab6b
incb %sil
movl %esi, %eax
retq