// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl 0x9f17(%rip), %edx      # 0x1030c
movl $0x1, %edi
leaq 0x691e(%rip), %rsi      # 0xcd1f
movb $0x0, %al
callq 0x1370
movl $0x1, -0x74(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x2, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x1230
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x644e
movl $0x1, %edi
leaq 0x690d(%rip), %rsi      # 0xcd47
movb $0x0, %al
callq 0x1370
movq $0x0, -0x8(%rbp)
jmp 0x66ff
movl -0x14(%rbp), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq -0x74(%rbp), %rcx
movl $0x4, %r8d
callq 0x1060
movl -0x14(%rbp), %edi
movl $0x1, %esi
movl $0xf, %edx
leaq -0x74(%rbp), %rcx
movl $0x4, %r8d
callq 0x1060
leaq -0x24(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x10f0
movw $0x2, -0x24(%rbp)
xorl %edi, %edi
callq 0x10e0
movl %eax, -0x20(%rbp)
movl 0x9e60(%rip), %eax      # 0x1030c
movzwl %ax, %edi
callq 0x10b0
movw %ax, -0x22(%rbp)
movl -0x14(%rbp), %edi
leaq -0x24(%rbp), %rsi
movl $0x10, %edx
callq 0x1180
cmpl $0x0, %eax
jge 0x64f6
movl $0x1, %edi
leaq 0x6897(%rip), %rsi      # 0xcd71
movb $0x0, %al
callq 0x1370
movl -0x14(%rbp), %edi
callq 0x1110
movq $0x0, -0x8(%rbp)
jmp 0x66ff
movq $0x0, -0x30(%rbp)
cmpl $0x0, 0x9deb(%rip)      # 0x102f0
jne 0x6514
movl -0x14(%rbp), %edi
callq 0x1110
jmp 0x66ef
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x3c, %edx
callq 0x10f0
leaq -0x70(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x30(%rbp), %rax
shrq $0x18, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x80(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x80(%rbp)
movb %cl, (%rax)
movq -0x30(%rbp), %rax
shrq $0x10, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x80(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x80(%rbp)
movb %cl, (%rax)
movq -0x30(%rbp), %rax
shrq $0x8, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x80(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x80(%rbp)
movb %cl, (%rax)
movq -0x30(%rbp), %rax
shrq $0x0, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x80(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x80(%rbp)
movb %cl, (%rax)
movq -0x80(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x80(%rbp)
movb $0x0, (%rax)
movq -0x80(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x80(%rbp)
movb $0x0, (%rax)
movq -0x80(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x80(%rbp)
movb $0x0, (%rax)
movl 0xa004(%rip), %eax      # 0x105f0
movb %al, %cl
movq -0x80(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x80(%rbp)
movb %cl, (%rax)
movq -0x80(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x80(%rbp)
movsd 0x5ad5(%rip), %xmm0     # 0xc0e8
leaq 0xa01e(%rip), %rax      # 0x10638
divsd (%rax), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd 0x5ab2(%rip), %xmm0     # 0xc0e0
mulsd 0x9fe2(%rip), %xmm0     # 0x10618
leaq 0xa003(%rip), %rax      # 0x10640
mulsd (%rax), %xmm0
callq 0x11f0
movaps %xmm0, %xmm1
movsd -0x88(%rbp), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x80(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x80(%rbp)
movb %cl, (%rax)
movl -0x78(%rbp), %eax
andl $0xff, %eax
movb %al, %cl
movq -0x80(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x80(%rbp)
movb %cl, (%rax)
movb $0x3f, -0x3f(%rbp)
movl -0x14(%rbp), %edi
leaq -0x70(%rbp), %rsi
movl $0x3c, %edx
xorl %ecx, %ecx
leaq 0x18d13ea(%rip), %r8    # 0x18d7a98
movl $0x10, %r9d
callq 0x1100
cmpq $0x0, %rax
jge 0x66d4
movl $0x1, %edi
leaq 0x66ce(%rip), %rsi      # 0xcd99
movb $0x0, %al
callq 0x1370
jmp 0x66ef
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movl $0xc350, %edi           # imm = 0xC350
callq 0x1220
jmp 0x64fe
movl -0x14(%rbp), %edi
callq 0x1110
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)