// File: /workspace/github_c_makefile_star2_O0/bobrippling[P]tim/motion.c
// Function: m_paren
int m_paren(
		motion_arg const *arg, unsigned repeat,
		window *win, point_t *to)
{
	list_t *l = window_current_line(win, false);
	if(!l)
		return MOTION_FAILURE;

	if(arg->i == '%'){
		/* look forward for a paren on this line, then match */
		char paren = 0, opp;
		unsigned x = win->ui_pos->x;
		unsigned y = win->ui_pos->y;

		if(x >= l->len_line)
			x = l->len_line - 1;
		for(unsigned i = x; i < l->len_line; i++)
			if(paren_match(l->line[i], &opp)){
				paren = l->line[i];
				x = i;
				break;
			}

		if(!paren)
			return MOTION_FAILURE;

		const int dir = paren_left(paren) ? 1 : -1;
		point_t pos = { .y = y, .x = x + dir };

		if(find_unnested_paren(opp, paren, dir, &l, &pos)){
			*to = pos;
			return MOTION_SUCCESS;
		}
		return MOTION_FAILURE;
	}

	if(paren_match(arg->i, &(char){ 0 })){
		repeat = DEFAULT_REPEAT(repeat);

		/* look for an unmatched `arg->i' */
		char paren = arg->i, opp = paren_opposite(paren);

		point_t pos = *win->ui_pos;

		int dir = paren_left(paren) ? -1 : 1;
		bool done_one = false;

		for(; repeat > 0; repeat--){
			const point_t before_move = pos;

			if((unsigned)pos.x < l->len_line &&
			(l->line[pos.x] == paren || l->line[pos.x] == opp))
			{
				/* "[{" while on a '{' - step out so we don't stay on it
				 * or
				 * "[{" while on a '}' - step in so we match the other paren
				 */
				l = list_advance_x(l, dir, &pos.y, &pos.x);
			}

			if(!find_unnested_paren(paren, opp,
						dir, &l, &pos))
			{
				if(done_one){
					pos = before_move;
					break;
				}
				return MOTION_FAILURE;
			}

			done_one = true;
		}

		*to = pos;
		return MOTION_SUCCESS;
	}

	return MOTION_FAILURE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x20(%rbp), %rdi
xorl %esi, %esi
callq 0x13790
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xfe79
movl $0x0, -0x4(%rbp)
jmp 0x100e4
movq -0x10(%rbp), %rax
cmpl $0x25, (%rax)
jne 0xff96
movb $0x0, -0x31(%rbp)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movl 0x4(%rax), %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jb 0xfec1
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
subq $0x1, %rax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0xff16
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl -0x40(%rbp), %ecx
leaq -0x32(%rbp), %rsi
movsbl (%rax,%rcx), %edi
callq 0x10a70
testb $0x1, %al
jne 0xfef1
jmp 0xff09
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl -0x40(%rbp), %ecx
movb (%rax,%rcx), %al
movb %al, -0x31(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0xff16
jmp 0xff0b
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xfec7
cmpb $0x0, -0x31(%rbp)
jne 0xff28
movl $0x0, -0x4(%rbp)
jmp 0x100e4
movsbl -0x31(%rbp), %edi
callq 0x10af0
movb %al, %dl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x38(%rbp), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x48(%rbp)
movsbl -0x32(%rbp), %edi
movsbl -0x31(%rbp), %esi
movl -0x44(%rbp), %edx
leaq -0x30(%rbp), %rcx
leaq -0x4c(%rbp), %r8
callq 0x100f0
testb $0x1, %al
jne 0xff73
jmp 0xff8a
movq -0x28(%rbp), %rax
movq -0x4c(%rbp), %rcx
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x100e4
movl $0x0, -0x4(%rbp)
jmp 0x100e4
movq -0x10(%rbp), %rax
movl (%rax), %eax
movb $0x0, -0x4d(%rbp)
leaq -0x4d(%rbp), %rsi
movsbl %al, %edi
callq 0x10a70
testb $0x1, %al
jne 0xffb5
jmp 0x100dd
cmpl $0x0, -0x14(%rbp)
je 0xffc3
movl -0x14(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0xffcd
movl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0xffcd
movl -0x6c(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movb %al, -0x4e(%rbp)
movsbl -0x4e(%rbp), %edi
callq 0x10b20
movb %al, -0x4f(%rbp)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movsbl -0x4e(%rbp), %edi
callq 0x10af0
movb %al, %dl
movl $0x1, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x5c(%rbp)
movb $0x0, -0x5d(%rbp)
cmpl $0x0, -0x14(%rbp)
jbe 0x100c9
movq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x58(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x10082
movq -0x30(%rbp), %rax
movq (%rax), %rax
movslq -0x58(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x4e(%rbp), %ecx
cmpl %ecx, %eax
je 0x10066
movq -0x30(%rbp), %rax
movq (%rax), %rax
movslq -0x58(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x4f(%rbp), %ecx
cmpl %ecx, %eax
jne 0x10082
movq -0x30(%rbp), %rdi
movl -0x5c(%rbp), %esi
leaq -0x58(%rbp), %rdx
addq $0x4, %rdx
leaq -0x58(%rbp), %rcx
callq 0xe4b0
movq %rax, -0x30(%rbp)
movsbl -0x4e(%rbp), %edi
movsbl -0x4f(%rbp), %esi
movl -0x5c(%rbp), %edx
leaq -0x30(%rbp), %rcx
leaq -0x58(%rbp), %r8
callq 0x100f0
testb $0x1, %al
jne 0x100b7
testb $0x1, -0x5d(%rbp)
je 0x100ae
movq -0x68(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x100c9
movl $0x0, -0x4(%rbp)
jmp 0x100e4
movb $0x1, -0x5d(%rbp)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x10019
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x100e4
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)