// File: /workspace/github_c_makefile_star2_O3/cglindkamp[P]dfm/src/keymap.c
// Function: keymap_addmapping
int keymap_addmapping(struct keymap *keymap, char *keymapstring)
{
	if(keymap->entries == NULL)
		keymap->entries = list_new(0);
	if(keymap->entries == NULL)
		return ENOMEM;

	struct keymap_entry *entry = malloc(sizeof(*entry));
	if(entry == NULL)
		return ENOMEM;

	entry->command = NULL;
	int ret = keymap_parse_line(entry, keymapstring, keymap->commandexecutor);
	if(ret != 0) {
		keymap_entry_delete(entry);
		return ret;
	}

	if(entry->command != NULL) {
		struct keymap_entry *oldentry;
		size_t length = list_length(keymap->entries);
		size_t i;
		for(i = 0; i < length; i++) {
			oldentry = list_get_item(keymap->entries, i);
			if(oldentry->keyspec.iskeycode == entry->keyspec.iskeycode &&
			   oldentry->keyspec.key == entry->keyspec.key)
				break;
		}

		if(i < length) {
			free((void*)oldentry->command);
			oldentry->command = entry->command;
			free(entry);
		} else if(!list_append(keymap->entries, entry)) {
			keymap_entry_delete(entry);
			return ENOMEM;
		}
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r13
movq %rdi, %r14
cmpq $0x0, 0x8(%rdi)
jne 0x6c96
xorl %edi, %edi
callq 0x76b0
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x6e2a
movl $0x10, %edi
callq 0x3490
testq %rax, %rax
je 0x6e2a
movq %rax, %rbx
movq (%r14), %r15
leaq 0x2558(%rip), %rsi      # 0x920e
movq %r13, %rdi
callq 0x33a0
movl $0x16, %ebp
testq %rax, %rax
je 0x6daa
movq %rax, %r12
cmpb $0x0, (%r13,%rax)
je 0x6daa
addq %r13, %r12
movb $0x0, (%r12)
xorl %edi, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x31a0
cmpq $0x1, %rax
jne 0x6d20
leaq 0x1c(%rsp), %rdi
movl $0x1, %edx
movq %r13, %rsi
callq 0x31a0
leaq 0x1c(%rsp), %rax
movl (%rax), %r13d
movl %r13d, 0x4(%rbx)
movb $0x0, (%rbx)
movl $0x0, 0xc(%rsp)
jmp 0x6d7c
movq %r15, 0x20(%rsp)
movq %rbx, 0x10(%rsp)
movl $0xc, %r15d
leaq 0x5f49(%rip), %rbx      # 0xcc80
movq -0xc(%r15,%rbx), %rdi
movq %r13, %rsi
callq 0x33d0
testl %eax, %eax
je 0x6d5c
addq $0x10, %r15
cmpq $0x13c, %r15            # imm = 0x13C
jne 0x6d37
movq 0x10(%rsp), %rbx
jmp 0x6daa
movl (%r15,%rbx), %r13d
movq 0x10(%rsp), %rax
movl %r13d, 0x4(%rax)
movb -0x4(%r15,%rbx), %cl
movq %rax, %rbx
movl %ecx, 0xc(%rsp)
movb %cl, (%rax)
movq 0x20(%rsp), %r15
cmpl $-0x1, %r13d
je 0x6daa
leaq 0x1(%r12), %rdi
leaq 0x2480(%rip), %rsi      # 0x920e
callq 0x3340
addq %rax, %r12
incq %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x5444
movl %eax, %ebp
testl %eax, %eax
je 0x6db4
movq %rbx, %rdi
callq 0x3740
jmp 0x6e2f
movq %r12, %rdi
callq 0x36a0
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x6e40
movq %rax, 0x10(%rsp)
movl %r13d, %r15d
movq 0x8(%r14), %rdi
callq 0x774e
testq %rax, %rax
je 0x6e07
movq %rax, %r12
xorl %r13d, %r13d
movq 0x8(%r14), %rdi
movq %r13, %rsi
callq 0x7929
movq %rax, %rbp
movl 0xc(%rsp), %eax
cmpb %al, (%rbp)
jne 0x6dff
cmpl %r15d, 0x4(%rbp)
je 0x6e4a
incq %r13
cmpq %r13, %r12
jne 0x6de1
movq 0x8(%r14), %rdi
movq %rbx, %rsi
callq 0x7752
xorl %ebp, %ebp
testb %al, %al
jne 0x6e2f
movq 0x8(%rbx), %rdi
callq 0x3740
movq %rbx, %rdi
callq 0x3740
movl $0xc, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xc, %ebp
jmp 0x6daa
movq 0x8(%rbp), %rdi
callq 0x3740
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rbp)
movq %rbx, %rdi
callq 0x3740
xorl %ebp, %ebp
jmp 0x6e2f