// File: /workspace/github_c_makefile_star2_O2/Ziddykins[P]Dawn/src/status.c
// Function: save_events
void save_events(char const * fn) {
    FILE * file;
    size_t len = 0, ret;
    if(!(file = fopen(fn, "wb"))) {
        PRINTWARN("Could not save events")
    } else {
        if(elist == 0) {
            fprintf(stderr, WARN "status/save_events: tried to save but there was no event list\n");
            return;
        }
        struct event_list * celist = elist;
        struct event_node * tmp = celist->head;
        while(tmp != 0) {
            if(!(ret = fwrite(&tmp->event_time, sizeof tmp->event_time, 1, file))) {
                PRINTERR("fwrite")
                fprintf(stderr, ERR "status/save_events: event file corrupted while saving - continuing");
                break;
            }
            len += ret * sizeof tmp->event_time;
            if(!(ret = fwrite(&tmp->elem->event, sizeof tmp->elem->event, 1, file))) {
                PRINTERR("fwrite")
                fprintf(stderr, ERR "status/save_events: event file corrupted while saving - continuing");
                break;
            }
            len += ret * sizeof tmp->elem->event;
            if(!(ret = fwrite(&tmp->elem->data, sizeof tmp->elem->data, 1, file))) {
                PRINTERR("fwrite")
                fprintf(stderr, ERR "status/save_events: event file corrupted while saving - continuing");
                break;
            }
            len += ret * sizeof tmp->elem->data;
            tmp = tmp->next;
        }
        fclose(file);
    }
    printf(INFO "Saved events (%zu bytes)\n", len);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x5d41(%rip), %rsi      # 0x1468a
callq 0x2240
testq %rax, %rax
je 0xe9dc
movq 0x11132(%rip), %r12     # 0x1fa90
testq %r12, %r12
je 0xe9ec
movq %rax, %r14
xorl %ebx, %ebx
pushq $0x1
popq %r13
pushq $0x4
popq %rbp
movq (%r12), %r12
testq %r12, %r12
je 0xea54
leaq 0x10(%r12), %rdi
pushq $0x8
popq %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x2480
testq %rax, %rax
je 0xea16
leaq (%rbx,%rax,8), %rbx
movq 0x8(%r12), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x2480
testq %rax, %rax
je 0xea1f
movq %rax, %r15
movq 0x8(%r12), %rdi
addq $0x4, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x2480
testq %rax, %rax
je 0xea28
addq %rax, %r15
leaq (%rbx,%r15,4), %rbx
jmp 0xe973
leaq 0x8ad6(%rip), %rdi      # 0x174b9
callq 0x2190
xorl %ebx, %ebx
jmp 0xea5c
movq 0xe5e5(%rip), %rax      # 0x1cfd8
movq (%rax), %rcx
leaq 0x8af7(%rip), %rdi      # 0x174f4
pushq $0x51
popq %rsi
pushq $0x1
popq %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2480
leaq 0x8b29(%rip), %rdi      # 0x17546
jmp 0xea33
leaq 0x8ba2(%rip), %rdi      # 0x175c8
jmp 0xea33
leaq (%rbx,%r15,4), %rbx
leaq 0x8bc1(%rip), %rdi      # 0x175f4
callq 0x2190
movq 0xe599(%rip), %rax      # 0x1cfd8
movq (%rax), %rcx
leaq 0x8b29(%rip), %rdi      # 0x17572
pushq $0x55
popq %rsi
pushq $0x1
popq %rdx
callq 0x2480
movq %r14, %rdi
callq 0x21f0
leaq 0x8bbd(%rip), %rdi      # 0x17620
movq %rbx, %rsi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2040
nop