// File: /workspace/github_c_makefile_star2_O1/Oric4ever[P]lcc65/6502/build/../src/stmt.c
// Function: swcode
static int swcode(swp, b, lb, ub, n) struct swtch *swp; int lb, ub, n, b[]; {
	int hilab, k, l, lolab, median, u, *v;

	v = swp->values;
	median = ((float)v[b[lb]] + (float)v[b[ub+1]-1] + 1)/2;
	for (l = lb, u = ub; l <= u; ) {
		k = (l + u)/2;
		if (v[b[k]] > median)
			u = k - 1;
		else if (v[b[k+1]-1] < median)
			l = k + 1;
		else
			break;
	}
	if (l > u) {	/* which of two buckets is closest to the median? */
		l = b[k];
		u = b[k+1] - 1;
		if (median < v[l] && k > lb && v[l] - median > median - v[l-1])
			k--;
		else if (median > v[u] && k < ub && median - v[u] > v[u+1] - median)
			k++;
	}
	l = b[k];
	u = b[k+1] - 1;
	lolab = hilab = swp->deflab->u.l.label;
	if (k > lb) {
		lolab = 0;
		if (k < ub)
			hilab = genlabel(1);
	} else if (k < ub)
		hilab = 0;
	if (n == 0)
		lolab = hilab = 0;
	if (u - l + 1 <= 3) {
		int i;
		for (i = l; i <= u; i++)
			cmp(EQ, swp->sym, swp->values[i], swp->labels[i]->u.l.label);
		if (lolab && lolab == hilab)
			branch(lolab);
		else {
			if (lolab)
				cmp(LT, swp->sym, swp->values[l], lolab);
			if (hilab)
				cmp(GT, swp->sym, swp->values[u], hilab);
			walk(0, 0, 0);
		}
	} else {
		int lab = genlabel(1);
		Symbol tab = genident(STATIC, array(voidptype, u - l + 1, 0), GLOBAL);
		cmp(LT, swp->sym, swp->values[l], lolab ? lolab : lab);
		cmp(GT, swp->sym, swp->values[u], hilab ? hilab : lab);
		walk(tree(JUMP, voidtype, rvalue((*opnode['+'])(ADD, pointer(idnode(tab)),
			(*opnode['-'])(SUB, cast(idnode(swp->sym), inttype),
				constnode(swp->values[l], inttype)))), 0), 0, 0);
		code(Switch);
		codelist->u.swtch.sym = swp->sym;
		codelist->u.swtch.deflab = swp->deflab;
		codelist->u.swtch.table = tab;
		codelist->u.swtch.size = u - l + 1;
		codelist->u.swtch.values = &swp->values[l];
		codelist->u.swtch.labels = &swp->labels[l];
		branch(0);
		definelab(lab);
		if (swp->values[u] - swp->values[l] + 1 >= 10000)
			warning("switch generates a huge table\n");
	}
	if (k > lb)
		n = swcode(swp, b, lb, k - 1, n - 1);
	if (k < ub) {
		if (hilab)
			definelab(hilab);
		n = swcode(swp, b, k + 1, ub, n - 1);
	}
	return n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r8d, %r13d
movl %ecx, %ebp
movq %rsi, %r14
movq %rdi, %r15
movslq %ecx, %rax
movq %rax, 0x60(%rsp)
movl %ecx, 0x10(%rsp)
movq 0x20(%r15), %rax
movslq %edx, %rdi
movslq (%r14,%rdi,4), %rcx
cvtsi2ssl (%rax,%rcx,4), %xmm0
movq 0x60(%rsp), %rsi
movslq 0x4(%r14,%rsi,4), %rcx
xorps %xmm1, %xmm1
cvtsi2ssl -0x4(%rax,%rcx,4), %xmm1
addss %xmm0, %xmm1
addss 0x9e29(%rip), %xmm1     # 0x2049c
mulss 0x9e25(%rip), %xmm1     # 0x204a0
cvttss2si %xmm1, %ecx
cmpl %esi, %edi
setg %r10b
jle 0x16689
jmp 0x166c4
movl %ebp, %esi
movl %edx, %edi
leal (%rsi,%rdi), %r8d
movl %r8d, %ebx
shrl $0x1f, %ebx
addl %r8d, %ebx
sarl %ebx
movslq %ebx, %r8
movslq (%r14,%r8,4), %r9
cmpl %ecx, (%rax,%r9,4)
jle 0x166ae
leal -0x1(%rbx), %esi
jmp 0x166bc
movslq 0x4(%r14,%r8,4), %rdi
cmpl %ecx, -0x4(%rax,%rdi,4)
jge 0x166c4
leal 0x1(%rbx), %edi
cmpl %esi, %edi
setg %r10b
jle 0x1668d
testb $0x1, %r10b
je 0x1670f
movslq %ebx, %rsi
movslq 0x4(%r14,%rsi,4), %r9
cmpl %edx, %ebx
jle 0x166f2
movslq (%r14,%rsi,4), %rsi
movl (%rax,%rsi,4), %edi
subl %ecx, %edi
jle 0x166f2
movl %ecx, %r8d
subl -0x4(%rax,%rsi,4), %r8d
cmpl %r8d, %edi
jle 0x166f2
decl %ebx
jmp 0x1670f
cmpl %ebp, %ebx
jge 0x1670f
movl %ecx, %esi
subl -0x4(%rax,%r9,4), %esi
jle 0x1670f
leal 0x1(%rbx), %edi
movl (%rax,%r9,4), %eax
subl %ecx, %eax
cmpl %eax, %esi
cmovlel %ebx, %edi
movl %edi, %ebx
movslq %ebx, %rax
movslq (%r14,%rax,4), %rsi
movslq 0x4(%r14,%rax,4), %rdi
movq 0x10(%r15), %rax
movl 0x48(%rax), %eax
movl %edx, 0x14(%rsp)
cmpl %edx, %ebx
jle 0x1674d
xorl %r12d, %r12d
cmpl %ebp, %ebx
jge 0x1675a
movq %rdi, 0x8(%rsp)
movl $0x1, %edi
movq %rsi, %rbp
callq 0x1769a
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
jmp 0x1675a
cmpl %ebp, %ebx
movl %eax, %r12d
movl $0x0, %ecx
cmovll %ecx, %eax
testl %r13d, %r13d
cmovel %r13d, %r12d
movl %r13d, 0x18(%rsp)
cmovel %r13d, %eax
leal -0x1(%rdi), %edx
movl %edx, %r13d
subl %esi, %r13d
cmpl $0x2, %r13d
movl %eax, 0x4(%rsp)
movq %rsi, 0x20(%rsp)
jg 0x167ed
movq %rdi, 0x8(%rsp)
cmpl %esi, %edi
jle 0x167c1
movq 0x8(%rsp), %rax
movl %eax, %ebp
movq 0x20(%rsp), %r13
subl %r13d, %ebp
movq (%r15), %rsi
movq 0x20(%r15), %rax
movl (%rax,%r13,4), %edx
movq 0x28(%r15), %rax
movq (%rax,%r13,8), %rax
movl 0x48(%rax), %ecx
movl $0x1e0, %edi            # imm = 0x1E0
callq 0x16a92
incq %r13
decl %ebp
jne 0x1679a
testl %r12d, %r12d
movl 0x4(%rsp), %ecx
je 0x169e8
cmpl %ecx, %r12d
jne 0x169e8
movl %r12d, %edi
callq 0x15554
movl 0x10(%rsp), %ebp
movl 0x18(%rsp), %r13d
jmp 0x16a3f
movl %eax, %ebp
incl %r13d
movl $0x1, %edi
movl %r13d, 0x34(%rsp)
movl %edx, 0x28(%rsp)
callq 0x1769a
movl %eax, 0x1c(%rsp)
leaq 0x1b7e0(%rip), %rax     # 0x31ff0
movq (%rax), %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x18a62
movl $0x51, %edi
movq %rax, %rsi
movl $0x3, %edx
callq 0x175a8
movq %rax, 0x8(%rsp)
movq (%r15), %rsi
movq 0x20(%r15), %rax
movq 0x20(%rsp), %rcx
leaq (,%rcx,4), %rdx
movq %rdx, 0x58(%rsp)
movl (%rax,%rcx,4), %edx
testl %r12d, %r12d
movl 0x1c(%rsp), %r13d
cmovel %r13d, %r12d
movl $0x220, %edi            # imm = 0x220
movl %r12d, %ecx
callq 0x16a92
movq (%r15), %rsi
movq 0x20(%r15), %rax
movslq 0x28(%rsp), %rcx
movq %rcx, 0x28(%rsp)
movl (%rax,%rcx,4), %edx
testl %ebp, %ebp
cmovel %r13d, %ebp
movl $0x200, %edi            # imm = 0x200
movl %ebp, %ecx
callq 0x16a92
leaq 0x1b74a(%rip), %rax     # 0x31fe0
movq (%rax), %rax
movq %rax, 0x50(%rsp)
leaq 0x118bb(%rip), %r12     # 0x28160
movq 0x158(%r12), %rax
movq %rax, 0x48(%rsp)
movq 0x8(%rsp), %rdi
callq 0x9d77
movq %rax, %rdi
callq 0xac81
movq %rax, 0x40(%rsp)
movq 0x168(%r12), %rax
movq %rax, 0x38(%rsp)
movq (%r15), %rdi
callq 0x9d77
leaq 0x1b6b3(%rip), %r12     # 0x31f98
movq (%r12), %rsi
movq %rax, %rdi
callq 0xa341
movq %rax, %rbp
movq 0x20(%r15), %rax
movq 0x20(%rsp), %r13
movl (%rax,%r13,4), %edi
movq (%r12), %rsi
callq 0x9044
movl $0x140, %edi            # imm = 0x140
movq %rbp, %rsi
movq %rax, %rdx
callq *0x38(%rsp)
movl $0x130, %edi            # imm = 0x130
movq 0x40(%rsp), %rsi
movq %rax, %rdx
callq *0x48(%rsp)
movq %rax, %rdi
callq 0xab00
movl $0x240, %edi            # imm = 0x240
movq 0x50(%rsp), %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x17b61
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3941
movl $0xa, %edi
callq 0x3468
movq (%r15), %rax
leaq 0x117d2(%rip), %rcx     # 0x28138
movq (%rcx), %rcx
movq %rax, 0x18(%rcx)
movq 0x10(%r15), %rax
movq %rax, 0x28(%rcx)
movq 0x8(%rsp), %rax
movq %rax, 0x20(%rcx)
movl 0x34(%rsp), %eax
movl %eax, 0x30(%rcx)
movq 0x58(%rsp), %rax
addq 0x20(%r15), %rax
movq %rax, 0x38(%rcx)
leaq (,%r13,8), %rax
addq 0x28(%r15), %rax
movq %rax, 0x40(%rcx)
xorl %edi, %edi
callq 0x15554
movl 0x1c(%rsp), %edi
callq 0x14f70
movq 0x20(%r15), %rax
movq 0x28(%rsp), %rcx
movl (%rax,%rcx,4), %ecx
subl (%rax,%r13,4), %ecx
cmpl $0x270f, %ecx           # imm = 0x270F
movl 0x10(%rsp), %ebp
movl 0x18(%rsp), %r13d
movl 0x14(%rsp), %r12d
jl 0x16a44
leaq 0x9d5c(%rip), %rdi      # 0x2073b
xorl %eax, %eax
callq 0x9be3
jmp 0x16a44
testl %r12d, %r12d
movl 0x10(%rsp), %ebp
movl 0x18(%rsp), %r13d
je 0x16a16
movq (%r15), %rsi
movq 0x20(%r15), %rax
movq 0x20(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movl $0x220, %edi            # imm = 0x220
movl %r12d, %ecx
callq 0x16a92
movl 0x4(%rsp), %ecx
testl %ecx, %ecx
je 0x16a34
movq (%r15), %rsi
movq 0x20(%r15), %rax
movq 0x8(%rsp), %rdx
movl -0x4(%rax,%rdx,4), %edx
movl $0x200, %edi            # imm = 0x200
callq 0x16a92
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3941
movl 0x14(%rsp), %r12d
cmpl %r12d, %ebx
jle 0x16a63
leal -0x1(%rbx), %ecx
decl %r13d
movq %r15, %rdi
movq %r14, %rsi
movl %r12d, %edx
movl %r13d, %r8d
callq 0x1661f
movl %eax, %r13d
movl 0x4(%rsp), %edi
cmpl %ebp, %ebx
jge 0x16a80
testl %edi, %edi
je 0x16a74
callq 0x14f70
incl %ebx
decl %r13d
movl %ebx, %edx
jmp 0x16644
movl %r13d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq