// File: /workspace/github_c_makefile_star2_O0/pajlada[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 = &term.line[*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 (!(term.line[yt][xt].mode & ATTR_WRAP))
					break;
			}

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

			gp = &term.line[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 (!(term.line[*y-1][term.col-1].mode
						& ATTR_WRAP)) {
					break;
				}
			}
		} else if (direction > 0) {
			for (; *y < term.row-1; *y += direction) {
				if (!(term.line[*y][term.col-1].mode
						& ATTR_WRAP)) {
					break;
				}
			}
		}
		break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl 0x118af(%rip), %eax     # 0x19d28
movl %eax, -0x44(%rbp)
subl $0x1, %eax
je 0x8494
jmp 0x8483
movl -0x44(%rbp), %eax
subl $0x2, %eax
je 0x8679
jmp 0x875c
movq 0x118bd(%rip), %rax     # 0x19d58
movq -0x10(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %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, -0x45(%rbp)
je 0x84e5
leaq 0xf1f3(%rip), %rax      # 0x176c0
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movl (%rax), %esi
callq 0x5680
cmpq $0x0, %rax
setne %al
movb %al, -0x45(%rbp)
movb -0x45(%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 0x8520
movl -0x18(%rbp), %eax
movl 0x1183f(%rip), %ecx     # 0x19d54
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x85ad
movl -0x14(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
addl 0x11822(%rip), %eax     # 0x19d54
cltd
idivl 0x1181b(%rip)           # 0x19d54
movl %edx, -0x18(%rbp)
xorl %eax, %eax
cmpl -0x1c(%rbp), %eax
jg 0x8553
movl -0x1c(%rbp), %eax
movl 0x11804(%rip), %ecx     # 0x19d50
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x8558
jmp 0x8674
cmpl $0x0, -0x14(%rbp)
jle 0x8572
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
jmp 0x857e
movl -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x20(%rbp)
movq 0x117d3(%rip), %rax     # 0x19d58
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x4(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
jne 0x85ab
jmp 0x8674
jmp 0x85ad
movl -0x18(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x1c(%rbp), %edi
callq 0x6560
movl %eax, %ecx
movl -0x4c(%rbp), %eax
cmpl %ecx, %eax
jl 0x85c9
jmp 0x8674
movq 0x11788(%rip), %rax     # 0x19d58
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %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, -0x4d(%rbp)
je 0x8614
leaq 0xf0c4(%rip), %rax      # 0x176c0
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movl (%rax), %esi
callq 0x5680
cmpq $0x0, %rax
setne %al
movb %al, -0x4d(%rbp)
movb -0x4d(%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 0x864f
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x864d
cmpl $0x0, -0x28(%rbp)
je 0x864f
movq -0x38(%rbp), %rax
movl (%rax), %eax
movq -0x40(%rbp), %rcx
cmpl (%rcx), %eax
je 0x864f
jmp 0x8674
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 0x84f0
jmp 0x875c
cmpl $0x0, -0x14(%rbp)
jge 0x8686
xorl %eax, %eax
movl %eax, -0x54(%rbp)
jmp 0x8692
movl 0x116c8(%rip), %eax     # 0x19d54
subl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x14(%rbp)
jge 0x86f7
jmp 0x86a3
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x86f5
movq 0x116a5(%rip), %rax     # 0x19d58
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl 0x1168b(%rip), %ecx     # 0x19d54
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 0x86e6
jmp 0x86f5
jmp 0x86e8
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x86a3
jmp 0x875a
cmpl $0x0, -0x14(%rbp)
jle 0x8758
jmp 0x86ff
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl 0x11645(%rip), %ecx     # 0x19d50
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x8756
movq 0x1163f(%rip), %rax     # 0x19d58
movq -0x10(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movl 0x1162a(%rip), %ecx     # 0x19d54
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 0x8747
jmp 0x8756
jmp 0x8749
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x86ff
jmp 0x8758
jmp 0x875a
jmp 0x875c
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)