// File: /workspace/github_c_makefile_star2_O1/hiperiondev[P]hpsdrsim/src/hpsdr_newprotocol.c
// Function: send_highprio_thread
void* send_highprio_thread(void *data) {
    dbg_printf(1, "-- Start send_highprio_thread port: %d\n", shp_port);
    int sock;
    struct sockaddr_in addr;
    unsigned long seqnum;
    unsigned char buffer[60];
    int yes = 1;
    int rc;
    unsigned char *p;

    seqnum = 0;

    sock = socket(AF_INET, SOCK_DGRAM, 0);
    if (sock < 0) {
        dbg_printf(1, "***** ERROR: SendHighPrio thread: socket\n");
        return NULL;
    }

    setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*) &yes, sizeof(yes));
    setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (void*) &yes, sizeof(yes));

    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
    addr.sin_port = htons(shp_port);

    if (bind(sock, (struct sockaddr*) &addr, sizeof(addr)) < 0) {
        dbg_printf(1, "***** ERROR: SendHighPrio thread: bind\n");
        close(sock);
        return NULL;
    }

    seqnum = 0;
    while (1) {
        if (!run) {
            close(sock);
            break;
        }
        // prepare buffer
        memset(buffer, 0, 60);
        p = buffer;
        *p++ = (seqnum >> 24) & 0xFF;
        *p++ = (seqnum >> 16) & 0xFF;
        *p++ = (seqnum >> 8) & 0xFF;
        *p++ = (seqnum >> 0) & 0xFF;
        *p++ = 0;  // no PTT and CW attached
        *p++ = 0;  // no ADC overload
        *p++ = 0;
        *p++ = txdrive;

        p += 6;

        rc = (int) ((4095.0 / c1) * sqrt(100.0 * txlevel * c2));
        *p++ = (rc >> 8) & 0xFF;
        *p++ = (rc) & 0xFF;

        buffer[49] = 63;  // about 13 volts supply

        if (sendto(sock, buffer, 60, 0, (struct sockaddr*) &addr_new, sizeof(addr_new)) < 0) {
            dbg_printf(1, "***** ERROR: HP send thread sendto\n");
            break;
        }
        seqnum++;
        usleep(50000);  // wait 50 msec then send again
    }
    close(sock);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl 0x82b5(%rip), %edx      # 0xc2fc
leaq 0x4cd9(%rip), %rsi      # 0x8d27
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movl $0x1, 0xc(%rsp)
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1200
testl %eax, %eax
js 0x4203
movl %eax, %ebp
leaq 0xc(%rsp), %r14
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movq %r14, %rcx
movl $0x4, %r8d
callq 0x1070
movl %ebp, %edi
movl $0x1, %esi
movl $0xf, %edx
movq %r14, %rcx
movl $0x4, %r8d
callq 0x1070
xorpd %xmm0, %xmm0
leaq 0x60(%rsp), %rsi
movapd %xmm0, (%rsi)
movw $0x2, (%rsi)
movl $0x0, 0x4(%rsi)
movzwl 0x8226(%rip), %eax      # 0xc2fc
rolw $0x8, %ax
movw %ax, 0x2(%rsi)
movl %ebp, %edi
movl $0x10, %edx
callq 0x1150
testl %eax, %eax
js 0x4218
cmpl $0x0, 0x81e7(%rip)      # 0xc2e0
je 0x41fa
xorl %ebx, %ebx
leaq 0x8518(%rip), %r12      # 0xc620
leaq 0x8519(%rip), %r13      # 0xc628
leaq 0x18cf962(%rip), %r14   # 0x18d3a78
leaq 0x10(%rsp), %r15
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movupd %xmm0, 0x3c(%rsp)
movapd %xmm0, 0x30(%rsp)
movapd %xmm0, 0x20(%rsp)
movl %ebx, %eax
shrl $0x18, %eax
movb %al, 0x10(%rsp)
movl %ebx, %eax
shrl $0x10, %eax
movb %al, 0x11(%rsp)
movb %bh, 0x12(%rsp)
movb %bl, 0x13(%rsp)
movw $0x0, 0x14(%rsp)
movb $0x0, 0x16(%rsp)
movb 0x847d(%rip), %al       # 0xc5e0
movb %al, 0x17(%rsp)
movsd 0x3f71(%rip), %xmm1     # 0x80e0
divsd (%r12), %xmm1
movsd 0x848b(%rip), %xmm0     # 0xc608
mulsd 0x3f63(%rip), %xmm0     # 0x80e8
mulsd (%r13), %xmm0
ucomisd 0x3f5d(%rip), %xmm0     # 0x80f0
jb 0x419b
sqrtsd %xmm0, %xmm0
jmp 0x41ac
movsd %xmm1, 0x58(%rsp)
callq 0x11c0
movsd 0x58(%rsp), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movb %ah, 0x1e(%rsp)
movb %al, 0x1f(%rsp)
movb $0x3f, 0x41(%rsp)
movl $0x3c, %edx
movl %ebp, %edi
movq %r15, %rsi
xorl %ecx, %ecx
movq %r14, %r8
movl $0x10, %r9d
callq 0x10e0
testq %rax, %rax
js 0x4221
incq %rbx
movl $0xc350, %edi           # imm = 0xC350
callq 0x11f0
cmpl $0x0, 0x80ec(%rip)      # 0xc2e0
jne 0x411b
movl %ebp, %edi
callq 0x10f0
jmp 0x4234
leaq 0x4b45(%rip), %rsi      # 0x8d4f
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
jmp 0x423b
leaq 0x4b5a(%rip), %rsi      # 0x8d79
jmp 0x4228
leaq 0x4b79(%rip), %rsi      # 0x8da1
movl $0x1, %edi
xorl %eax, %eax
callq 0x13aa
movl %ebp, %edi
callq 0x10f0
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq