// File: /workspace/github_c_makefile_star2_O2/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 $0x18, %rsp
movq %rsi, %r12
movq %rdi, %r14
cmpq $0x0, 0x8(%rdi)
pushq $0xc
popq %rbp
jne 0x6b0c
xorl %edi, %edi
callq 0x7480
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x6c8a
pushq $0x10
popq %rdi
callq 0x3490
testq %rax, %rax
je 0x6c8a
movq %rax, %rbx
andq $0x0, 0x8(%rax)
movq (%r14), %r15
leaq 0x26df(%rip), %rsi      # 0x920e
movq %r12, %rdi
callq 0x33a0
pushq $0x16
popq %rbp
testq %rax, %rax
je 0x6c82
movq %rax, %r13
cmpb $0x0, (%r12,%rax)
je 0x6c82
movq %r15, 0x8(%rsp)
addq %r12, %r13
movb $0x0, (%r13)
xorl %edi, %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x31a0
cmpq $0x1, %rax
jne 0x6b91
leaq 0x14(%rsp), %r15
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x31a0
movl (%r15), %ecx
movl %ecx, 0x4(%rbx)
movb $0x0, (%rbx)
xorl %r15d, %r15d
jmp 0x6bd9
movq %rbx, (%rsp)
xorl %ecx, %ecx
leaq 0x60e2(%rip), %r15      # 0xcc80
leaq 0x10(%rcx), %rbx
cmpq $0x140, %rbx            # imm = 0x140
je 0x6c5a
movq (%rcx,%r15), %rdi
movq %r12, %rsi
callq 0x33d0
movq %rbx, %rcx
testl %eax, %eax
jne 0x6b9e
movl -0x4(%rbx,%r15), %ecx
movq (%rsp), %rax
movl %ecx, 0x4(%rax)
movb -0x8(%rbx,%r15), %r15b
movq %rax, %rbx
movb %r15b, (%rax)
movl %ecx, (%rsp)
cmpl $-0x1, %ecx
je 0x6c82
leaq 0x1(%r13), %rdi
leaq 0x261e(%rip), %rsi      # 0x920e
callq 0x3340
leaq (%rax,%r13), %r12
incq %r12
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x53d8
movl %eax, %ebp
testl %eax, %eax
jne 0x6c82
movq %r12, %rdi
callq 0x36a0
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x6c7f
movq %rax, 0x8(%rsp)
movq 0x8(%r14), %rdi
callq 0x7515
movq %rax, %r12
xorl %r13d, %r13d
movq 0x8(%r14), %rdi
cmpq %r13, %r12
je 0x6c64
movq %r13, %rsi
callq 0x76e4
cmpb %r15b, (%rax)
jne 0x6c55
movq %rax, %rbp
movl (%rsp), %eax
cmpl %eax, 0x4(%rbp)
je 0x6c9b
incq %r13
jmp 0x6c34
movq (%rsp), %rbx
orl $-0x1, 0x4(%rbx)
jmp 0x6c82
movq %rbx, %rsi
callq 0x7519
xorl %ebp, %ebp
testb %al, %al
jne 0x6c8a
movq %rbx, %rdi
callq 0x6cb9
pushq $0xc
popq %rbp
jmp 0x6c8a
pushq $0xc
popq %rbp
movq %rbx, %rdi
callq 0x6cb9
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rbp), %rdi
callq 0x3740
movq 0x8(%rsp), %rax
movq %rax, 0x8(%rbp)
movq %rbx, %rdi
callq 0x3740
xorl %ebp, %ebp
jmp 0x6c8a