// File: /workspace/github_c_makefile_star2_O0/jarun[P]nnn/src/nnn.c
// Function: handle_context_switch
static int handle_context_switch(enum action sel)
{
	int r = -1;

	switch (sel) {
	case SEL_CYCLE: // fallthrough
	case SEL_CYCLER:
		/* visit next and previous contexts */
		r = cfg.curctx;
		if (sel == SEL_CYCLE)
			do
				r = (r + 1) & ~CTX_MAX;
			while (!g_ctx[r].c_cfg.ctxactive);
		else {
			do /* Attempt to create a new context */
				r = (r + 1) & ~CTX_MAX;
			while (g_ctx[r].c_cfg.ctxactive && (r != cfg.curctx));

			if (r == cfg.curctx) /* If all contexts are active, reverse cycle */
				do
					r = (r + (CTX_MAX - 1)) & (CTX_MAX - 1);
				while (!g_ctx[r].c_cfg.ctxactive);
		} // fallthrough
	default: /* SEL_CTXN */
		if (sel >= SEL_CTX1) /* CYCLE keys are lesser in value */
			r = sel - SEL_CTX1; /* Save the next context id */

		if (cfg.curctx == r) {
			if (sel == SEL_CYCLE)
				(r == CTX_MAX - 1) ? (r = 0) : ++r;
			else if (sel == SEL_CYCLER)
				(r == 0) ? (r = CTX_MAX - 1) : --r;
			else
				return -1;
		}
	}

	return r;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl %edi, -0x8(%rbp)
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
movl -0x8(%rbp), %eax
addl $-0x15, %eax
subl $0x1, %eax
ja 0x11e5f
jmp 0x11d5f
movl 0xe76b(%rip), %eax      # 0x204d0
shrl $0xd, %eax
andl $0x7, %eax
movl %eax, -0xc(%rbp)
cmpl $0x15, -0x8(%rbp)
jne 0x11db4
jmp 0x11d76
movl -0xc(%rbp), %eax
addl $0x1, %eax
andl $-0x5, %eax
movl %eax, -0xc(%rbp)
movslq -0xc(%rbp), %rcx
leaq 0x10103(%rip), %rax     # 0x21e90
imulq $0x2138, %rcx, %rcx     # imm = 0x2138
addq %rcx, %rax
movl 0x2130(%rax), %eax
shrl $0x9, %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x11d76
jmp 0x11e5d
jmp 0x11db6
movl -0xc(%rbp), %eax
addl $0x1, %eax
andl $-0x5, %eax
movl %eax, -0xc(%rbp)
movslq -0xc(%rbp), %rcx
leaq 0x100c3(%rip), %rax     # 0x21e90
imulq $0x2138, %rcx, %rcx     # imm = 0x2138
addq %rcx, %rax
movl 0x2130(%rax), %ecx
shrl $0x9, %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xd(%rbp)
je 0x11e04
movl -0xc(%rbp), %eax
movl 0xe6da(%rip), %ecx      # 0x204d0
shrl $0xd, %ecx
andl $0x7, %ecx
cmpl %ecx, %eax
setne %al
movb %al, -0xd(%rbp)
movb -0xd(%rbp), %al
testb $0x1, %al
jne 0x11db6
movl -0xc(%rbp), %eax
movl 0xe6bc(%rip), %ecx      # 0x204d0
shrl $0xd, %ecx
andl $0x7, %ecx
cmpl %ecx, %eax
jne 0x11e5b
jmp 0x11e20
movl -0xc(%rbp), %eax
addl $0x3, %eax
andl $0x3, %eax
movl %eax, -0xc(%rbp)
movslq -0xc(%rbp), %rcx
leaq 0x10059(%rip), %rax     # 0x21e90
imulq $0x2138, %rcx, %rcx     # imm = 0x2138
addq %rcx, %rax
movl 0x2130(%rax), %eax
shrl $0x9, %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x11e20
jmp 0x11e5b
jmp 0x11e5d
jmp 0x11e5f
cmpl $0x17, -0x8(%rbp)
jb 0x11e6e
movl -0x8(%rbp), %eax
subl $0x17, %eax
movl %eax, -0xc(%rbp)
movl 0xe65c(%rip), %eax      # 0x204d0
shrl $0xd, %eax
andl $0x7, %eax
cmpl -0xc(%rbp), %eax
jne 0x11ecc
cmpl $0x15, -0x8(%rbp)
jne 0x11e9f
cmpl $0x3, -0xc(%rbp)
jne 0x11e94
movl $0x0, -0xc(%rbp)
jmp 0x11e9d
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x11eca
cmpl $0x16, -0x8(%rbp)
jne 0x11ebf
cmpl $0x0, -0xc(%rbp)
jne 0x11eb4
movl $0x3, -0xc(%rbp)
jmp 0x11ebd
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x11ec8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x11ed4
jmp 0x11eca
jmp 0x11ecc
jmp 0x11ece
movl -0xc(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)