// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x6e07(%rip), %rsi      # 0x1e786
callq 0x2230
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
jne 0x1799f
leaq 0x9b2f(%rip), %rdi      # 0x214c4
callq 0x2190
jmp 0x17b18
cmpq $0x0, 0x110d9(%rip)     # 0x28a80
jne 0x179c6
movq 0xe630(%rip), %rax      # 0x25fe0
movq (%rax), %rdi
leaq 0x9b45(%rip), %rsi      # 0x214ff
movb $0x0, %al
callq 0x2310
jmp 0x17b2a
movq 0x110b3(%rip), %rax     # 0x28a80
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x17b0f
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
movq -0x10(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2470
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x17a35
leaq 0x9b3e(%rip), %rdi      # 0x21551
callq 0x2190
movq 0xe5c1(%rip), %rax      # 0x25fe0
movq (%rax), %rdi
leaq 0x9b54(%rip), %rsi      # 0x2157d
movb $0x0, %al
callq 0x2310
jmp 0x17b0f
movq -0x20(%rbp), %rax
shlq $0x3, %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2470
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x17a90
leaq 0x9b62(%rip), %rdi      # 0x215d3
callq 0x2190
movq 0xe563(%rip), %rax      # 0x25fe0
movq (%rax), %rdi
leaq 0x9af6(%rip), %rsi      # 0x2157d
movb $0x0, %al
callq 0x2310
jmp 0x17b0f
movq -0x20(%rbp), %rax
shlq $0x2, %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x4, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2470
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x17aef
leaq 0x9b2f(%rip), %rdi      # 0x215ff
callq 0x2190
movq 0xe504(%rip), %rax      # 0x25fe0
movq (%rax), %rdi
leaq 0x9a97(%rip), %rsi      # 0x2157d
movb $0x0, %al
callq 0x2310
jmp 0x17b0f
movq -0x20(%rbp), %rax
shlq $0x2, %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x179dc
movq -0x10(%rbp), %rdi
callq 0x21f0
movq -0x18(%rbp), %rsi
leaq 0x9b08(%rip), %rdi      # 0x2162b
movb $0x0, %al
callq 0x2040
addq $0x30, %rsp
popq %rbp
retq