// File: /workspace/github_c_makefile_star2_O0/bobrippling[P]tim/keys.c
// Function: k_replace
void k_replace(const keyarg_u *a, unsigned repeat, const int from_ch)
{
	if(a->i == 1){
		// TODO: repeated
	}else{
		/* single char */
		bool raw;
		int ch = io_getch(IO_NOMAP | IO_MAPRAW, &raw, true);

		if(!raw && ch == K_ESC)
			return;

		repeat = DEFAULT_REPEAT(repeat);

		motion move_repeat = {
			.func = m_move,
			.arg.pos.x = repeat - 1,
			.how = M_NONE
		};

		window *win = windows_cur();
		const motion *mchosen =
			win->ui_mode & UI_VISUAL_ANY
			? motion_read_or_visual(&(unsigned){0}, false)
			: &move_repeat;


		region_t r;
		if(!motion_to_region(mchosen, 1, win, &r))
			return;

		/* special case - single _line_ replace
		 * we differ from vim in that multi-char-single-line
		 * replace adds N many '\n's
		 */
		const bool ins_nl = r.type == REGION_CHAR
			&& r.begin.y == r.end.y
			&& !raw
			&& isnewline(ch);

		if(ins_nl)
			ch = '\n';
		else if(ch == '\n')
			ch = '\r'; /* not an explicit newline - force ^M / \r */

		buffer_t *const buf = win->buf;

		list_iter_region(buf->head, &r, LIST_ITER_EVAL_NL, replace_iter, &ch);

		if(ins_nl){
			win->ui_pos->x = 0;
			win->ui_pos->y += repeat;
		}

		buf->modified = true;
		win->ui_mode = UI_NORMAL;
	}
	ui_redraw();
	ui_cur_changed();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x66f3
jmp 0x6883
movl $0x11, %edi
leaq -0x11(%rbp), %rsi
movl $0x1, %edx
callq 0x11310
movl %eax, -0x18(%rbp)
testb $0x1, -0x11(%rbp)
jne 0x671a
cmpl $0x1b, -0x18(%rbp)
jne 0x671a
jmp 0x688d
cmpl $0x0, -0xc(%rbp)
je 0x6728
movl -0xc(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x6732
movl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x6732
movl -0x6c(%rbp), %eax
movl %eax, -0xc(%rbp)
leaq 0x8a71(%rip), %rax      # 0xf1b0
movq %rax, -0x30(%rbp)
movl -0xc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
callq 0x13c60
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl 0x40(%rax), %eax
andl $0x38, %eax
cmpl $0x0, %eax
je 0x678a
movl $0x0, -0x44(%rbp)
leaq -0x44(%rbp), %rdi
xorl %esi, %esi
callq 0x81e0
movq %rax, -0x78(%rbp)
jmp 0x6794
leaq -0x30(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x6794
movq -0x78(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rdx
movl $0x1, %esi
leaq -0x58(%rbp), %rcx
callq 0x10390
testb $0x1, %al
jne 0x67bb
jmp 0x688d
xorl %eax, %eax
cmpl $0x0, -0x48(%rbp)
movb %al, -0x79(%rbp)
jne 0x67f9
movl -0x54(%rbp), %ecx
xorl %eax, %eax
cmpl -0x4c(%rbp), %ecx
movb %al, -0x79(%rbp)
jne 0x67f9
xorl %eax, %eax
testb $0x1, -0x11(%rbp)
movb %al, -0x79(%rbp)
jne 0x67f9
movb $0x1, %al
cmpl $0xa, -0x18(%rbp)
movb %al, -0x7a(%rbp)
je 0x67f3
cmpl $0xd, -0x18(%rbp)
sete %al
movb %al, -0x7a(%rbp)
movb -0x7a(%rbp), %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
andb $0x1, %al
movb %al, -0x59(%rbp)
testb $0x1, -0x59(%rbp)
je 0x6810
movl $0xa, -0x18(%rbp)
jmp 0x681f
cmpl $0xa, -0x18(%rbp)
jne 0x681d
movl $0xd, -0x18(%rbp)
jmp 0x681f
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x58(%rbp), %rsi
movl $0x1, %edx
leaq 0x1a0e(%rip), %rcx      # 0x8250
leaq -0x18(%rbp), %r8
callq 0xe160
testb $0x1, -0x59(%rbp)
je 0x6870
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movl $0x0, (%rax)
movl -0xc(%rbp), %ecx
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
movq -0x68(%rbp), %rax
movb $0x1, 0x39(%rax)
movq -0x38(%rbp), %rax
movl $0x1, 0x40(%rax)
callq 0x4fd0
callq 0x5050
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)