// File: /workspace/github_c_makefile_star2_O1/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
pushq %rax
movq %rsi, %r12
movq %rdi, %r14
cmpq $0x0, 0x8(%rdi)
jne 0x6db1
xorl %edi, %edi
callq 0x7840
movq %rax, 0x8(%r14)
movl $0xc, %ebp
cmpq $0x0, 0x8(%r14)
je 0x6f06
movl $0x10, %edi
callq 0x3490
testq %rax, %rax
je 0x6f06
movq %rax, %rbx
movq $0x0, 0x8(%rax)
movq (%r14), %r15
leaq 0x2435(%rip), %rsi      # 0x921e
movq %r12, %rdi
callq 0x33a0
movl $0x16, %ebp
testq %rax, %rax
je 0x6ef1
movq %rax, %r13
cmpb $0x0, (%r12,%rax)
je 0x6ef1
movq %r15, (%rsp)
addq %r12, %r13
movb $0x0, (%r13)
xorl %edi, %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x31a0
cmpq $0x1, %rax
jne 0x6e41
movq %rbx, %rdi
addq $0x4, %rdi
movl $0x1, %edx
movq %r12, %rsi
callq 0x31a0
jmp 0x6ea1
leaq 0x23f7(%rip), %rdi      # 0x923f
movq %r12, %rsi
callq 0x33d0
testl %eax, %eax
je 0x6e9a
movq $-0x1, %rbp
leaq 0x5e2e(%rip), %r15      # 0xcc90
cmpq $0x11, %rbp
je 0x6e91
movq (%r15), %rdi
movq %r12, %rsi
callq 0x33d0
incq %rbp
addq $0x10, %r15
testl %eax, %eax
jne 0x6e62
movl -0x4(%r15), %eax
movl %eax, 0x4(%rbx)
movb -0x8(%r15), %al
movb %al, (%rbx)
cmpq $0x12, %rbp
jb 0x6ea4
movl $0xffffffff, 0x4(%rbx)  # imm = 0xFFFFFFFF
jmp 0x6ea4
movl $0x20, 0x4(%rbx)
movb $0x0, (%rbx)
cmpl $-0x1, 0x4(%rbx)
movl $0x16, %ebp
je 0x6ef1
leaq 0x1(%r13), %rdi
leaq 0x2364(%rip), %rsi      # 0x921e
callq 0x3340
leaq (%rax,%r13), %r12
incq %r12
movq (%rsp), %rdi
movq %r12, %rsi
callq 0x54a8
movl %eax, %ebp
testl %eax, %eax
jne 0x6ef1
movq %r12, %rdi
callq 0x36a0
movq %rax, 0x8(%rbx)
xorl %ecx, %ecx
testq %rax, %rax
movl $0xc, %ebp
cmovnel %ecx, %ebp
movq 0x8(%rbx), %rdi
testl %ebp, %ebp
je 0x6f17
callq 0x3740
movq %rbx, %rdi
callq 0x3740
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
testq %rdi, %rdi
je 0x6f06
movq 0x8(%r14), %rdi
callq 0x78de
testq %rax, %rax
setne %bpl
je 0x6f62
movq %rax, %r12
xorl %r13d, %r13d
movq 0x8(%r14), %rdi
movq %r13, %rsi
callq 0x7ab9
movq %rax, %r15
movb (%rax), %al
cmpb (%rbx), %al
jne 0x6f54
movl 0x4(%r15), %eax
cmpl 0x4(%rbx), %eax
je 0x6f62
incq %r13
cmpq %r12, %r13
setb %bpl
jne 0x6f36
jmp 0x6f62
testb $0x1, %bpl
je 0x6f7d
movq 0x8(%r15), %rdi
callq 0x3740
movq 0x8(%rbx), %rax
movq %rax, 0x8(%r15)
xorl %ebp, %ebp
jmp 0x6efe
movq 0x8(%r14), %rdi
movq %rbx, %rsi
callq 0x78e2
testb %al, %al
movl $0x0, %ebp
jne 0x6f06
movq 0x8(%rbx), %rdi
callq 0x3740
movl $0xc, %ebp
jmp 0x6efe