// File: /workspace/github_c_makefile_star2_O1/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 0xde6c
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0xdbe9
testq %rax, %rax
je 0x6c6b
movq %rax, %r14
movq 0x30(%rbx), %rax
movl (%rax), %eax
cmpq %rax, 0x8(%r14)
jbe 0x6c6b
movslq %eax, %r13
cmpq %r13, 0x8(%r14)
jbe 0x6b2c
movq (%r14), %rax
movsbl (%rax,%r13), %edi
callq 0xc18a
testb %al, %al
jne 0x6b2c
incq %r13
cmpq 0x8(%r14), %r13
jb 0x6b12
cmpq 0x8(%r14), %r13
je 0x6c6b
testq %r13, %r13
je 0x6b61
movq 0x30(%rbx), %rax
movslq (%rax), %rax
cmpq %rax, %r13
jne 0x6b61
movq (%r14), %rax
movsbl -0x1(%rax,%r13), %edi
callq 0xc18a
testb %al, %al
je 0x6b61
decq %r13
jne 0x6b47
xorl %r13d, %r13d
movq (%r14), %rdi
addq %r13, %rdi
leaq 0x8(%rsp), %r12
movq %r12, %rsi
xorl %edx, %edx
callq 0x4300
movq (%r12), %r12
movq (%r14), %rcx
addq %r13, %rcx
cmpq %rcx, %r12
je 0x6c6b
cmpl $0x1, %ebp
adcl $0x0, %ebp
movslq (%r15), %rcx
movslq %ebp, %rdx
imulq %rcx, %rdx
addq %rdx, %rax
leaq 0x86b9(%rip), %rdx      # 0xf25c
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), %rdi
subq %rdi, %r12
subq %r13, %r12
movq %r15, %rbp
subq %r12, %rbp
testq %rbp, %rbp
jle 0x6c14
movq 0x8(%r14), %rax
addq %rbp, %rax
movq 0x10(%r14), %rsi
cmpq %rsi, %rax
jbe 0x6bf8
addq %rbp, %rsi
movq %rsi, 0x10(%r14)
callq 0x5851
movq %rax, (%r14)
movq (%r14), %rsi
addq %r13, %rsi
leaq (%rsi,%r15), %rdi
addq %r12, %rsi
movq 0x8(%r14), %rdx
subq %r12, %rdx
subq %r13, %rdx
callq 0x4400
movq (%r14), %rdi
addq %r13, %rdi
leaq 0x10(%rsp), %rsi
movq %r15, %rdx
callq 0x4350
testq %rbp, %rbp
jns 0x6c4a
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 0x51d8
callq 0x4e77
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq