// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl 0x122ac(%rip), %eax     # 0x1c1b8
movl %eax, -0x44(%rbp)
subl $0x1, %eax
je 0x9f27
jmp 0x9f16
movl -0x44(%rbp), %eax
subl $0x2, %eax
je 0xa1ff
jmp 0xa3b2
movq -0x10(%rbp), %rax
movl (%rax), %eax
cmpl 0x16149(%rip), %eax     # 0x2007c
jge 0x9f6c
movq -0x10(%rbp), %rax
movl (%rax), %eax
addl 0x16137(%rip), %eax     # 0x20078
subl 0x16135(%rip), %eax     # 0x2007c
addl $0x7d0, %eax            # imm = 0x7D0
addl $0x1, %eax
movl $0x7d0, %ecx            # imm = 0x7D0
cltd
idivl %ecx
movslq %edx, %rcx
leaq 0x1227f(%rip), %rax     # 0x1c1e0
movq 0x18(%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
jmp 0x9f8a
movq 0x12275(%rip), %rax     # 0x1c1e8
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
subl 0x160fd(%rip), %ecx     # 0x2007c
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, (%rcx)
movb %al, -0x51(%rbp)
je 0x9fcd
leaq 0xf7db(%rip), %rax      # 0x19790
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movl (%rax), %esi
callq 0x6790
cmpq $0x0, %rax
setne %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
xorl %eax, %eax
cmpl -0x18(%rbp), %eax
jg 0xa008
movl -0x18(%rbp), %eax
movl 0x121e7(%rip), %ecx     # 0x1c1e4
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0xa0e4
movl -0x14(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
addl 0x121ca(%rip), %eax     # 0x1c1e4
cltd
idivl 0x121c3(%rip)           # 0x1c1e4
movl %edx, -0x18(%rbp)
xorl %eax, %eax
cmpl -0x1c(%rbp), %eax
jg 0xa03b
movl -0x1c(%rbp), %eax
movl 0x121ac(%rip), %ecx     # 0x1c1e0
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0xa040
jmp 0xa1fa
cmpl $0x0, -0x14(%rbp)
jle 0xa05a
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
jmp 0xa066
movl -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x24(%rbp), %eax
cmpl 0x1600d(%rip), %eax     # 0x2007c
jge 0xa0a5
movl -0x24(%rbp), %eax
addl 0x15ffe(%rip), %eax     # 0x20078
subl 0x15ffc(%rip), %eax     # 0x2007c
addl $0x7d0, %eax            # imm = 0x7D0
addl $0x1, %eax
movl $0x7d0, %ecx            # imm = 0x7D0
cltd
idivl %ecx
movslq %edx, %rcx
leaq 0x12146(%rip), %rax     # 0x1c1e0
movq 0x18(%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
jmp 0xa0c0
movq 0x1213c(%rip), %rax     # 0x1c1e8
movl -0x24(%rbp), %ecx
subl 0x15fc7(%rip), %ecx     # 0x2007c
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x4(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
jne 0xa0e2
jmp 0xa1fa
jmp 0xa0e4
movl -0x18(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x1c(%rbp), %edi
callq 0x77f0
movl %eax, %ecx
movl -0x64(%rbp), %eax
cmpl %ecx, %eax
jl 0xa100
jmp 0xa1fa
movl -0x1c(%rbp), %eax
cmpl 0x15f73(%rip), %eax     # 0x2007c
jge 0xa13f
movl -0x1c(%rbp), %eax
addl 0x15f64(%rip), %eax     # 0x20078
subl 0x15f62(%rip), %eax     # 0x2007c
addl $0x7d0, %eax            # imm = 0x7D0
addl $0x1, %eax
movl $0x7d0, %ecx            # imm = 0x7D0
cltd
idivl %ecx
movslq %edx, %rcx
leaq 0x120ac(%rip), %rax     # 0x1c1e0
movq 0x18(%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
jmp 0xa15a
movq 0x120a2(%rip), %rax     # 0x1c1e8
movl -0x1c(%rbp), %ecx
subl 0x15f2d(%rip), %ecx     # 0x2007c
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, (%rcx)
movb %al, -0x71(%rbp)
je 0xa19a
leaq 0xf60e(%rip), %rax      # 0x19790
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movl (%rax), %esi
callq 0x6790
cmpq $0x0, %rax
setne %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x28(%rbp)
movq -0x38(%rbp), %rax
movzwl 0x4(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0xa1d5
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0xa1d3
cmpl $0x0, -0x28(%rbp)
je 0xa1d5
movq -0x38(%rbp), %rax
movl (%rax), %eax
movq -0x40(%rbp), %rcx
cmpl (%rcx), %eax
je 0xa1d5
jmp 0xa1fa
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x9fd8
jmp 0xa3b2
cmpl $0x0, -0x14(%rbp)
jge 0xa20c
xorl %eax, %eax
movl %eax, -0x78(%rbp)
jmp 0xa218
movl 0x11fd2(%rip), %eax     # 0x1c1e4
subl $0x1, %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x14(%rbp)
jge 0xa2e4
jmp 0xa22d
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jle 0xa2df
movq -0x10(%rbp), %rax
movl (%rax), %eax
subl $0x1, %eax
cmpl 0x15e33(%rip), %eax     # 0x2007c
jge 0xa285
movq -0x10(%rbp), %rax
movl (%rax), %eax
subl $0x1, %eax
addl 0x15e1e(%rip), %eax     # 0x20078
subl 0x15e1c(%rip), %eax     # 0x2007c
addl $0x7d0, %eax            # imm = 0x7D0
addl $0x1, %eax
movl $0x7d0, %ecx            # imm = 0x7D0
cltd
idivl %ecx
movslq %edx, %rcx
leaq 0x11f66(%rip), %rax     # 0x1c1e0
movq 0x18(%rax,%rcx,8), %rax
movq %rax, -0x80(%rbp)
jmp 0xa2a6
movq 0x11f5c(%rip), %rax     # 0x1c1e8
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
subl 0x15de1(%rip), %ecx     # 0x2007c
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl 0x11f34(%rip), %ecx     # 0x1c1e4
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x4(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
jne 0xa2cd
jmp 0xa2df
jmp 0xa2cf
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0xa22d
jmp 0xa3b0
cmpl $0x0, -0x14(%rbp)
jle 0xa3ae
jmp 0xa2f0
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl 0x11ee4(%rip), %ecx     # 0x1c1e0
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xa3ac
movq -0x10(%rbp), %rax
movl (%rax), %eax
cmpl 0x15d69(%rip), %eax     # 0x2007c
jge 0xa34f
movq -0x10(%rbp), %rax
movl (%rax), %eax
addl 0x15d57(%rip), %eax     # 0x20078
subl 0x15d55(%rip), %eax     # 0x2007c
addl $0x7d0, %eax            # imm = 0x7D0
addl $0x1, %eax
movl $0x7d0, %ecx            # imm = 0x7D0
cltd
idivl %ecx
movslq %edx, %rcx
leaq 0x11e9f(%rip), %rax     # 0x1c1e0
movq 0x18(%rax,%rcx,8), %rax
movq %rax, -0x88(%rbp)
jmp 0xa370
movq 0x11e92(%rip), %rax     # 0x1c1e8
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
subl 0x15d1a(%rip), %ecx     # 0x2007c
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movl 0x11e67(%rip), %ecx     # 0x1c1e4
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x4(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
jne 0xa39a
jmp 0xa3ac
jmp 0xa39c
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0xa2f0
jmp 0xa3ae
jmp 0xa3b0
jmp 0xa3b2
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)