// File: /workspace/github_cpp_makefile_star2_O1/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 0x2c1a
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 0x2c1a
movabsq $-0xe6fffffe, %rax      # imm = 0xFFFFFFFF19000002
leaq 0x8(%rsp), %rbx
movq %rax, (%rbx)
movq $0x0, 0x8(%rbx)
leaq 0x4(%rsp), %r14
movl (%r14), %eax
leaq 0x30(%rsp), %rcx
movl %eax, (%rcx)
movw $0x19, 0x4(%rcx)
movq (%rcx), %rax
leaq 0x28(%rsp), %r15
movq %rax, (%r15)
movw $0x1700, 0x4(%r15)      # imm = 0x1700
leaq 0x586f(%rip), %r12      # 0x82d8
leaq -0x1f1(%rip), %r13      # 0x287f
xorl %ebp, %ebp
movq %r12, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x2390
movq %r12, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r15, %rcx
callq 0x2390
leaq -0x235(%rip), %rdx      # 0x2861
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movq %r14, %rcx
callq 0x2390
xorps %xmm0, %xmm0
movaps %xmm0, 0x5781(%rip)     # 0x8230
movaps %xmm0, 0x578a(%rip)     # 0x8240
movaps %xmm0, 0x5793(%rip)     # 0x8250
movaps %xmm0, 0x579c(%rip)     # 0x8260
movaps %xmm0, 0x57a5(%rip)     # 0x8270
movaps %xmm0, 0x57ae(%rip)     # 0x8280
movaps %xmm0, 0x57b7(%rip)     # 0x8290
movaps %xmm0, 0x57c0(%rip)     # 0x82a0
leaq 0x5749(%rip), %r15      # 0x8230
xorl %edi, %edi
callq 0x21d0
addl $0x509d, %eax           # imm = 0x509D
bswapl %eax
movl %eax, %ecx
shrl $0x10, %ecx
movl $0x90c07e2, 0x5744(%rip) # imm = 0x90C07E2
shrl $0x18, %eax
movb %al, 0x573f(%rip)       # 0x824c
movb %cl, 0x573a(%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 0x2c11
movl $0x17, %r15d
leaq 0x56e9(%rip), %rbx      # 0x8230
leaq 0x8(%rsp), %r14
cmpb $0x1, 0x56a5(%rip)      # 0x81f8
jne 0x2c11
cmpw $0x1900, 0xa(%rsp)      # imm = 0x1900
movl $0x1900, %eax           # imm = 0x1900
cmovel %r15d, %eax
movw %ax, 0xa(%rsp)
movl $0x11940, %edi          # imm = 0x11940
callq 0x2280
xorps %xmm0, %xmm0
movaps %xmm0, 0x56ae(%rip)     # 0x8230
movaps %xmm0, 0x56b7(%rip)     # 0x8240
movaps %xmm0, 0x56c0(%rip)     # 0x8250
movaps %xmm0, 0x56c9(%rip)     # 0x8260
movaps %xmm0, 0x56d2(%rip)     # 0x8270
movaps %xmm0, 0x56db(%rip)     # 0x8280
movaps %xmm0, 0x56e4(%rip)     # 0x8290
movaps %xmm0, 0x56ed(%rip)     # 0x82a0
xorl %edi, %edi
callq 0x21d0
addl $0x509d, %eax           # imm = 0x509D
bswapl %eax
movl %eax, %ecx
shrl $0x10, %ecx
movl $0x90c07e2, 0x5678(%rip) # imm = 0x90C07E2
shrl $0x18, %eax
movb %al, 0x5673(%rip)       # 0x824c
movb %cl, 0x566e(%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 0x2c11
leal 0x1(%rbp), %eax
cmpl $0xd, %ebp
movl %eax, %ebp
jb 0x2b4c
movl 0x4(%rsp), %edi
callq 0x2829
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq