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

  switch (sel.snap) {
  case SNAP_WORD:
    /*
     * Snap around if the word wraps around at the end or
     * beginning of a line.
     */
    // >>>>>>>>>>>>>>>>>>>> scrollback
    // ==================== scrollback
    prevgp = &term.line[*y][*x];
    // ==================== scrollback
    // <<<<<<<<<<<<<<<<<<<< scrollback
    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;
        // >>>>>>>>>>>>>>>>>>>> scrollback
        // ==================== scrollback
        if (!(term.line[yt][xt].mode & ATTR_WRAP))
        // ==================== scrollback
        // <<<<<<<<<<<<<<<<<<<< scrollback
          break;
      }

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

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl 0x1092f(%rip), %eax     # 0x18d98
movl %eax, -0x44(%rbp)
subl $0x1, %eax
je 0x8484
jmp 0x8473
movl -0x44(%rbp), %eax
subl $0x2, %eax
je 0x8669
jmp 0x874c
movq 0x1093d(%rip), %rax     # 0x18dc8
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 0x84d5
leaq 0xe233(%rip), %rax      # 0x166f0
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movl (%rax), %esi
callq 0x5670
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 0x8510
movl -0x18(%rbp), %eax
movl 0x108bf(%rip), %ecx     # 0x18dc4
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x859d
movl -0x14(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
addl 0x108a2(%rip), %eax     # 0x18dc4
cltd
idivl 0x1089b(%rip)           # 0x18dc4
movl %edx, -0x18(%rbp)
xorl %eax, %eax
cmpl -0x1c(%rbp), %eax
jg 0x8543
movl -0x1c(%rbp), %eax
movl 0x10884(%rip), %ecx     # 0x18dc0
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x8548
jmp 0x8664
cmpl $0x0, -0x14(%rbp)
jle 0x8562
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
jmp 0x856e
movl -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x20(%rbp)
movq 0x10853(%rip), %rax     # 0x18dc8
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 0x859b
jmp 0x8664
jmp 0x859d
movl -0x18(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x1c(%rbp), %edi
callq 0x6550
movl %eax, %ecx
movl -0x4c(%rbp), %eax
cmpl %ecx, %eax
jl 0x85b9
jmp 0x8664
movq 0x10808(%rip), %rax     # 0x18dc8
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 0x8604
leaq 0xe104(%rip), %rax      # 0x166f0
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movl (%rax), %esi
callq 0x5670
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 0x863f
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x863d
cmpl $0x0, -0x28(%rbp)
je 0x863f
movq -0x38(%rbp), %rax
movl (%rax), %eax
movq -0x40(%rbp), %rcx
cmpl (%rcx), %eax
je 0x863f
jmp 0x8664
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 0x84e0
jmp 0x874c
cmpl $0x0, -0x14(%rbp)
jge 0x8676
xorl %eax, %eax
movl %eax, -0x54(%rbp)
jmp 0x8682
movl 0x10748(%rip), %eax     # 0x18dc4
subl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x14(%rbp)
jge 0x86e7
jmp 0x8693
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x86e5
movq 0x10725(%rip), %rax     # 0x18dc8
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl 0x1070b(%rip), %ecx     # 0x18dc4
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 0x86d6
jmp 0x86e5
jmp 0x86d8
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x8693
jmp 0x874a
cmpl $0x0, -0x14(%rbp)
jle 0x8748
jmp 0x86ef
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl 0x106c5(%rip), %ecx     # 0x18dc0
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x8746
movq 0x106bf(%rip), %rax     # 0x18dc8
movq -0x10(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movl 0x106aa(%rip), %ecx     # 0x18dc4
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 0x8737
jmp 0x8746
jmp 0x8739
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x86ef
jmp 0x8748
jmp 0x874a
jmp 0x874c
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)