// File: /workspace/github_c_makefile_star2_O2/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 0xd170
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0xcef6
testq %rax, %rax
je 0x680b
movq %rax, %r14
movq 0x30(%rbx), %rax
movl (%rax), %eax
movq 0x8(%r14), %rcx
cmpq %rax, %rcx
jbe 0x680b
movslq %eax, %r13
cmpq %rcx, %r13
jae 0x66b6
movq (%r14), %rax
movsbl (%rax,%r13), %edi
callq 0xb605
movq 0x8(%r14), %rcx
testb %al, %al
jne 0x66b6
incq %r13
jmp 0x6697
cmpq %r13, %rcx
je 0x680b
testq %r13, %r13
je 0x66ea
movq 0x30(%rbx), %rax
movslq (%rax), %rax
cmpq %r13, %rax
jne 0x66ea
movq (%r14), %rax
movsbl -0x1(%rax,%r13), %edi
callq 0xb605
testb %al, %al
je 0x66ea
decq %r13
jne 0x66d0
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 0x680b
cmpl $0x1, %ebp
adcl $0x0, %ebp
movslq (%r15), %rcx
movslq %ebp, %rdx
imulq %rcx, %rdx
addq %rdx, %rax
leaq 0x7b24(%rip), %rdx      # 0xe250
leaq 0x10(%rsp), %r15
pushq $0x40
popq %rsi
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 0x67ba
movq 0x8(%r14), %rdx
movq 0x10(%r14), %rax
leaq (%rdx,%rbp), %rcx
cmpq %rax, %rcx
jbe 0x678e
addq %rbp, %rax
movq %rax, 0x10(%r14)
movq %rsi, %rdi
movq %rax, %rsi
callq 0x5660
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 0x67ea
leaq 0x10(%rsp), %rsi
movq %r15, %rdx
callq 0x4360
testq %rbp, %rbp
jns 0x67ea
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 0x501c
callq 0x4cc7
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq