// File: flightlessmango[P]macro-recorder/main.cpp
// Function: writeToFile()
void writeToFile(){
    printf("%i\n", keyArray.size());
    FILE *outFile = fopen("/tmp/recording", "a");
    now = std::chrono::high_resolution_clock::now();  
    if (keyArray.empty()){
        fprintf(outFile, "%i\n", std::chrono::duration_cast<std::chrono::microseconds>(now - last_change));
        fflush(outFile);
    }
    if (!keyArray_prev.empty()){
        fprintf(outFile, "%i\n", std::chrono::duration_cast<std::chrono::microseconds>(now - last_change));
        fflush(outFile);
    }

    for (auto i : keyArray)
    {
        KeySym ks = XKeycodeToKeysym(display, i, 1);
        if (i == keyArray.size() - 1){
            fprintf(outFile, "%s\n", XKeysymToString(ks));
        } else {
            fprintf(outFile, "%s,", XKeysymToString(ks));
        }
        fflush(outFile);
    }
    last_change = now;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
leaq 0x5d06(%rip), %rdi      # 0x7128
callq 0x1810
movq %rax, %rsi
leaq 0x2bdb(%rip), %rdi      # 0x400c
movb $0x0, %al
callq 0x1030
leaq 0x2bd1(%rip), %rdi      # 0x4010
leaq 0x2bd9(%rip), %rsi      # 0x401f
callq 0x1130
movq %rax, -0x8(%rbp)
callq 0x1040
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, 0x5cbd(%rip)      # 0x7120
leaq 0x5cbe(%rip), %rdi      # 0x7128
callq 0x1830
testb $0x1, %al
jne 0x1475
jmp 0x14c0
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq 0x5c9c(%rip), %rdi      # 0x7120
leaq 0x5c8d(%rip), %rsi      # 0x7118
callq 0x1880
movq %rax, -0x20(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x1850
movq -0x60(%rbp), %rdi
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdx
leaq 0x2b5c(%rip), %rsi      # 0x400c
movb $0x0, %al
callq 0x1170
movq -0x8(%rbp), %rdi
callq 0x1120
leaq 0x5c91(%rip), %rdi      # 0x7158
callq 0x1830
testb $0x1, %al
jne 0x151b
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq 0x5c41(%rip), %rdi      # 0x7120
leaq 0x5c32(%rip), %rsi      # 0x7118
callq 0x1880
movq %rax, -0x30(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x1850
movq -0x68(%rbp), %rdi
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdx
leaq 0x2b01(%rip), %rsi      # 0x400c
movb $0x0, %al
callq 0x1170
movq -0x8(%rbp), %rdi
callq 0x1120
leaq 0x5c06(%rip), %rax      # 0x7128
movq %rax, -0x38(%rbp)
leaq 0x5bfb(%rip), %rdi      # 0x7128
callq 0x18d0
movq %rax, -0x40(%rbp)
leaq 0x5beb(%rip), %rdi      # 0x7128
callq 0x1900
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x1930
testb $0x1, %al
jne 0x155c
jmp 0x160d
leaq -0x40(%rbp), %rdi
callq 0x1960
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq 0x5c17(%rip), %rdi      # 0x7188
movl -0x4c(%rbp), %eax
movl $0x1, %edx
movzbl %al, %esi
callq 0x1090
movq %rax, -0x58(%rbp)
movl -0x4c(%rbp), %eax
movq %rax, -0x70(%rbp)
leaq 0x5b95(%rip), %rdi      # 0x7128
callq 0x1810
movq %rax, %rcx
movq -0x70(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x15d0
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x58(%rbp), %rdi
callq 0x11d0
movq -0x78(%rbp), %rdi
movq %rax, %rdx
leaq 0x2a5a(%rip), %rsi      # 0x4021
movb $0x0, %al
callq 0x1170
jmp 0x15f6
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x58(%rbp), %rdi
callq 0x11d0
movq -0x80(%rbp), %rdi
movq %rax, %rdx
leaq 0x2a36(%rip), %rsi      # 0x4025
movb $0x0, %al
callq 0x1170
movq -0x8(%rbp), %rdi
callq 0x1120
leaq -0x40(%rbp), %rdi
callq 0x1990
jmp 0x1546
movq 0x5b0c(%rip), %rax      # 0x7120
movq %rax, 0x5afd(%rip)      # 0x7118
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)