// File: /workspace/github_c_makefile_star2_O2/Ziddykins[P]Dawn/src/status.c
// Function: add_event
void add_event(enum Events event, int e_data, unsigned int offset, int flags) { //flags -> enum event_mode (status.h)
    if(elist == 0)
        return;
    struct event_list * celist = (struct event_list *)elist;

    time_t newtime = time(0) + offset;
    struct event_node * tmp = celist->head, * prev = 0;
    if(flags & UNIQUE) {
        while(tmp != 0 && tmp->event_time < newtime) { //go to the place where we need to insert the new event
            if(tmp->elem->event == event && tmp->elem->data == e_data) {
                if(flags & KEEP) {
                    return;
                } else {
                    tmp = prev; //move to previous event
                    remove_event(prev); //remove next event
                }
            }
            prev = tmp;
            if(tmp != 0)
                tmp = tmp->next;
        }
        struct event_node * scanner = tmp, * prev_scanner = prev;
        while(scanner != 0) {
            if(tmp->elem->event == event && tmp->elem->data == e_data) {
                if(flags & KEEP) {
                    return;
                } else {
                    scanner = prev_scanner;
                    remove_event(prev_scanner);
                }
            }
            prev_scanner = scanner;
            if(scanner != 0)
                scanner = scanner->next;
        }
    } else {
        while(tmp != 0 && tmp->event_time < newtime) { //go to the place where we need to insert the new event
            prev = tmp;
            tmp = tmp->next;
        }
    }

    if(prev == 0) { //create a new node from scratch
        struct event_node * prev_head = celist->head;
        CALLEXIT(!(celist->head = calloc(1, sizeof *celist->head)))
        celist->head->next = prev_head;
        tmp = celist->head;
    } else { //or insert it where it belongs
        struct event_node * prevnext = prev->next;
        CALLEXIT(!(prev->next = calloc(1, sizeof *prev)))
        tmp = prev->next;
        tmp->next = prevnext;
    }
    CALLEXIT(!(tmp->elem = malloc(sizeof *tmp->elem)))
    tmp->elem->event = event;
    tmp->elem->data = e_data;
    tmp->event_time = newtime;

    celist->len++;
    update_alarm(); //head may have been replaced so we reset the alarm to the next event in the queue
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, 0xc(%rsp)
movq 0x114b0(%rip), %rax     # 0x1fa90
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0xe6d0
movl %ecx, %r14d
movl %edx, %r15d
movl %edi, %ebp
xorl %edi, %edi
callq 0x21b0
movl %r15d, %r13d
addq %rax, %r13
movq 0x10(%rsp), %r12
movq (%r12), %r15
testb $0x1, %r14b
jne 0xe62f
xorl %ebx, %ebx
testq %r15, %r15
je 0xe6e4
cmpq %r13, 0x10(%r15)
jge 0xe6e4
movq %r15, %rbx
movq (%r15), %r15
jmp 0xe614
xorl %eax, %eax
movq %rax, %rbx
testq %r15, %r15
je 0xe681
cmpq %r13, 0x10(%r15)
jge 0xe681
movq 0x8(%r15), %rax
cmpl %ebp, (%rax)
jne 0xe676
movq %r15, %rcx
movl 0xc(%rsp), %edx
cmpl %edx, 0x4(%rax)
jne 0xe679
testb $0x2, %r14b
jne 0xe6d0
movq %rbx, %rdi
callq 0xe853
movl $0x0, %eax
movl $0x0, %r15d
movq %rbx, %rcx
testq %rbx, %rbx
jne 0xe679
jmp 0xe631
movq %r15, %rcx
movq (%rcx), %r15
movq %rcx, %rax
jmp 0xe631
movq %r15, %rax
movq %rbx, %rdx
testq %rax, %rax
je 0xe6df
movq %rdx, %r12
movq 0x8(%r15), %rdx
cmpl %ebp, (%rdx)
jne 0xe6c5
movq %rax, %rcx
movl 0xc(%rsp), %eax
cmpl %eax, 0x4(%rdx)
jne 0xe6c8
testb $0x2, %r14b
jne 0xe6d0
movq %r12, %rdi
callq 0xe853
movl $0x0, %eax
movl $0x0, %edx
movq %r12, %rcx
testq %r12, %r12
jne 0xe6c8
jmp 0xe687
movq %rax, %rcx
movq (%rcx), %rax
movq %rcx, %rdx
jmp 0xe687
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %r12
testq %rbx, %rbx
je 0xe707
movq (%rbx), %r15
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
callq 0x2110
movq %rax, (%rbx)
testq %rax, %rax
je 0xe764
movq %rax, %r14
movq %r15, (%rax)
jmp 0xe725
movq (%r12), %rbx
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
callq 0x2110
movq %rax, (%r12)
testq %rax, %rax
je 0xe76d
movq %rax, %r14
movq %rbx, (%rax)
pushq $0x8
popq %rdi
callq 0x22c0
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0xe75b
movl %ebp, (%rax)
movl 0xc(%rsp), %ecx
movl %ecx, 0x4(%rax)
movq %r13, 0x10(%r14)
incq 0x8(%r12)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe812
leaq 0x8c51(%rip), %rdi      # 0x173b3
jmp 0xe774
leaq 0x8bfb(%rip), %rdi      # 0x17366
jmp 0xe774
leaq 0x8b9b(%rip), %rdi      # 0x1730f
callq 0x2190
pushq $0x1
popq %rdi
callq 0x2270