// File: /workspace/github_cpp_makefile_star2_O3/blakewford[P]kab/main.cpp
// Function: main
int main(int argc, char **argv)
{
    FILE* cache = fopen("cache.json", "r");
    if(cache != nullptr)
    {
        fclose(cache);

        std::ifstream sample("cache.json");

        set_target t;
        std::string line;
        std::getline(sample, line);
        std::istringstream iss(line);
        parse(line.c_str(), &t);
        addCachedTarget(t);
        while(std::getline(sample, line))
        {
            std::istringstream iss(line);
            parse(line.c_str(), &t);
            addCachedTarget(t);
        }

        if(argc > 1)
        {
            loop();
            return 0;
        }

        int32_t selection = -1;
        printTargets(false);
        printf("[%zu] \u001b[31mCancel\u001b[0m\n", gFound.size());
        printf("\nChoose device:\n");
        std::cin >> selection;

        if(selection >=0 && selection < gFound.size())
        {
            size_t ndx = selection;
            printf("\nSwitch \u001b[34m%s\u001b[0m:\n", gFound.at(ndx).name);
            printf("[0] OFF\n");
            printf("[1] ON\n");
            printf("[2] Listen\n");
            printf("[3] \u001b[31mCancel\u001b[0m\n");
            std::cin >> selection;
            if(selection >=0 && selection < 3)
            {
                switch(selection)
                {
                    case 0:
                    case 1:
                        toggle(ndx, selection ? true: false);
                        break;
                    case 2:
                        loop();
                        break;
                    default:
                        break;
                }
            }
        }
    }
    else
    {
        printf("Starting discovery...\n");
        discover();
    }
 
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5f8, %rsp            # imm = 0x5F8
movl %edi, 0x4(%rsp)
leaq 0x1f03(%rip), %rdi      # 0x501a
leaq 0x21b7(%rip), %rsi      # 0x52d5
callq 0x2250
testq %rax, %rax
je 0x33c6
movq %rax, %rdi
callq 0x2210
leaq 0x1edf(%rip), %rsi      # 0x501a
leaq 0x3f0(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x23a0
xorps %xmm0, %xmm0
movups %xmm0, 0x60(%rsp)
movups %xmm0, 0x50(%rsp)
movups %xmm0, 0x40(%rsp)
movups %xmm0, 0x30(%rsp)
leaq 0x4b5a(%rip), %rax      # 0x7cc8
addq $0x10, %rax
movq %rax, 0x28(%rsp)
movups %xmm0, 0x70(%rsp)
movups %xmm0, 0x80(%rsp)
movups %xmm0, 0x90(%rsp)
movups %xmm0, 0xa0(%rsp)
movups %xmm0, 0xb0(%rsp)
movups %xmm0, 0xc0(%rsp)
movups %xmm0, 0xd0(%rsp)
movups %xmm0, 0xe0(%rsp)
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %edx
leaq 0x3f0(%rsp), %r14
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x23b0
leaq 0x270(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x8, %edx
callq 0x2350
movq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x3930
leaq 0x28(%rsp), %rdi
callq 0x2f1f
leaq 0x168(%rsp), %r15
leaq 0x8(%rsp), %r12
leaq 0xf0(%rsp), %r13
leaq 0x28(%rsp), %rbp
movq 0x4d8b(%rip), %rbx      # 0x7fd0
movq 0x3f0(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x23b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x32b4
movq %r13, %rdi
movq %r12, %rsi
movl $0x8, %edx
callq 0x2350
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x3930
movq %rbp, %rdi
callq 0x2f1f
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2290
movq %r15, %rdi
callq 0x20a0
jmp 0x3245
cmpl $0x2, 0x4(%rsp)
jge 0x33d9
leaq 0xf0(%rsp), %rbx
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
xorl %edi, %edi
callq 0x279a
movq 0x5015(%rip), %rsi      # 0x82f0
subq 0x5006(%rip), %rsi      # 0x82e8
sarq $0x3, %rsi
movabsq $-0x505050505050505, %r14 # imm = 0xFAFAFAFAFAFAFAFB
imulq %r14, %rsi
leaq 0x1fdc(%rip), %rdi      # 0x52d7
xorl %eax, %eax
callq 0x2030
leaq 0x209f(%rip), %rdi      # 0x53a8
callq 0x2300
movq 0x4ccb(%rip), %rdi      # 0x7fe0
movq %rbx, %rsi
callq 0x2110
movslq 0xf0(%rsp), %rbx
testq %rbx, %rbx
js 0x33de
movq 0x4fbb(%rip), %rcx      # 0x82f0
movq 0x4fac(%rip), %rax      # 0x82e8
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r14, %rcx
cmpq %rbx, %rcx
jbe 0x33de
imulq $0x198, %rbx, %rcx      # imm = 0x198
leaq (%rax,%rcx), %rsi
addq $0x2a, %rsi
leaq 0x1f88(%rip), %rdi      # 0x52ee
xorl %eax, %eax
callq 0x2030
leaq 0x2044(%rip), %rdi      # 0x53b8
callq 0x2300
leaq 0x2040(%rip), %rdi      # 0x53c0
callq 0x2300
leaq 0x203b(%rip), %rdi      # 0x53c7
callq 0x2300
leaq 0x203a(%rip), %rdi      # 0x53d2
callq 0x2300
movq 0x4c3c(%rip), %rdi      # 0x7fe0
leaq 0xf0(%rsp), %rsi
callq 0x2110
movl 0xf0(%rsp), %eax
cmpl $0x2, %eax
ja 0x33de
jne 0x3434
callq 0x2ff5
jmp 0x33de
leaq 0x1fc5(%rip), %rdi      # 0x5392
callq 0x2300
callq 0x2a03
jmp 0x3420
callq 0x2ff5
movq 0x4beb(%rip), %rsi      # 0x7fd0
leaq 0x270(%rsp), %rdi
callq 0x2290
leaq 0x2e8(%rsp), %rdi
callq 0x20a0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x3413
callq 0x21e0
leaq 0x3f0(%rsp), %rdi
callq 0x2070
xorl %eax, %eax
addq $0x5f8, %rsp            # imm = 0x5F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %esi, %esi
testl %eax, %eax
setne %sil
movq %rbx, %rdi
callq 0x262a
jmp 0x33de
jmp 0x3476
jmp 0x3476
jmp 0x344c
movq %rax, %rbx
jmp 0x349a
jmp 0x3476
jmp 0x3476
movq %rax, %rbx
movq 0x4b71(%rip), %rsi      # 0x7fd0
leaq 0xf0(%rsp), %rdi
callq 0x2290
movq %r15, %rdi
callq 0x20a0
jmp 0x3479
movq %rax, %rbx
movq 0x4b50(%rip), %rsi      # 0x7fd0
leaq 0x270(%rsp), %rdi
callq 0x2290
leaq 0x2e8(%rsp), %rdi
callq 0x20a0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x34ae
callq 0x21e0
leaq 0x3f0(%rsp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x2360
nop