// File: /workspace/github_cpp_makefile_star2_O3/blakewford[P]kab/main.cpp
// Function: discover()
void discover()
{
    int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if(sock < 0) return;

    int32_t broadcast = 1;
    int ret = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof(broadcast));
    if(ret != 0) return;

    struct sockaddr_in server = buildServerType(INADDR_BROADCAST, DISCOVER_PORT1);

    broadcastParams params1;
    params1.socket = sock;
    params1.port = DISCOVER_PORT1;
    broadcastParams params2 = params1;
    params2.port = DISCOVER_PORT2;

    pthread_t watchDog;
    pthread_create(&gRecvP1,  nullptr, recvBroadcast, &params1);
    pthread_create(&gRecvP1,  nullptr, recvBroadcast, &params2);
    pthread_create(&watchDog, nullptr, timeoutThread, &sock);

    buildQuery();

    int32_t count = 0;
    ssize_t sent = sendto(sock, query, QUERY_SIZE, 0, (sockaddr*)&server, sizeof(server));
    while(sent == QUERY_SIZE && count < ATTTEMPTS && gKeepGoing)
    {
        count++;
        server.sin_port = server.sin_port == htons(DISCOVER_PORT1) ? htons(DISCOVER_PORT2): htons(DISCOVER_PORT1);
        usleep(1000*72);
        buildQuery();

        sent = sendto(sock, query, QUERY_SIZE, 0, (sockaddr*)&server, sizeof(server));
    }

    quit(sock);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl $0x2, %edi
movl $0x2, %esi
movl $0x11, %edx
callq 0x2060
movl %eax, 0x4(%rsp)
testl %eax, %eax
js 0x2c55
movl %eax, %ebp
leaq 0x1c(%rsp), %rcx
movl $0x1, (%rcx)
movl %eax, %edi
movl $0x1, %esi
movl $0x6, %edx
movl $0x4, %r8d
callq 0x2370
testl %eax, %eax
jne 0x2c55
movabsq $-0xe6fffffe, %rax      # imm = 0xFFFFFFFF19000002
leaq 0x8(%rsp), %rbx
movq %rax, (%rbx)
movq $0x0, 0x8(%rbx)
leaq 0x30(%rsp), %rcx
movl %ebp, (%rcx)
movw $0x19, 0x4(%rcx)
movq (%rcx), %rax
leaq 0x28(%rsp), %r14
movq %rax, (%r14)
movw $0x1700, 0x4(%r14)      # imm = 0x1700
leaq 0x583b(%rip), %r15      # 0x82d8
leaq -0x1eb(%rip), %r12      # 0x28b9
xorl %r13d, %r13d
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x2390
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %r14, %rcx
callq 0x2390
leaq -0x230(%rip), %rdx      # 0x289b
leaq 0x20(%rsp), %rdi
leaq 0x4(%rsp), %r14
xorl %esi, %esi
movq %r14, %rcx
callq 0x2390
xorps %xmm0, %xmm0
movaps %xmm0, 0x5747(%rip)     # 0x8230
movaps %xmm0, 0x5750(%rip)     # 0x8240
movaps %xmm0, 0x5759(%rip)     # 0x8250
movaps %xmm0, 0x5762(%rip)     # 0x8260
movaps %xmm0, 0x576b(%rip)     # 0x8270
movaps %xmm0, 0x5774(%rip)     # 0x8280
movaps %xmm0, 0x577d(%rip)     # 0x8290
movaps %xmm0, 0x5786(%rip)     # 0x82a0
leaq 0x570f(%rip), %r15      # 0x8230
xorl %edi, %edi
callq 0x21d0
addl $0x509d, %eax           # imm = 0x509D
bswapl %eax
movl %eax, %ecx
shrl $0x10, %ecx
movl $0x90c07e2, 0x570a(%rip) # imm = 0x90C07E2
shrl $0x18, %eax
movb %al, 0x5705(%rip)       # 0x824c
movb %cl, 0x5700(%rip)       # 0x824d
movl (%r14), %edi
movl $0x80, %edx
movq %r15, %rsi
xorl %ecx, %ecx
movq %rbx, %r8
movl $0x10, %r9d
callq 0x2040
cmpq $0x80, %rax
jne 0x2c4c
movl $0x17, %ebp
leaq 0x56b0(%rip), %rbx      # 0x8230
leaq 0x8(%rsp), %r14
cmpb $0x1, 0x566c(%rip)      # 0x81f8
jne 0x2c4c
cmpw $0x1900, 0xa(%rsp)      # imm = 0x1900
movl $0x1900, %eax           # imm = 0x1900
cmovel %ebp, %eax
movw %ax, 0xa(%rsp)
movl $0x11940, %edi          # imm = 0x11940
callq 0x2280
xorps %xmm0, %xmm0
movaps %xmm0, 0x5676(%rip)     # 0x8230
movaps %xmm0, 0x567f(%rip)     # 0x8240
movaps %xmm0, 0x5688(%rip)     # 0x8250
movaps %xmm0, 0x5691(%rip)     # 0x8260
movaps %xmm0, 0x569a(%rip)     # 0x8270
movaps %xmm0, 0x56a3(%rip)     # 0x8280
movaps %xmm0, 0x56ac(%rip)     # 0x8290
movaps %xmm0, 0x56b5(%rip)     # 0x82a0
xorl %edi, %edi
callq 0x21d0
addl $0x509d, %eax           # imm = 0x509D
bswapl %eax
movl %eax, %ecx
shrl $0x10, %ecx
movl $0x90c07e2, 0x5640(%rip) # imm = 0x90C07E2
shrl $0x18, %eax
movb %al, 0x563b(%rip)       # 0x824c
movb %cl, 0x5636(%rip)       # 0x824d
movl 0x4(%rsp), %edi
movl $0x80, %edx
movq %rbx, %rsi
xorl %ecx, %ecx
movq %r14, %r8
movl $0x10, %r9d
callq 0x2040
cmpq $0x80, %rax
jne 0x2c4c
leal 0x1(%r13), %eax
cmpl $0xd, %r13d
movl %eax, %r13d
jb 0x2b85
movl 0x4(%rsp), %edi
callq 0x2863
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq