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

    sock = socket(AF_INET, SOCK_DGRAM, 0);
    if (sock < 0) {
        dbg_printf(1, "***** ERROR: RX 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(ddc_port);

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

    seqnum = 0;
    while (run) {
        rc = recvfrom(sock, buffer, 1444, 0, (struct sockaddr*) &addr, &lenaddr);
        if (rc < 0 && errno != EAGAIN) {
            dbg_printf(1, "***** ERROR: DDC specific thread: recvmsg\n");
            break;
        }
        if (rc < 0)
            continue;
        if (rc != 1444) {
            dbg_printf(1, "RXspec: Received DDC specific packet with incorrect 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, "RXspec: SEQ ERROR, old=%lu new=%lu\n", seqold, seqnum);
        }
        if (adc != buffer[4]) {
            adc = buffer[4];
            dbg_printf(1, "RX: Number of ADCs: %d\n", adc);
        }
        for (i = 0; i < adc; i++) {
            rc = (buffer[5] >> i) & 0x01;
            if (rc != adcdither[i]) {
                adcdither[i] = rc;
                dbg_printf(1, "RX: ADC%d dither=%d\n", i, rc);
            }
        }
        for (i = 0; i < adc; i++) {
            rc = (buffer[6] >> i) & 0x01;
            if (rc != adcrandom[i]) {
                adcrandom[i] = rc;
                dbg_printf(1, "RX: ADC%d random=%d\n", i, rc);
            }
        }

        for (i = 0; i < NUMRECEIVERS; i++) {
            int modified = 0;

            rc = buffer[17 + 6 * i];
            if (rc != adcmap[i]) {
                modified = 1;
                adcmap[i] = rc;
            }

            rc = (buffer[18 + 6 * i] << 8) + buffer[19 + 6 * i];
            if (rc != rxrate[i]) {
                modified = 1;
                rxrate[i] = rc;
                modified = 1;
            }

            if (syncddc[i] != buffer[1363 + i]) {
                syncddc[i] = buffer[1363 + i];
                modified = 1;
            }
            rc = (buffer[7 + (i / 8)] >> (i % 8)) & 0x01;
            if (rc != ddcenable[i]) {
                modified = 1;
                ddcenable[i] = rc;
            }
            if (modified) {
                dbg_printf(1, "RX: DDC%d Enable=%d ADC%d Rate=%d SyncMap=%02x\n", i, ddcenable[i], adcmap[i], rxrate[i], syncddc[i]);
                rc = 0;
                for (j = 0; j < 8; j++) {
                    rc += (syncddc[i] >> i) & 0x01;
                }
                if (rc > 1) {
                    dbg_printf(1, "WARNING:\n");
                    dbg_printf(1, "WARNING:\n");
                    dbg_printf(1, "WARNING:\n");
                    dbg_printf(1, "WARNING: more than two DDC sync'ed\n");
                    dbg_printf(1, "WARNING: this system is not prepared to handle this case\n");
                    dbg_printf(1, "WARNING: so are most of SDRs around!\n");
                    dbg_printf(1, "WARNING:\n");
                    dbg_printf(1, "WARNING:\n");
                    dbg_printf(1, "WARNING:\n");
                }
            }
        }
    }
    close(sock);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x840, %rsp            # imm = 0x840
movq %rdi, -0x10(%rbp)
movl 0xbfcb(%rip), %edx      # 0x10300
movl $0x1, %edi
leaq 0x813a(%rip), %rsi      # 0xc47b
movb $0x0, %al
callq 0x1370
movl $0x10, -0x28(%rbp)
movl $0x1, -0x824(%rbp)
movl $0x2, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x1230
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x4390
movl $0x1, %edi
leaq 0x8126(%rip), %rsi      # 0xc4a2
movb $0x0, %al
callq 0x1370
movq $0x0, -0x8(%rbp)
jmp 0x4a39
movl -0x14(%rbp), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq -0x824(%rbp), %rcx
movl $0x4, %r8d
callq 0x1060
movl -0x14(%rbp), %edi
movl $0x1, %esi
movl $0xf, %edx
leaq -0x824(%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 0xbee0(%rip), %eax      # 0x10300
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 0x446a
movl $0x1, %edi
leaq 0x8076(%rip), %rsi      # 0xc4c4
movb $0x0, %al
callq 0x1370
movl -0x14(%rbp), %edi
callq 0x1110
movq $0x0, -0x8(%rbp)
jmp 0x4a39
movq $0x0, -0x30(%rbp)
cmpl $0x0, 0xbe77(%rip)      # 0x102f0
je 0x4a29
movl -0x14(%rbp), %edi
leaq -0x820(%rbp), %rsi
movl $0x5a4, %edx            # imm = 0x5A4
xorl %ecx, %ecx
leaq -0x24(%rbp), %r8
leaq -0x28(%rbp), %r9
callq 0x1170
movl %eax, -0x828(%rbp)
cmpl $0x0, -0x828(%rbp)
jge 0x44ce
callq 0x1030
cmpl $0xb, (%rax)
je 0x44ce
movl $0x1, %edi
leaq 0x8022(%rip), %rsi      # 0xc4e4
movb $0x0, %al
callq 0x1370
jmp 0x4a29
cmpl $0x0, -0x828(%rbp)
jge 0x44d9
jmp 0x4472
cmpl $0x5a4, -0x828(%rbp)    # imm = 0x5A4
je 0x44fd
movl $0x1, %edi
leaq 0x801e(%rip), %rsi      # 0xc50f
movb $0x0, %al
callq 0x1370
jmp 0x4a29
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movzbl -0x820(%rbp), %eax
sarl $0x18, %eax
movzbl -0x81f(%rbp), %ecx
shll $0x10, %ecx
addl %ecx, %eax
movzbl -0x81e(%rbp), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movzbl -0x81d(%rbp), %ecx
addl %ecx, %eax
cltq
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x4569
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
je 0x4569
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl $0x1, %edi
leaq 0x7fe9(%rip), %rsi      # 0xc54b
movb $0x0, %al
callq 0x1370
movl 0xbf91(%rip), %eax      # 0x10500
movzbl -0x81c(%rbp), %ecx
cmpl %ecx, %eax
je 0x45a0
movzbl -0x81c(%rbp), %eax
movl %eax, 0xbf79(%rip)      # 0x10500
movl 0xbf73(%rip), %edx      # 0x10500
movl $0x1, %edi
leaq 0x7fd6(%rip), %rsi      # 0xc56f
movb $0x0, %al
callq 0x1370
movl $0x0, -0x82c(%rbp)
movl -0x82c(%rbp), %eax
cmpl 0xbf4a(%rip), %eax      # 0x10500
jge 0x4635
movzbl -0x81b(%rbp), %eax
movl -0x82c(%rbp), %ecx
sarl %cl, %eax
andl $0x1, %eax
movl %eax, -0x828(%rbp)
movl -0x828(%rbp), %eax
movslq -0x82c(%rbp), %rdx
leaq 0xbd8c(%rip), %rcx      # 0x10370
cmpl (%rcx,%rdx,4), %eax
je 0x461f
movl -0x828(%rbp), %edx
movslq -0x82c(%rbp), %rcx
leaq 0xbd73(%rip), %rax      # 0x10370
movl %edx, (%rax,%rcx,4)
movl -0x82c(%rbp), %edx
movl -0x828(%rbp), %ecx
movl $0x1, %edi
leaq 0x7f6f(%rip), %rsi      # 0xc587
movb $0x0, %al
callq 0x1370
jmp 0x4621
movl -0x82c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x82c(%rbp)
jmp 0x45aa
movl $0x0, -0x82c(%rbp)
movl -0x82c(%rbp), %eax
cmpl 0xbeb5(%rip), %eax      # 0x10500
jge 0x46ca
movzbl -0x81a(%rbp), %eax
movl -0x82c(%rbp), %ecx
sarl %cl, %eax
andl $0x1, %eax
movl %eax, -0x828(%rbp)
movl -0x828(%rbp), %eax
movslq -0x82c(%rbp), %rdx
leaq 0xbd17(%rip), %rcx      # 0x10390
cmpl (%rcx,%rdx,4), %eax
je 0x46b4
movl -0x828(%rbp), %edx
movslq -0x82c(%rbp), %rcx
leaq 0xbcfe(%rip), %rax      # 0x10390
movl %edx, (%rax,%rcx,4)
movl -0x82c(%rbp), %edx
movl -0x828(%rbp), %ecx
movl $0x1, %edi
leaq 0x7eef(%rip), %rsi      # 0xc59c
movb $0x0, %al
callq 0x1370
jmp 0x46b6
movl -0x82c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x82c(%rbp)
jmp 0x463f
movl $0x0, -0x82c(%rbp)
cmpl $0x4, -0x82c(%rbp)
jge 0x4a24
movl $0x0, -0x834(%rbp)
imull $0x6, -0x82c(%rbp), %eax
addl $0x11, %eax
cltq
movzbl -0x820(%rbp,%rax), %eax
movl %eax, -0x828(%rbp)
movl -0x828(%rbp), %eax
movslq -0x82c(%rbp), %rdx
leaq 0xbca7(%rip), %rcx      # 0x103c0
cmpl (%rcx,%rdx,4), %eax
je 0x473f
movl $0x1, -0x834(%rbp)
movl -0x828(%rbp), %edx
movslq -0x82c(%rbp), %rcx
leaq 0xbc84(%rip), %rax      # 0x103c0
movl %edx, (%rax,%rcx,4)
imull $0x6, -0x82c(%rbp), %eax
addl $0x12, %eax
cltq
movzbl -0x820(%rbp,%rax), %eax
shll $0x8, %eax
imull $0x6, -0x82c(%rbp), %ecx
addl $0x13, %ecx
movslq %ecx, %rcx
movzbl -0x820(%rbp,%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x828(%rbp)
movl -0x828(%rbp), %eax
movslq -0x82c(%rbp), %rdx
leaq 0xbd89(%rip), %rcx      # 0x10510
cmpl (%rcx,%rdx,4), %eax
je 0x47b7
movl $0x1, -0x834(%rbp)
movl -0x828(%rbp), %edx
movslq -0x82c(%rbp), %rcx
leaq 0xbd66(%rip), %rax      # 0x10510
movl %edx, (%rax,%rcx,4)
movl $0x1, -0x834(%rbp)
movslq -0x82c(%rbp), %rcx
leaq 0xbc0b(%rip), %rax      # 0x103d0
movl (%rax,%rcx,4), %eax
movl -0x82c(%rbp), %ecx
addl $0x553, %ecx            # imm = 0x553
movslq %ecx, %rcx
movzbl -0x820(%rbp,%rcx), %ecx
cmpl %ecx, %eax
je 0x4813
movl -0x82c(%rbp), %eax
addl $0x553, %eax            # imm = 0x553
cltq
movzbl -0x820(%rbp,%rax), %edx
movslq -0x82c(%rbp), %rcx
leaq 0xbbca(%rip), %rax      # 0x103d0
movl %edx, (%rax,%rcx,4)
movl $0x1, -0x834(%rbp)
movl -0x82c(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
addl $0x7, %eax
cltq
movzbl -0x820(%rbp,%rax), %eax
movl %eax, -0x838(%rbp)
movl -0x82c(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl -0x838(%rbp), %eax
movl %edx, %ecx
sarl %cl, %eax
andl $0x1, %eax
movl %eax, -0x828(%rbp)
movl -0x828(%rbp), %eax
movslq -0x82c(%rbp), %rdx
leaq 0xbb47(%rip), %rcx      # 0x103b0
cmpl (%rcx,%rdx,4), %eax
je 0x488f
movl $0x1, -0x834(%rbp)
movl -0x828(%rbp), %edx
movslq -0x82c(%rbp), %rcx
leaq 0xbb24(%rip), %rax      # 0x103b0
movl %edx, (%rax,%rcx,4)
cmpl $0x0, -0x834(%rbp)
je 0x4a0e
movl -0x82c(%rbp), %edx
movslq -0x82c(%rbp), %rcx
leaq 0xbb00(%rip), %rax      # 0x103b0
movl (%rax,%rcx,4), %ecx
movslq -0x82c(%rbp), %rsi
leaq 0xbaff(%rip), %rax      # 0x103c0
movl (%rax,%rsi,4), %r8d
movslq -0x82c(%rbp), %rsi
leaq 0xbc3d(%rip), %rax      # 0x10510
movl (%rax,%rsi,4), %r9d
movslq -0x82c(%rbp), %rsi
leaq 0xbaeb(%rip), %rax      # 0x103d0
movl (%rax,%rsi,4), %eax
movl $0x1, %edi
leaq 0x7cbd(%rip), %rsi      # 0xc5b1
movl %eax, (%rsp)
movb $0x0, %al
callq 0x1370
movl $0x0, -0x828(%rbp)
movl $0x0, -0x830(%rbp)
cmpl $0x8, -0x830(%rbp)
jge 0x4954
movslq -0x82c(%rbp), %rcx
leaq 0xbaa7(%rip), %rax      # 0x103d0
movl (%rax,%rcx,4), %eax
movl -0x82c(%rbp), %ecx
sarl %cl, %eax
andl $0x1, %eax
addl -0x828(%rbp), %eax
movl %eax, -0x828(%rbp)
movl -0x830(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x830(%rbp)
jmp 0x4912
cmpl $0x1, -0x828(%rbp)
jle 0x4a0c
movl $0x1, %edi
leaq 0x7c74(%rip), %rsi      # 0xc5e1
movb $0x0, %al
callq 0x1370
movl $0x1, %edi
leaq 0x7c61(%rip), %rsi      # 0xc5e1
movb $0x0, %al
callq 0x1370
movl $0x1, %edi
leaq 0x7c4e(%rip), %rsi      # 0xc5e1
movb $0x0, %al
callq 0x1370
movl $0x1, %edi
leaq 0x7c45(%rip), %rsi      # 0xc5eb
movb $0x0, %al
callq 0x1370
movl $0x1, %edi
leaq 0x7c56(%rip), %rsi      # 0xc60f
movb $0x0, %al
callq 0x1370
movl $0x1, %edi
leaq 0x7c7d(%rip), %rsi      # 0xc649
movb $0x0, %al
callq 0x1370
movl $0x1, %edi
leaq 0x7c02(%rip), %rsi      # 0xc5e1
movb $0x0, %al
callq 0x1370
movl $0x1, %edi
leaq 0x7bef(%rip), %rsi      # 0xc5e1
movb $0x0, %al
callq 0x1370
movl $0x1, %edi
leaq 0x7bdc(%rip), %rsi      # 0xc5e1
movb $0x0, %al
callq 0x1370
jmp 0x4a0e
jmp 0x4a10
movl -0x82c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x82c(%rbp)
jmp 0x46d4
jmp 0x4472
movl -0x14(%rbp), %edi
callq 0x1110
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x840, %rsp            # imm = 0x840
popq %rbp
retq
nopw %cs:(%rax,%rax)