// File: /workspace/github_c_makefile_star2_O0/comfies[P]custard/src/wm/custard.c
// Function: custard
int custard(int argc, char **argv) {
    rc_path = (char *)calloc(512, sizeof(char));

    /* Process arguments */

    char *argument;
    int index = 1;

    while (index < argc) {
        argument = argv[index++];
        log_message("arg = %s", argument);

        if (!argv[index] || !strlen(argv[index])) {
            log_fatal("No argument provided with %s, exiting.", argument);
            return EXIT_FAILURE;
        }

        if (!strcmp(argument, "--rc")) {
            strcpy(rc_path, argv[index]);
        } else if (!strcmp(argument, "--loglevel")) {
            loglevel = (short)string_to_integer(argv[index]);
        }

        index++;
    }

    /* initialize window manager */

    log_debug("Initializing window manager connections");
    if (!initialize()) {
        log_fatal("Initialization of window manager failed");
        finalize();
        return EXIT_FAILURE;
    }


    if (!strlen(rc_path)) {
        char *xdg_config_home = getenv("XDG_CONFIG_HOME");
        char *home_directory = getenv("HOME");

        if (xdg_config_home && strlen(xdg_config_home))
            sprintf(rc_path, "%s/custard/rc", xdg_config_home);
        else if (home_directory && strlen(home_directory))
            sprintf(rc_path, "%s/.config/custard/rc", home_directory);
        else
            log_debug("%s %s",
                "Unable to determine default rc path.",
                "Are $HOME or $XDG_CONFIG_HOME set?");
    }

    if (strlen(rc_path) && access(rc_path, X_OK | F_OK | R_OK) > -1) {
        log_debug("Attempting to execute file at %s", rc_path);
        if (fork() == 0)
            execl(rc_path, rc_path, NULL);
    }

    custard_is_running = 1;
    manage_pre_existing_windows();

    xcb_generic_event_t *xcb_event;
    unsigned int xcb_event_type;

    struct pollfd descriptors[2] = {
        { xcb_file_descriptor,    .events = POLLIN },
        { socket_file_descriptor, .events = POLLIN }
    };

    log_debug("Starting event loop");
    while (custard_is_running) {

        if (poll(descriptors, 2, -1)) {
            if (descriptors[0].revents & POLLIN) {
                while ((xcb_event = xcb_poll_for_event(xcb_connection))) {
                    xcb_event_type = xcb_event->response_type & ~0x80;

                    if (xcb_events[xcb_event_type])
                        xcb_events[xcb_event_type](xcb_event);

                }
            }

            if (descriptors[1].revents & POLLIN)
                ipc_process_input(read_from_socket());
        }
    }

    finalize();

    return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x200, %edi            # imm = 0x200
movl $0x1, %esi
callq 0x3350
movq %rax, 0x80d3(%rip)      # 0xd8c8
movl $0x1, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x5914
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x1c(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %r9
movl $0x2, %edi
leaq 0x4b7f(%rip), %rsi      # 0xa3b1
leaq 0x4b89(%rip), %rdx      # 0xa3c2
movl $0x28, %ecx
leaq 0x4b85(%rip), %r8       # 0xa3ca
movb $0x0, %al
callq 0x5bf0
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x5872
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x31f0
cmpq $0x0, %rax
jne 0x58a8
movq -0x18(%rbp), %r9
movl $0x1, %edi
leaq 0x4b2f(%rip), %rsi      # 0xa3b1
leaq 0x4b39(%rip), %rdx      # 0xa3c2
movl $0x2b, %ecx
leaq 0x4b3e(%rip), %r8       # 0xa3d3
movb $0x0, %al
callq 0x5bf0
movl $0x1, -0x4(%rbp)
jmp 0x5be3
movq -0x18(%rbp), %rdi
leaq 0x4b47(%rip), %rsi      # 0xa3fa
callq 0x3380
cmpl $0x0, %eax
jne 0x58d7
movq 0x8004(%rip), %rdi      # 0xd8c8
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x30e0
jmp 0x5906
movq -0x18(%rbp), %rdi
leaq 0x4b1d(%rip), %rsi      # 0xa3ff
callq 0x3380
cmpl $0x0, %eax
jne 0x5904
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x4e90
movw %ax, 0x7a8c(%rip)       # 0xd390
jmp 0x5906
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x57fc
movl $0x3, %edi
leaq 0x4a91(%rip), %rsi      # 0xa3b1
leaq 0x4a9b(%rip), %rdx      # 0xa3c2
movl $0x3a, %ecx
leaq 0x4ad7(%rip), %r8       # 0xa40a
movb $0x0, %al
callq 0x5bf0
callq 0x5ce0
cmpw $0x0, %ax
jne 0x597c
movl $0x1, %edi
leaq 0x4a60(%rip), %rsi      # 0xa3b1
leaq 0x4a6a(%rip), %rdx      # 0xa3c2
movl $0x3c, %ecx
leaq 0x4ace(%rip), %r8       # 0xa432
movb $0x0, %al
callq 0x5bf0
callq 0x5e20
movl $0x1, -0x4(%rbp)
jmp 0x5be3
movq 0x7f45(%rip), %rdi      # 0xd8c8
callq 0x31f0
cmpq $0x0, %rax
jne 0x5a50
leaq 0x4ac1(%rip), %rdi      # 0xa45a
callq 0x3050
movq %rax, -0x28(%rbp)
leaq 0x4abc(%rip), %rdi      # 0xa465
callq 0x3050
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x59e3
movq -0x28(%rbp), %rdi
callq 0x31f0
cmpq $0x0, %rax
je 0x59e3
movq 0x7ef9(%rip), %rdi      # 0xd8c8
movq -0x28(%rbp), %rdx
leaq 0x4a90(%rip), %rsi      # 0xa46a
movb $0x0, %al
callq 0x3630
jmp 0x5a4e
cmpq $0x0, -0x30(%rbp)
je 0x5a14
movq -0x30(%rbp), %rdi
callq 0x31f0
cmpq $0x0, %rax
je 0x5a14
movq 0x7ec8(%rip), %rdi      # 0xd8c8
movq -0x30(%rbp), %rdx
leaq 0x4a6d(%rip), %rsi      # 0xa478
movb $0x0, %al
callq 0x3630
jmp 0x5a4c
movl $0x3, %edi
leaq 0x4991(%rip), %rsi      # 0xa3b1
leaq 0x499b(%rip), %rdx      # 0xa3c2
movl $0x4d, %ecx
leaq 0x4a5b(%rip), %r8       # 0xa48e
leaq 0x4a5a(%rip), %r9       # 0xa494
leaq 0x4a78(%rip), %rax      # 0xa4b9
movq %rax, (%rsp)
movb $0x0, %al
callq 0x5bf0
jmp 0x5a4e
jmp 0x5a50
movq 0x7e71(%rip), %rdi      # 0xd8c8
callq 0x31f0
cmpq $0x0, %rax
je 0x5aca
movq 0x7e5f(%rip), %rdi      # 0xd8c8
movl $0x5, %esi
callq 0x3560
cmpl $-0x1, %eax
jle 0x5aca
movq 0x7e49(%rip), %r9       # 0xd8c8
movl $0x3, %edi
leaq 0x4926(%rip), %rsi      # 0xa3b1
leaq 0x4930(%rip), %rdx      # 0xa3c2
movl $0x51, %ecx
leaq 0x4a3e(%rip), %r8       # 0xa4dc
movb $0x0, %al
callq 0x5bf0
callq 0x36d0
cmpl $0x0, %eax
jne 0x5ac8
movq 0x7e12(%rip), %rdi      # 0xd8c8
movq 0x7e0b(%rip), %rsi      # 0xd8c8
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0x36b0
jmp 0x5aca
movw $0x1, 0x7dfd(%rip)      # 0xd8d0
callq 0x6110
leaq 0x7e35(%rip), %rax      # 0xd914
movl (%rax), %eax
movl %eax, -0x50(%rbp)
movw $0x1, -0x4c(%rbp)
movw $0x0, -0x4a(%rbp)
leaq 0x7dc1(%rip), %rax      # 0xd8b8
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movw $0x1, -0x44(%rbp)
movw $0x0, -0x42(%rbp)
movl $0x3, %edi
leaq 0x489d(%rip), %rsi      # 0xa3b1
leaq 0x48a7(%rip), %rdx      # 0xa3c2
movl $0x61, %ecx
leaq 0x49d6(%rip), %r8       # 0xa4fd
movb $0x0, %al
callq 0x5bf0
cmpw $0x0, 0x7d9a(%rip)      # 0xd8d0
je 0x5bd7
leaq -0x50(%rbp), %rdi
movl $0x2, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x34e0
cmpl $0x0, %eax
je 0x5bd2
movswl -0x4a(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x5bb7
jmp 0x5b62
leaq 0x7d8f(%rip), %rax      # 0xd8f8
movq (%rax), %rdi
callq 0x3480
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x5bb5
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
andl $0xffffff7f, %eax       # imm = 0xFFFFFF7F
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, %ecx
leaq 0x780a(%rip), %rax      # 0xd3a0
cmpq $0x0, (%rax,%rcx,8)
je 0x5bb3
movl -0x3c(%rbp), %eax
movl %eax, %ecx
leaq 0x77f7(%rip), %rax      # 0xd3a0
movq (%rax,%rcx,8), %rax
movq -0x38(%rbp), %rdi
callq *%rax
jmp 0x5b62
jmp 0x5bb7
movswl -0x42(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x5bd0
callq 0x52d0
movq %rax, %rdi
callq 0x3c80
jmp 0x5bd2
jmp 0x5b2e
callq 0x5e20
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)