// File: /workspace/github_c_makefile_star2_O1/odknt[P]st/st.c
// Function: selsnap
void
selsnap(int *x, int *y, int direction)
{
	int newx, newy, xt, yt;
	int delim, prevdelim;
	const Glyph *gp, *prevgp;

	switch (sel.snap) {
	case SNAP_WORD:
		/*
		 * Snap around if the word wraps around at the end or
		 * beginning of a line.
		 */
		prevgp = &TLINE(*y)[*x];
		prevdelim = ISDELIM(prevgp->u);
		for (;;) {
			newx = *x + direction;
			newy = *y;
			if (!BETWEEN(newx, 0, term.col - 1)) {
				newy += direction;
				newx = (newx + term.col) % term.col;
				if (!BETWEEN(newy, 0, term.row - 1))
					break;

				if (direction > 0)
					yt = *y, xt = *x;
				else
					yt = newy, xt = newx;
				if (!(TLINE(yt)[xt].mode & ATTR_WRAP))
					break;
			}

			if (newx >= tlinelen(newy))
				break;

			gp = &TLINE(newy)[newx];
			delim = ISDELIM(gp->u);
			if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
					|| (delim && gp->u != prevgp->u)))
				break;

			*x = newx;
			*y = newy;
			prevgp = gp;
			prevdelim = delim;
		}
		break;
	case SNAP_LINE:
		/*
		 * Snap around if the the previous line or the current one
		 * has set ATTR_WRAP at its end. Then the whole next or
		 * previous line will be selected.
		 */
		*x = (direction < 0) ? 0 : term.col - 1;
		if (direction < 0) {
			for (; *y > 0; *y += direction) {
				if (!(TLINE(*y-1)[term.col-1].mode
						& ATTR_WRAP)) {
					break;
				}
			}
		} else if (direction > 0) {
			for (; *y < term.row-1; *y += direction) {
				if (!(TLINE(*y)[term.col-1].mode
						& ATTR_WRAP)) {
					break;
				}
			}
		}
		break;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, %ebx
movq %rsi, %r10
movq %rdi, %r15
movl 0xf058(%rip), %eax      # 0x18428
cmpl $0x2, %eax
je 0x942e
cmpl $0x1, %eax
jne 0x9793
movl (%r10), %eax
leaq 0xf068(%rip), %rsi      # 0x18450
subl 0x12efe(%rip), %eax     # 0x1c2ec
jge 0x950a
movl 0x12eee(%rip), %ecx     # 0x1c2e8
addl %ecx, %eax
addl $0x7d1, %eax            # imm = 0x7D1
cltq
imulq $0x10624dd3, %rax, %rcx # imm = 0x10624DD3
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x27, %rcx
addl %edx, %ecx
imull $0x7d0, %ecx, %ecx      # imm = 0x7D0
subl %ecx, %eax
cltq
leaq (%rsi,%rax,8), %rax
addq $0x18, %rax
jmp 0x9517
movl 0xf020(%rip), %eax      # 0x18454
decl %eax
xorl %ecx, %ecx
testl %ebx, %ebx
cmovnsl %eax, %ecx
movl %ecx, (%r15)
js 0x970e
je 0x9793
movl (%r10), %eax
movl 0xeffb(%rip), %ecx      # 0x18450
decl %ecx
cmpl %ecx, %eax
jge 0x9793
movslq %eax, %rcx
shlq $0x3, %rcx
addq 0xefeb(%rip), %rcx      # 0x18458
movslq %ebx, %rdx
shlq $0x3, %rdx
leaq 0xefd5(%rip), %rsi      # 0x18450
movslq 0x12e6a(%rip), %rdi     # 0x1c2ec
cmpl %edi, %eax
jge 0x94c9
movl 0x12e5b(%rip), %r8d     # 0x1c2e8
subl %edi, %r8d
leal (%rax,%r8), %edi
addl $0x7d1, %edi            # imm = 0x7D1
movslq %edi, %rdi
imulq $0x10624dd3, %rdi, %r8  # imm = 0x10624DD3
movq %r8, %r9
shrq $0x3f, %r9
sarq $0x27, %r8
addl %r9d, %r8d
imull $0x7d0, %r8d, %r8d      # imm = 0x7D0
subl %r8d, %edi
movslq %edi, %rdi
leaq (%rsi,%rdi,8), %r8
addq $0x18, %r8
jmp 0x94d3
shlq $0x3, %rdi
movq %rcx, %r8
subq %rdi, %r8
movq (%r8), %rdi
movslq 0xef77(%rip), %r8       # 0x18454
shlq $0x4, %r8
testb $0x1, -0xb(%rdi,%r8)
je 0x9793
addl %ebx, %eax
movl %eax, (%r10)
movl 0xef58(%rip), %edi      # 0x18450
decl %edi
addq %rdx, %rcx
cmpl %edi, %eax
jl 0x947b
jmp 0x9793
cltq
shlq $0x3, %rax
addq 0xef41(%rip), %rax      # 0x18458
movq (%rax), %r12
movslq (%r15), %r14
shlq $0x4, %r14
movl (%r12,%r14), %esi
testl %esi, %esi
movq %r10, 0x10(%rsp)
je 0x9550
leaq 0xe06b(%rip), %rax      # 0x175a0
movq (%rax), %rdi
callq 0x6790
movq 0x10(%rsp), %r10
xorl %ecx, %ecx
testq %rax, %rax
setne %cl
movl %ecx, 0xc(%rsp)
jmp 0x9558
movl $0x0, 0xc(%rsp)
addq %r14, %r12
movq %r12, 0x28(%rsp)
movq 0xeef1(%rip), %rax      # 0x18458
movq %rax, 0x20(%rsp)
leaq 0xe02d(%rip), %rax      # 0x175a0
movq (%rax), %rax
movq %rax, 0x30(%rsp)
movl %ebx, 0x1c(%rsp)
movl (%r15), %ecx
movl %ecx, %ebp
addl %ebx, %ebp
movl (%r10), %esi
setns %al
movl 0xeec2(%rip), %edi      # 0x18454
cmpl %edi, %ebp
setl %dl
testb %dl, %al
je 0x95a3
movl %esi, %r13d
jmp 0x9635
addl %edi, %ebp
movl %ebp, %eax
cltd
idivl %edi
movl %esi, %r13d
addl %ebx, %r13d
js 0x9793
cmpl 0xee93(%rip), %r13d     # 0x18450
jge 0x9793
movl %edx, %ebp
testl %ebx, %ebx
cmovlel %edx, %ecx
cmovlel %r13d, %esi
subl 0x12d18(%rip), %esi     # 0x1c2ec
jge 0x9614
movl 0x12d0c(%rip), %eax     # 0x1c2e8
addl %esi, %eax
addl $0x7d1, %eax            # imm = 0x7D1
cltq
imulq $0x10624dd3, %rax, %rdx # imm = 0x10624DD3
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0x27, %rdx
addl %esi, %edx
imull $0x7d0, %edx, %edx      # imm = 0x7D0
subl %edx, %eax
cltq
leaq 0xee46(%rip), %rdx      # 0x18450
leaq (%rdx,%rax,8), %rax
addq $0x18, %rax
jmp 0x9620
movslq %esi, %rax
movq 0x20(%rsp), %rdx
leaq (%rdx,%rax,8), %rax
movq (%rax), %rax
movslq %ecx, %rcx
shlq $0x4, %rcx
testb $0x1, 0x5(%rax,%rcx)
je 0x9793
movl %r13d, %edi
callq 0x785d
movq 0x10(%rsp), %r10
cmpl %eax, %ebp
jge 0x9793
movl %r13d, %eax
subl 0x12c99(%rip), %eax     # 0x1c2ec
jge 0x9693
movl 0x12c8d(%rip), %ecx     # 0x1c2e8
addl %ecx, %eax
addl $0x7d1, %eax            # imm = 0x7D1
cltq
imulq $0x10624dd3, %rax, %rcx # imm = 0x10624DD3
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x27, %rcx
addl %edx, %ecx
imull $0x7d0, %ecx, %ecx      # imm = 0x7D0
subl %ecx, %eax
cltq
leaq 0xedc7(%rip), %rcx      # 0x18450
leaq (%rcx,%rax,8), %rax
addq $0x18, %rax
jmp 0x969e
cltq
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
movq (%rax), %r14
movslq %ebp, %rbx
shlq $0x4, %rbx
movl (%r14,%rbx), %r12d
testl %r12d, %r12d
je 0x96cb
movq 0x30(%rsp), %rdi
movl %r12d, %esi
callq 0x6790
movq 0x10(%rsp), %r10
testq %rax, %rax
setne %al
jmp 0x96cd
xorl %eax, %eax
addq %rbx, %r14
movzbl %al, %eax
testb $0x4, 0x5(%r14)
movl 0x1c(%rsp), %ebx
jne 0x96fa
cmpl %eax, 0xc(%rsp)
jne 0x9793
testl %eax, %eax
je 0x96fa
movq 0x28(%rsp), %rcx
cmpl (%rcx), %r12d
jne 0x9793
movl %ebp, (%r15)
movl %r13d, (%r10)
movl %eax, 0xc(%rsp)
movq %r14, 0x28(%rsp)
jmp 0x957f
movl (%r10), %eax
testl %eax, %eax
jle 0x9793
movq 0xed3c(%rip), %rcx      # 0x18458
leaq 0xed2d(%rip), %rdx      # 0x18450
movl 0x12bc3(%rip), %esi     # 0x1c2ec
cmpl %esi, %eax
jle 0x973a
notl %esi
addl %eax, %esi
movslq %esi, %rsi
leaq (%rcx,%rsi,8), %rsi
jmp 0x9775
movl 0x12ba8(%rip), %edi     # 0x1c2e8
addl %eax, %edi
subl %esi, %edi
addl $0x7d0, %edi            # imm = 0x7D0
movslq %edi, %rsi
imulq $0x10624dd3, %rsi, %rdi # imm = 0x10624DD3
movq %rdi, %r8
shrq $0x3f, %r8
sarq $0x27, %rdi
addl %r8d, %edi
imull $0x7d0, %edi, %edi      # imm = 0x7D0
subl %edi, %esi
movslq %esi, %rsi
leaq (%rdx,%rsi,8), %rsi
addq $0x18, %rsi
movq (%rsi), %rsi
movslq 0xecd5(%rip), %rdi      # 0x18454
shlq $0x4, %rdi
testb $0x1, -0xb(%rsi,%rdi)
je 0x9793
addl %ebx, %eax
movl %eax, (%r10)
testl %eax, %eax
jg 0x9723
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq