// File: /workspace/github_cpp_makefile_star2_O2/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, %ebx
leaq 0x219c(%rip), %rdi      # 0x501a
leaq 0x2450(%rip), %rsi      # 0x52d5
callq 0x2260
testq %rax, %rax
je 0x30d5
movq %rax, %rdi
callq 0x2220
leaq 0x2178(%rip), %rsi      # 0x501a
leaq 0x3f0(%rsp), %r14
pushq $0x8
popq %rdx
movq %r14, %rdi
callq 0x2390
xorps %xmm0, %xmm0
movups %xmm0, 0x60(%rsp)
movups %xmm0, 0x50(%rsp)
movups %xmm0, 0x40(%rsp)
movups %xmm0, 0x30(%rsp)
leaq 0x4ddd(%rip), %rax      # 0x7cb0
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)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x2060
leaq 0x270(%rsp), %rdi
leaq 0x8(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x2350
movq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x3584
leaq 0x28(%rsp), %rdi
callq 0x2cb9
leaq 0x3f0(%rsp), %r14
leaq 0x8(%rsp), %r15
leaq 0xf0(%rsp), %r12
pushq $0x8
popq %rbp
leaq 0x28(%rsp), %r13
movq %r14, %rdi
movq %r15, %rsi
callq 0x2060
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2fc7
movq %r12, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x2350
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x3584
movq %r13, %rdi
callq 0x2cb9
movq %r12, %rdi
callq 0x2110
jmp 0x2f82
cmpl $0x2, %ebx
jge 0x30e8
leaq 0xf0(%rsp), %rbx
orl $-0x1, (%rbx)
xorl %edi, %edi
callq 0x26f2
movq 0x52f7(%rip), %rax      # 0x82e0
subq 0x52e8(%rip), %rax      # 0x82d8
movl $0x198, %ecx            # imm = 0x198
cqto
idivq %rcx
leaq 0x22d6(%rip), %rdi      # 0x52d7
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x236c(%rip), %rdi      # 0x537e
callq 0x2300
movq 0x4fc2(%rip), %rdi      # 0x7fe0
movq %rbx, %rsi
callq 0x2140
movslq 0xf0(%rsp), %rbx
testq %rbx, %rbx
js 0x30ed
movq 0x52a2(%rip), %rax      # 0x82e0
subq 0x5293(%rip), %rax      # 0x82d8
movl $0x198, %ecx            # imm = 0x198
cqto
idivq %rcx
cmpq %rbx, %rax
jbe 0x30ed
leaq 0x5279(%rip), %rdi      # 0x82d8
movq %rbx, %rsi
callq 0x318e
addq $0x2a, %rax
leaq 0x227c(%rip), %rdi      # 0x52ee
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
leaq 0x230b(%rip), %rdi      # 0x538e
callq 0x2300
leaq 0x2307(%rip), %rdi      # 0x5396
callq 0x2300
leaq 0x2302(%rip), %rdi      # 0x539d
callq 0x2300
leaq 0x2301(%rip), %rdi      # 0x53a8
callq 0x2300
movq 0x4f2d(%rip), %rdi      # 0x7fe0
leaq 0xf0(%rsp), %rsi
callq 0x2140
movl 0xf0(%rsp), %eax
cmpl $0x2, %eax
ja 0x30ed
jne 0x3125
callq 0x2d5d
jmp 0x30ed
leaq 0x228c(%rip), %rdi      # 0x5368
callq 0x2300
callq 0x2901
jmp 0x3111
callq 0x2d5d
leaq 0x270(%rsp), %rdi
callq 0x2110
leaq 0x8(%rsp), %rdi
callq 0x2100
leaq 0x3f0(%rsp), %rdi
callq 0x2080
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 0x25ca
jmp 0x30ed
jmp 0x3146
jmp 0x3146
jmp 0x313d
movq %rax, %rbx
jmp 0x3168
jmp 0x3146
jmp 0x3146
movq %rax, %rbx
jmp 0x315b
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x2110
leaq 0x270(%rsp), %rdi
callq 0x2110
leaq 0x8(%rsp), %rdi
callq 0x2100
leaq 0x3f0(%rsp), %rdi
callq 0x2080
movq %rbx, %rdi
callq 0x2360
nop