// File: /workspace/github_c_makefile_star2_O0/hiperiondev[P]hpsdrsim/src/hpsdr_newprotocol.c
// Function: duc_specific_thread
void* duc_specific_thread(void *data) {
    dbg_printf(1, "-- Start duc_specific_thread port: %d\n", duc_port);
    int sock;
    struct sockaddr_in addr;
    socklen_t lenaddr = sizeof(addr);
    unsigned long seqnum, seqold;
    struct timeval tv;
    unsigned char buffer[100];
    int yes = 1;
    int rc;

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

    setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*) &yes, sizeof(yes));
    setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (void*) &yes, sizeof(yes));
    tv.tv_sec = 0;
    tv.tv_usec = 10000;
    setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void*) &tv, sizeof(tv));

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

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

    seqnum = 0;
    while (run) {
        rc = recvfrom(sock, buffer, 60, 0, (struct sockaddr*) &addr, &lenaddr);
        if (rc < 0 && errno != EAGAIN) {
            dbg_printf(1, "***** ERROR: TXspec: recvmsg\n");
            break;
        }
        if (rc < 0)
            continue;
        if (rc != 60) {
            dbg_printf(1, "TX: wrong length\n");
            break;
        }
        seqold = seqnum;
        seqnum = (buffer[0] >> 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3];
        if (seqnum != 0 && seqnum != seqold + 1) {
            dbg_printf(1, "TX: SEQ ERROR, old=%lu new=%lu\n", seqold, seqnum);
        }
        if (dac != buffer[4]) {
            dac = buffer[4];
            dbg_printf(1, "TX: Number of DACs: %d\n", dac);
        }
        if (cwmode != buffer[5]) {
            cwmode = buffer[5];
            dbg_printf(1, "TX: CW mode bits = %x\n", cwmode);
        }
        if (sidelevel != buffer[6]) {
            sidelevel = buffer[6];
            dbg_printf(1, "TX: CW side tone level: %d\n", sidelevel);
        }
        rc = (buffer[7] << 8) + buffer[8];
        if (rc != sidefreq) {
            sidefreq = rc;
            dbg_printf(1, "TX: CW sidetone freq: %d\n", sidefreq);
        }
        if (speed != buffer[9]) {
            speed = buffer[9];
            dbg_printf(1, "TX: CW keyer speed: %d wpm\n", speed);
        }
        if (weight != buffer[10]) {
            weight = buffer[10];
            dbg_printf(1, "TX: CW weight: %d\n", weight);
        }
        rc = (buffer[11] << 8) + buffer[12];
        if (hang != rc) {
            hang = rc;
            dbg_printf(1, "TX: CW hang time: %d msec\n", hang);
        }
        if (delay != buffer[13]) {
            delay = buffer[13];
            dbg_printf(1, "TX: RF delay: %d msec\n", delay);
        }
        rc = (buffer[14] << 8) + buffer[15];
        if (txrate != rc) {
            txrate = rc;
            dbg_printf(1, "TX: DUC sample rate: %d\n", rc);
        }
        if (ducbits != buffer[16]) {
            ducbits = buffer[16];
            dbg_printf(1, "TX: DUC sample width: %d bits\n", ducbits);
        }
        if (orion != buffer[50]) {
            orion = buffer[50];
            dbg_printf(1, "TX: ORION bits (mic etc): %x\n", orion);
        }
        if (gain != buffer[51]) {
            gain = buffer[51];
            dbg_printf(1, "TX: LineIn Gain (dB): %f\n", 12.0 - 1.5 * gain);
        }
        if (txatt != buffer[59]) {
            txatt = buffer[59];
            txatt_dbl = pow(10.0, -0.05 * txatt);
            dbg_printf(1, "TX: ATT DUC0/ADC0: %d\n", txatt);
        }
    }
    close(sock);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movl 0xb89f(%rip), %edx      # 0x10304
movl $0x1, %edi
leaq 0x7bfe(%rip), %rsi      # 0xc66f
movb $0x0, %al
callq 0x1370
movl $0x10, -0x28(%rbp)
movl $0x1, -0xb4(%rbp)
movl $0x2, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x1230
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x4ac0
movl $0x1, %edi
leaq 0x7bea(%rip), %rsi      # 0xc696
movb $0x0, %al
callq 0x1370
movq $0x0, -0x8(%rbp)
jmp 0x4fe6
movl -0x14(%rbp), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq -0xb4(%rbp), %rcx
movl $0x4, %r8d
callq 0x1060
movl -0x14(%rbp), %edi
movl $0x1, %esi
movl $0xf, %edx
leaq -0xb4(%rbp), %rcx
movl $0x4, %r8d
callq 0x1060
movq $0x0, -0x48(%rbp)
movq $0x2710, -0x40(%rbp)    # imm = 0x2710
movl -0x14(%rbp), %edi
movl $0x1, %esi
movl $0x14, %edx
leaq -0x48(%rbp), %rcx
movl $0x10, %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 0xb7b4(%rip), %eax      # 0x10304
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 0x4b9a
movl $0x1, %edi
leaq 0x7b3a(%rip), %rsi      # 0xc6b8
movb $0x0, %al
callq 0x1370
movl -0x14(%rbp), %edi
callq 0x1110
movq $0x0, -0x8(%rbp)
jmp 0x4fe6
movq $0x0, -0x30(%rbp)
cmpl $0x0, 0xb747(%rip)      # 0x102f0
je 0x4fd6
movl -0x14(%rbp), %edi
leaq -0xb0(%rbp), %rsi
movl $0x3c, %edx
xorl %ecx, %ecx
leaq -0x24(%rbp), %r8
leaq -0x28(%rbp), %r9
callq 0x1170
movl %eax, -0xb8(%rbp)
cmpl $0x0, -0xb8(%rbp)
jge 0x4bfe
callq 0x1030
cmpl $0xb, (%rax)
je 0x4bfe
movl $0x1, %edi
leaq 0x7ae1(%rip), %rsi      # 0xc6d3
movb $0x0, %al
callq 0x1370
jmp 0x4fd6
cmpl $0x0, -0xb8(%rbp)
jge 0x4c09
jmp 0x4ba2
cmpl $0x3c, -0xb8(%rbp)
je 0x4c2a
movl $0x1, %edi
leaq 0x7ad3(%rip), %rsi      # 0xc6f1
movb $0x0, %al
callq 0x1370
jmp 0x4fd6
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movzbl -0xb0(%rbp), %eax
sarl $0x18, %eax
movzbl -0xaf(%rbp), %ecx
shll $0x10, %ecx
addl %ecx, %eax
movzbl -0xae(%rbp), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movzbl -0xad(%rbp), %ecx
addl %ecx, %eax
cltq
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x4c96
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
je 0x4c96
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl $0x1, %edi
leaq 0x7a74(%rip), %rsi      # 0xc703
movb $0x0, %al
callq 0x1370
movl 0xb884(%rip), %eax      # 0x10520
movzbl -0xac(%rbp), %ecx
cmpl %ecx, %eax
je 0x4ccd
movzbl -0xac(%rbp), %eax
movl %eax, 0xb86c(%rip)      # 0x10520
movl 0xb866(%rip), %edx      # 0x10520
movl $0x1, %edi
leaq 0x7a5d(%rip), %rsi      # 0xc723
movb $0x0, %al
callq 0x1370
movl 0xb851(%rip), %eax      # 0x10524
movzbl -0xab(%rbp), %ecx
cmpl %ecx, %eax
je 0x4d04
movzbl -0xab(%rbp), %eax
movl %eax, 0xb839(%rip)      # 0x10524
movl 0xb833(%rip), %edx      # 0x10524
movl $0x1, %edi
leaq 0x7a3e(%rip), %rsi      # 0xc73b
movb $0x0, %al
callq 0x1370
movl 0xb81e(%rip), %eax      # 0x10528
movzbl -0xaa(%rbp), %ecx
cmpl %ecx, %eax
je 0x4d3b
movzbl -0xaa(%rbp), %eax
movl %eax, 0xb806(%rip)      # 0x10528
movl 0xb800(%rip), %edx      # 0x10528
movl $0x1, %edi
leaq 0x7a1e(%rip), %rsi      # 0xc752
movb $0x0, %al
callq 0x1370
movzbl -0xa9(%rbp), %eax
shll $0x8, %eax
movzbl -0xa8(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
cmpl 0xb7cc(%rip), %eax      # 0x1052c
je 0x4d87
movl -0xb8(%rbp), %eax
movl %eax, 0xb7be(%rip)      # 0x1052c
movl 0xb7b8(%rip), %edx      # 0x1052c
movl $0x1, %edi
leaq 0x79ee(%rip), %rsi      # 0xc76e
movb $0x0, %al
callq 0x1370
movl 0xb7a3(%rip), %eax      # 0x10530
movzbl -0xa7(%rbp), %ecx
cmpl %ecx, %eax
je 0x4dbe
movzbl -0xa7(%rbp), %eax
movl %eax, 0xb78b(%rip)      # 0x10530
movl 0xb785(%rip), %edx      # 0x10530
movl $0x1, %edi
leaq 0x79d1(%rip), %rsi      # 0xc788
movb $0x0, %al
callq 0x1370
movl 0xb770(%rip), %eax      # 0x10534
movzbl -0xa6(%rbp), %ecx
cmpl %ecx, %eax
je 0x4df5
movzbl -0xa6(%rbp), %eax
movl %eax, 0xb758(%rip)      # 0x10534
movl 0xb752(%rip), %edx      # 0x10534
movl $0x1, %edi
leaq 0x79b6(%rip), %rsi      # 0xc7a4
movb $0x0, %al
callq 0x1370
movzbl -0xa5(%rbp), %eax
shll $0x8, %eax
movzbl -0xa4(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0xb8(%rbp)
movl 0xb724(%rip), %eax      # 0x10538
cmpl -0xb8(%rbp), %eax
je 0x4e41
movl -0xb8(%rbp), %eax
movl %eax, 0xb710(%rip)      # 0x10538
movl 0xb70a(%rip), %edx      # 0x10538
movl $0x1, %edi
leaq 0x797d(%rip), %rsi      # 0xc7b7
movb $0x0, %al
callq 0x1370
movl 0xb6f5(%rip), %eax      # 0x1053c
movzbl -0xa3(%rbp), %ecx
cmpl %ecx, %eax
je 0x4e78
movzbl -0xa3(%rbp), %eax
movl %eax, 0xb6dd(%rip)      # 0x1053c
movl 0xb6d7(%rip), %edx      # 0x1053c
movl $0x1, %edi
leaq 0x7961(%rip), %rsi      # 0xc7d2
movb $0x0, %al
callq 0x1370
movzbl -0xa2(%rbp), %eax
shll $0x8, %eax
movzbl -0xa1(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0xb8(%rbp)
movl 0xb6a9(%rip), %eax      # 0x10540
cmpl -0xb8(%rbp), %eax
je 0x4ec4
movl -0xb8(%rbp), %eax
movl %eax, 0xb695(%rip)      # 0x10540
movl -0xb8(%rbp), %edx
movl $0x1, %edi
leaq 0x792c(%rip), %rsi      # 0xc7e9
movb $0x0, %al
callq 0x1370
movl 0xb67a(%rip), %eax      # 0x10544
movzbl -0xa0(%rbp), %ecx
cmpl %ecx, %eax
je 0x4efb
movzbl -0xa0(%rbp), %eax
movl %eax, 0xb662(%rip)      # 0x10544
movl 0xb65c(%rip), %edx      # 0x10544
movl $0x1, %edi
leaq 0x790e(%rip), %rsi      # 0xc802
movb $0x0, %al
callq 0x1370
movl 0xb647(%rip), %eax      # 0x10548
movzbl -0x7e(%rbp), %ecx
cmpl %ecx, %eax
je 0x4f2c
movzbl -0x7e(%rbp), %eax
movl %eax, 0xb635(%rip)      # 0x10548
movl 0xb62f(%rip), %edx      # 0x10548
movl $0x1, %edi
leaq 0x78fc(%rip), %rsi      # 0xc821
movb $0x0, %al
callq 0x1370
movl 0xb61a(%rip), %eax      # 0x1054c
movzbl -0x7d(%rbp), %ecx
cmpl %ecx, %eax
je 0x4f77
movzbl -0x7d(%rbp), %eax
movl %eax, 0xb608(%rip)      # 0x1054c
cvtsi2sdl 0xb600(%rip), %xmm0 # 0x1054c
movsd 0x712c(%rip), %xmm1     # 0xc080
mulsd %xmm1, %xmm0
movsd 0x7128(%rip), %xmm1     # 0xc088
addsd %xmm1, %xmm0
movl $0x1, %edi
leaq 0x78cf(%rip), %rsi      # 0xc83f
movb $0x1, %al
callq 0x1370
movl 0xb5d3(%rip), %eax      # 0x10550
movzbl -0x75(%rbp), %ecx
cmpl %ecx, %eax
je 0x4fd1
movzbl -0x75(%rbp), %eax
movl %eax, 0xb5c1(%rip)      # 0x10550
cvtsi2sdl 0xb5b9(%rip), %xmm0 # 0x10550
movsd 0x70d9(%rip), %xmm1     # 0xc078
mulsd %xmm0, %xmm1
movsd 0x70c5(%rip), %xmm0     # 0xc070
callq 0x1090
movsd %xmm0, 0xb180(%rip)     # 0x10138
movl 0xb592(%rip), %edx      # 0x10550
movl $0x1, %edi
leaq 0x788f(%rip), %rsi      # 0xc859
movb $0x0, %al
callq 0x1370
jmp 0x4ba2
movl -0x14(%rbp), %edi
callq 0x1110
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)