// File: utkukaratas[P]xkeylayers/xkeylayers.cpp
// Function: main
int main(int argc, char **argv)
{
    int ch;
    app.debug = False;
    app.timeout.tv_sec = 0;
    app.timeout.tv_usec = 500000;
    app.timeout_valid = True;
    app.generated = NULL;

    while ((ch = getopt (argc, argv, "d")) != -1)
    {
        switch (ch)
        {
        case 'd':
            app.debug = True;
            break;
        default:
            printf("Usage: %s [-d]\n", argv[0]);
            printf("Runs as a daemon unless -d flag is set\n");
            return EXIT_SUCCESS;
        }
    }

    app.connect_x11();

    try {
       app.modifiers = load_config(".xkeylayers");
    }
    catch (...) {
        debug("configuration failure. exiting!");
        exit(EXIT_FAILURE);
    }

    if (app.modifiers.size() == 0) {
        debug("no modifiers declared. exiting!");
        exit(EXIT_FAILURE);
    }

    if (!app.debug)
        daemon (0, 0);

    // setup signal handler for proper exits.
    sigemptyset(&app._sigset);
    sigaddset(&app._sigset, SIGINT);
    sigaddset(&app._sigset, SIGTERM);
    pthread_sigmask(SIG_BLOCK, &app._sigset, NULL);
    pthread_create(&app._sigwait_thread, NULL, sig_handler, &app);

    // hook 11 and start processing input events. this call will block.
    app.hook_x11();

    XCloseDisplay(app._ctrl_conn);
    XCloseDisplay(app._data_conn);

    debug("main exiting\n");

    return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, 0x8093(%rip)      # 0xb2b0
movq $0x0, 0x80c8(%rip) # 0xb2f0
movq $0x7a120, 0x80c5(%rip) # imm = 0x7A120
movb $0x1, 0x80c6(%rip)      # 0xb300
movq $0x0, 0x80a3(%rip) # 0xb2e8
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x4056(%rip), %rdx      # 0x72a9
callq 0x2050
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0x32a4
movl -0x14(%rbp), %eax
subl $0x64, %eax
jne 0x3273
jmp 0x326a
movb $0x1, 0x803f(%rip)      # 0xb2b0
jmp 0x32a2
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x3f6e(%rip), %rdi      # 0x71ef
movb $0x0, %al
callq 0x2030
leaq 0x3f70(%rip), %rdi      # 0x71ff
movb $0x0, %al
callq 0x2030
movl $0x0, -0x4(%rbp)
jmp 0x344d
jmp 0x3245
leaq 0x7f65(%rip), %rdi      # 0xb210
callq 0x28f0
leaq -0x51(%rbp), %rdi
movq %rdi, -0x70(%rbp)
callq 0x2340
movq -0x70(%rbp), %rdx
leaq 0x3f5f(%rip), %rsi      # 0x7227
leaq -0x50(%rbp), %rdi
callq 0x4130
jmp 0x32d3
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2580
jmp 0x32e2
leaq 0x7f27(%rip), %rdi      # 0xb210
addq $0xa8, %rdi
leaq -0x30(%rbp), %rsi
callq 0x41e0
leaq -0x30(%rbp), %rdi
callq 0x3cd0
leaq -0x50(%rbp), %rdi
callq 0x23d8
leaq -0x51(%rbp), %rdi
callq 0x21c0
jmp 0x3363
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x3339
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x23d8
leaq -0x51(%rbp), %rdi
callq 0x21c0
movq -0x60(%rbp), %rdi
callq 0x20c0
leaq 0x3ee1(%rip), %rdi      # 0x7233
movb $0x0, %al
callq 0x26d0
movl $0x1, %edi
callq 0x2210
leaq 0x7ea6(%rip), %rdi      # 0xb210
addq $0xa8, %rdi
callq 0x4210
cmpq $0x0, %rax
jne 0x3394
leaq 0x3ed0(%rip), %rdi      # 0x7253
movb $0x0, %al
callq 0x26d0
movl $0x1, %edi
callq 0x2210
testb $0x1, 0x7f15(%rip)      # 0xb2b0
jne 0x33a6
xorl %esi, %esi
movl %esi, %edi
callq 0x2200
leaq 0x7e63(%rip), %rdi      # 0xb210
addq $0x20, %rdi
callq 0x2240
leaq 0x7e53(%rip), %rdi      # 0xb210
addq $0x20, %rdi
movl $0x2, %esi
callq 0x22a0
leaq 0x7e3e(%rip), %rdi      # 0xb210
addq $0x20, %rdi
movl $0xf, %esi
callq 0x22a0
xorl %edi, %edi
leaq 0x7e27(%rip), %rsi      # 0xb210
addq $0x20, %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2060
leaq 0x7e13(%rip), %rcx      # 0xb210
movq %rcx, %rdi
addq $0x18, %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x2bf(%rip), %rdx      # 0x3150
callq 0x2370
leaq 0x7df5(%rip), %rdi      # 0xb210
callq 0x2a20
movq 0x7df1(%rip), %rdi      # 0xb218
callq 0x2390
movq 0x7ddd(%rip), %rdi      # 0xb210
callq 0x2390
leaq 0x3e34(%rip), %rdi      # 0x7273
movb $0x0, %al
callq 0x26d0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)