// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl %ecx, -0x10(%rbp)
cmpq $0x0, 0x117e4(%rip)     # 0x28a80
jne 0x172a3
jmp 0x17540
movq 0x117d6(%rip), %rax     # 0x28a80
movq %rax, -0x18(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x21b0
movl -0xc(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl -0x10(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x173e4
jmp 0x172e5
xorl %eax, %eax
cmpq $0x0, -0x28(%rbp)
movb %al, -0x51(%rbp)
je 0x17303
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x20(%rbp), %rax
setl %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x1730c
jmp 0x1736d
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %eax
cmpl -0x4(%rbp), %eax
jne 0x1734e
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x4(%rax), %eax
cmpl -0x8(%rbp), %eax
jne 0x1734e
movl -0x10(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1733b
jmp 0x17540
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rdi
callq 0x176f0
jmp 0x1734e
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x17368
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x172e5
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x173e2
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movl (%rax), %eax
cmpl -0x4(%rbp), %eax
jne 0x173c6
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x4(%rax), %eax
cmpl -0x8(%rbp), %eax
jne 0x173c6
movl -0x10(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x173b3
jmp 0x17540
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rdi
callq 0x176f0
jmp 0x173c6
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x173e0
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x1737d
jmp 0x17424
jmp 0x173e6
xorl %eax, %eax
cmpq $0x0, -0x28(%rbp)
movb %al, -0x52(%rbp)
je 0x17404
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x20(%rbp), %rax
setl %al
movb %al, -0x52(%rbp)
movb -0x52(%rbp), %al
testb $0x1, %al
jne 0x1740d
jmp 0x17422
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x173e6
jmp 0x17424
cmpq $0x0, -0x30(%rbp)
jne 0x17483
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movl $0x1, %edi
movl $0x18, %esi
callq 0x2110
movq -0x18(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x17468
leaq 0x9ec1(%rip), %rdi      # 0x2131a
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq -0x48(%rbp), %rcx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x174d6
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movl $0x1, %edi
movl $0x18, %esi
callq 0x2110
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x174c0
leaq 0x9ec0(%rip), %rdi      # 0x21371
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x50(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x8, %edi
callq 0x22b0
movq -0x28(%rbp), %rcx
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
jne 0x17504
leaq 0x9ec9(%rip), %rdi      # 0x213be
callq 0x2190
movl $0x1, %edi
callq 0x2260
movl -0x4(%rbp), %ecx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movl %ecx, (%rax)
movl -0x8(%rbp), %ecx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
callq 0x17650
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)