// File: fulhax[P]ncpamixer/src/pulsemixer.cpp
// Function: main
int main(int argc, char *argv[])
{
    setlocale(LC_ALL, "");

    static const struct option longOpts[] = {
        { "version", no_argument, 0, 'v' },
        { "help", no_argument, 0, 'h' },
        { "config", required_argument, 0, 'c' },
        { "tab", required_argument, 0, 't' },
        { 0, 0, 0, 0 }
    };

    int c;
    int longIndex = 0;
    int startingTab = TAB_PLAYBACK;

    std::optional<fs::path> config_path{std::nullopt};

    while ((c = getopt_long(argc, argv, "vhc:t:", longOpts, &longIndex)) != -1) {

        switch (c) {
            case 'v':
                version();
                return 0;

            case 'h':
                help();
                return 0;

            case 'c':
                config_path = optarg;
                break;

            case 't':
                switch (optarg[0]) {
                    case 'p':
                        break;
                    case 'r':
                        startingTab = TAB_RECORDING;
                        break;
                    case 'o':
                        startingTab = TAB_OUTPUT;
                        break;
                    case 'i':
                        startingTab = TAB_INPUT;
                        break;
                    case 'c':
                        startingTab = TAB_CONFIGURATION;
                        break;
                    default:
                        fprintf(stderr, "invalid tab: %s\n", optarg);
                        return 1;

                }
                break;
            case '?':
                return 0;

            default:
                break;
        }
    }

    config.init(config_path);

    pulse.init();

    if (ui.init(startingTab) > 0) {
        ui.run();
    }

    return 0;
}

// Assembly:
subq $0x88, %rsp
movl $0x0, 0x84(%rsp)
movl %edi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movl $0x6, %edi
leaq 0x18491(%rip), %rsi     # 0x204fb
callq 0x7660
movl $0x0, 0x70(%rsp)
movl $0x0, 0x6c(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x82c0
movl 0x80(%rsp), %edi
movq 0x78(%rsp), %rsi
leaq 0x1811e(%rip), %rdx     # 0x201ba
leaq 0x226cd(%rip), %rcx     # 0x2a770
leaq 0x70(%rsp), %r8
callq 0x7b60
movl %eax, 0x74(%rsp)
cmpl $-0x1, %eax
je 0x822b
movl 0x74(%rsp), %eax
movl %eax, 0x1c(%rsp)
subl $0x3f, %eax
je 0x820f
jmp 0x80cd
movl 0x1c(%rsp), %eax
subl $0x63, %eax
je 0x8160
jmp 0x80dc
movl 0x1c(%rsp), %eax
subl $0x68, %eax
je 0x8141
jmp 0x80e7
movl 0x1c(%rsp), %eax
subl $0x74, %eax
je 0x8178
jmp 0x80f6
movl 0x1c(%rsp), %eax
subl $0x76, %eax
jne 0x8224
jmp 0x8105
callq 0x7f80
jmp 0x810c
movl $0x0, 0x84(%rsp)
movl $0x1, 0x20(%rsp)
jmp 0x828e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x28(%rsp)
movl %eax, 0x24(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x8340
jmp 0x82a7
callq 0x8000
jmp 0x8148
movl $0x0, 0x84(%rsp)
movl $0x1, 0x20(%rsp)
jmp 0x828e
movq 0x22df9(%rip), %rsi     # 0x2af60
leaq 0x38(%rsp), %rdi
callq 0x82e0
jmp 0x8173
jmp 0x8226
movq 0x22de1(%rip), %rax     # 0x2af60
movq (%rax), %rax
movsbl (%rax), %eax
addl $-0x63, %eax
movl %eax, %ecx
movq %rcx, 0x10(%rsp)
subl $0xf, %eax
ja 0x81d3
movq 0x10(%rsp), %rax
leaq 0x17e64(%rip), %rcx     # 0x20004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x820d
movl $0x1, 0x6c(%rsp)
jmp 0x820d
movl $0x2, 0x6c(%rsp)
jmp 0x820d
movl $0x3, 0x6c(%rsp)
jmp 0x820d
movl $0x4, 0x6c(%rsp)
jmp 0x820d
movq 0x22dce(%rip), %rax     # 0x2afa8
movq (%rax), %rdi
movq 0x22d7c(%rip), %rax     # 0x2af60
movq (%rax), %rdx
leaq 0x17fd3(%rip), %rsi     # 0x201c1
movb $0x0, %al
callq 0x79b0
movl $0x1, 0x84(%rsp)
movl $0x1, 0x20(%rsp)
jmp 0x828e
jmp 0x8226
movl $0x0, 0x84(%rsp)
movl $0x1, 0x20(%rsp)
jmp 0x828e
jmp 0x8226
jmp 0x8089
leaq 0x2366e(%rip), %rdi     # 0x2b8a0
leaq 0x38(%rsp), %rsi
callq 0xfe40
jmp 0x823e
leaq 0x234c3(%rip), %rdi     # 0x2b708
callq 0xb370
jmp 0x824c
movl 0x6c(%rsp), %esi
leaq 0x236a1(%rip), %rdi     # 0x2b8f8
callq 0x14360
movl %eax, 0xc(%rsp)
jmp 0x8262
movl 0xc(%rsp), %eax
cmpl $0x0, %eax
jle 0x827b
leaq 0x23686(%rip), %rdi     # 0x2b8f8
callq 0x16fa0
jmp 0x8279
jmp 0x827b
movl $0x0, 0x84(%rsp)
movl $0x1, 0x20(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x8340
movl 0x84(%rsp), %eax
addq $0x88, %rsp
retq
movq 0x28(%rsp), %rdi
callq 0x7c40
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)