// File: /workspace/github_c_makefile_star2_O3/bobrippling[P]tim/keys.c
// Function: k_inc_dec
void k_inc_dec(const keyarg_u *a, unsigned repeat, const int from_ch)
{
	window *win = windows_cur();
	list_t *line = window_current_line(win, false);

	if(!line)
		return;
	if((unsigned)win->ui_pos->x >= line->len_line)
		return;

	size_t pos = win->ui_pos->x;
	for(; pos < line->len_line; pos++)
		if(isdigit_or_minus(line->line[pos]))
			break;
	if(pos == line->len_line)
		return;

	if(pos == (size_t)win->ui_pos->x){
		/* rewind if possible */
		while(pos > 0 && isdigit_or_minus(line->line[pos - 1]))
			pos--;
	}

	char *end;
	long long num = strtoll(&line->line[pos], &end, 0);
	if(end == &line->line[pos])
		return;

	repeat = DEFAULT_REPEAT(repeat);

	num += (signed)repeat * a->i;

	char numbuf[64];
	snprintf(numbuf, sizeof numbuf, "%lld", num);
	const size_t numbuflen_new = strlen(numbuf);
	const size_t numbuflen_old = end - &line->line[pos];

	const long change = numbuflen_new - numbuflen_old;

	if(change > 0){
		if(line->len_line + change > line->len_malloc)
			line->line = urealloc(line->line, line->len_malloc += change);

		/* make way */
		memmove(
				&line->line[pos] + numbuflen_new,
				&line->line[pos] + numbuflen_old,
				line->len_line - pos - numbuflen_old);
	}

	memcpy(&line->line[pos], numbuf, numbuflen_new);

	if(change < 0){
		/* fill back */
		memmove(
				&line->line[pos] + numbuflen_new,
				&line->line[pos] + numbuflen_old,
				line->len_line - pos - numbuflen_old);
	}

	line->len_line += change;
	win->buf->modified = true;

	win->ui_pos->x = pos + numbuflen_new - 1;

	ui_cur_changed();
	ui_redraw();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %esi, %ebp
movq %rdi, %r15
callq 0xdaf0
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0xd868
testq %rax, %rax
je 0x6c0a
movq %rax, %r14
movq 0x30(%rbx), %rax
movl (%rax), %eax
movq 0x8(%r14), %rcx
cmpq %rax, %rcx
jbe 0x6c0a
movslq %eax, %r13
cmpq %r13, %rcx
jbe 0x6ab3
movq (%r14), %rax
movsbl (%rax,%r13), %edi
callq 0xbe19
movq 0x8(%r14), %rcx
testb %al, %al
jne 0x6ab3
incq %r13
cmpq %rcx, %r13
jb 0x6a96
cmpq %rcx, %r13
je 0x6c0a
testq %r13, %r13
je 0x6ae7
movq 0x30(%rbx), %rax
movslq (%rax), %rax
cmpq %rax, %r13
jne 0x6ae7
movq (%r14), %rax
movsbl -0x1(%rax,%r13), %edi
callq 0xbe19
testb %al, %al
je 0x6ae7
decq %r13
jne 0x6acd
xorl %r13d, %r13d
movq (%r14), %rdi
addq %r13, %rdi
leaq 0x8(%rsp), %r12
movq %r12, %rsi
xorl %edx, %edx
callq 0x4310
movq (%r12), %r12
movq (%r14), %rcx
addq %r13, %rcx
cmpq %rcx, %r12
je 0x6c0a
cmpl $0x1, %ebp
adcl $0x0, %ebp
movslq (%r15), %rcx
movslq %ebp, %rdx
imulq %rcx, %rdx
addq %rdx, %rax
leaq 0x7727(%rip), %rdx      # 0xe250
leaq 0x10(%rsp), %r15
movl $0x40, %esi
movq %r15, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x41e0
movq %r15, %rdi
callq 0x4170
movq %rax, %r15
movq (%r14), %rsi
leaq (%rsi,%r13), %rdi
subq %rdi, %r12
movq %rax, %rbp
subq %r12, %rbp
testq %rbp, %rbp
jle 0x6bb9
movq 0x8(%r14), %rdx
movq 0x10(%r14), %rax
leaq (%rdx,%rbp), %rcx
cmpq %rax, %rcx
jbe 0x6b8d
addq %rbp, %rax
movq %rax, 0x10(%r14)
movq %rsi, %rdi
movq %rax, %rsi
callq 0x584a
movq %rax, %rsi
movq %rax, (%r14)
movq 0x8(%r14), %rdx
addq %r13, %rsi
movq %r15, %rdi
addq %rsi, %rdi
addq %r12, %rsi
addq %r13, %r12
subq %r12, %rdx
callq 0x4400
movq (%r14), %rdi
addq %r13, %rdi
leaq 0x10(%rsp), %rsi
movq %r15, %rdx
callq 0x4360
jmp 0x6be9
leaq 0x10(%rsp), %rsi
movq %r15, %rdx
callq 0x4360
testq %rbp, %rbp
jns 0x6be9
movq (%r14), %rsi
addq %r13, %rsi
movq %r15, %rdi
addq %rsi, %rdi
addq %r12, %rsi
movq 0x8(%r14), %rdx
addq %r13, %r12
subq %r12, %rdx
callq 0x4400
addq %rbp, 0x8(%r14)
movq (%rbx), %rax
movb $0x1, 0x39(%rax)
leal (%r15,%r13), %eax
decl %eax
movq 0x30(%rbx), %rcx
movl %eax, (%rcx)
callq 0x51ce
callq 0x4e77
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq