// File: /workspace/github_c_makefile_star2_O3/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, %rcx
movslq (%r14,%rcx,4), %rsi
xorps %xmm1, %xmm1
cvtsi2ssl (%rax,%rsi,4), %xmm1
movq 0x60(%rsp), %rsi
movslq 0x4(%r14,%rsi,4), %rdi
xorps %xmm0, %xmm0
cvtsi2ssl -0x4(%rax,%rdi,4), %xmm0
addss %xmm1, %xmm0
addss 0x9f8e(%rip), %xmm0     # 0x2051c
mulss 0x9f8a(%rip), %xmm0     # 0x20520
cmpl %esi, %ecx
jle 0x165e0
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 0x1664d
xorl %r12d, %r12d
cmpl %ebp, %ebx
jge 0x1665a
movq %rdi, 0x8(%rsp)
movl $0x1, %edi
movq %rsi, %rbp
callq 0x17522
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
jmp 0x1665a
cvttss2si %xmm0, %ecx
movl %ebp, %r10d
movl %edx, %r8d
leal (%r10,%r8), %esi
movl %esi, %ebx
shrl $0x1f, %ebx
addl %esi, %ebx
sarl %ebx
movslq %ebx, %r9
movslq (%r14,%r9,4), %rsi
movl (%rax,%rsi,4), %edi
cmpl %ecx, %edi
jle 0x1660b
leal -0x1(%rbx), %r10d
jmp 0x1661b
movslq 0x4(%r14,%r9,4), %r8
cmpl %ecx, -0x4(%rax,%r8,4)
jge 0x1659a
leal 0x1(%rbx), %r8d
cmpl %r10d, %r8d
jle 0x165ea
movslq 0x4(%r14,%r9,4), %r9
cmpl %edx, %ebx
jle 0x16980
subl %ecx, %edi
jle 0x16980
movl %ecx, %r8d
subl -0x4(%rax,%rsi,4), %r8d
cmpl %r8d, %edi
jle 0x16980
decl %ebx
jmp 0x1659a
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 0x166ed
movq %rdi, 0x8(%rsp)
cmpl %esi, %edi
jle 0x166c1
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 0x169bc
incq %r13
decl %ebp
jne 0x1669a
testl %r12d, %r12d
movl 0x4(%rsp), %ecx
je 0x168e8
cmpl %ecx, %r12d
jne 0x168e8
movl %r12d, %edi
callq 0x15402
movl 0x10(%rsp), %ebp
movl 0x18(%rsp), %r13d
jmp 0x1693f
movl %eax, %ebp
incl %r13d
movl $0x1, %edi
movl %r13d, 0x34(%rsp)
movl %edx, 0x28(%rsp)
callq 0x17522
movl %eax, 0x1c(%rsp)
leaq 0x1c8e0(%rip), %rax     # 0x32ff0
movq (%rax), %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x188ea
movl $0x51, %edi
movq %rax, %rsi
movl $0x3, %edx
callq 0x17456
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 0x169bc
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 0x169bc
leaq 0x1c84a(%rip), %rax     # 0x32fe0
movq (%rax), %rax
movq %rax, 0x50(%rsp)
leaq 0x129bb(%rip), %r12     # 0x29160
movq 0x158(%r12), %rax
movq %rax, 0x48(%rsp)
movq 0x8(%rsp), %rdi
callq 0x9d8b
movq %rax, %rdi
callq 0xac23
movq %rax, 0x40(%rsp)
movq 0x168(%r12), %rax
movq %rax, 0x38(%rsp)
movq (%r15), %rdi
callq 0x9d8b
leaq 0x1c7b3(%rip), %r12     # 0x32f98
movq (%r12), %rsi
movq %rax, %rdi
callq 0xa2f7
movq %rax, %rbp
movq 0x20(%r15), %rax
movq 0x20(%rsp), %r13
movl (%rax,%r13,4), %edi
movq (%r12), %rsi
callq 0x908f
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 0xaaaa
movl $0x240, %edi            # imm = 0x240
movq 0x50(%rsp), %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x179e5
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x394a
movl $0xa, %edi
callq 0x3468
movq (%r15), %rax
leaq 0x128d2(%rip), %rcx     # 0x29138
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 0x15402
movl 0x1c(%rsp), %edi
callq 0x14e24
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 0x16944
leaq 0x9edc(%rip), %rdi      # 0x207bb
xorl %eax, %eax
callq 0x9bfd
jmp 0x16944
testl %r12d, %r12d
movl 0x10(%rsp), %ebp
movl 0x18(%rsp), %r13d
je 0x16916
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 0x169bc
movl 0x4(%rsp), %ecx
testl %ecx, %ecx
je 0x16934
movq (%r15), %rsi
movq 0x20(%r15), %rax
movq 0x8(%rsp), %rdx
movl -0x4(%rax,%rdx,4), %edx
movl $0x200, %edi            # imm = 0x200
callq 0x169bc
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x394a
movl 0x14(%rsp), %r12d
cmpl %r12d, %ebx
jle 0x16963
leal -0x1(%rbx), %ecx
decl %r13d
movq %r15, %rdi
movq %r14, %rsi
movl %r12d, %edx
movl %r13d, %r8d
callq 0x16537
movl %eax, %r13d
movl 0x4(%rsp), %edi
cmpl %ebp, %ebx
jge 0x169aa
testl %edi, %edi
je 0x16974
callq 0x14e24
incl %ebx
decl %r13d
movl %ebx, %edx
jmp 0x1655c
cmpl %ebp, %ebx
jge 0x1659a
movl %ecx, %esi
subl -0x4(%rax,%r9,4), %esi
jle 0x1659a
leal 0x1(%rbx), %edi
movl (%rax,%r9,4), %eax
subl %ecx, %eax
cmpl %eax, %esi
cmovlel %ebx, %edi
movl %edi, %ebx
jmp 0x1659a
movl %r13d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq