// File: /workspace/github_c_makefile_star2_O3/hiperiondev[P]hpsdrsim/src/hpsdr_sim.c
// Function: handler_ep6
void* handler_ep6(void *arg) {
    int i, j, k, n, size;
    int header_offset;
    uint32_t counter;
    uint8_t buffer[1032];
    uint8_t *pointer;
    uint8_t id[4] = { 0xef, 0xfe, 1, 6 };
    uint8_t header[40] = {
         // C0   C1   C2   C3   C4
            127, 127, 127, 0,   0,
            33,  17,  21,  127, 127,
            127, 8,   0,   0,   0,
            0,   127, 127, 127, 16,
            0,   0,   0,   0,   127,
            127, 127, 24,  0,   0,
            0,   0,   127, 127, 127,
            32,  66,  66,  66,  66
    };
    int32_t adc1isample, adc1qsample;
    int32_t adc2isample, adc2qsample;
    int32_t dacisample, dacqsample;
    int32_t myisample, myqsample;

    struct timespec delay;
    long wait;
    int noiseIQpt, toneIQpt, divpt, rxptr;
    double i1, q1, fac1, fac2, fac3, fac4;
    int decimation;  // for converting 1536 kHz samples to 48, 192, 384, ....
    unsigned int seed;
    unsigned int tx_fifo_count;

    fac2 = 0;
    fac4 = 0;

    seed = ((uintptr_t) &seed) & 0xffffff;

    memcpy(buffer, id, 4);

    header_offset = 0;
    counter = 0;

    noiseIQpt = 0;
    toneIQpt = 0;
    divpt = 0;

    // The rxptr should never "overtake" the txptr, but
    // it also must not lag behind by too much. Let's take
    // the typical TX FIFO size
    rxptr = txptr - 4096;
    if (rxptr < 0)
        rxptr += OLDRTXLEN;

    clock_gettime(CLOCK_MONOTONIC, &delay);
    while (1) {
        if (!enable_thread)
            break;

        size = receivers * 6 + 2;
        n = 504 / size;  // number of samples per 512-byte-block
        // Time (in nanosecs) to "collect" the samples sent in one sendmsg
        if ((48 << rate) == 0) {
            wait = (2 * n * 1000000L);
        } else {
            wait = (2 * n * 1000000L) / (48 << rate);

        }

        // plug in sequence numbers
        *(uint32_t*) (buffer + 4) = htonl(counter);
        ++counter;

        // This defines the distortion as well as the amplification
        // Use PA settings such that there is full drive at full power (39 dB)

        //  48 kHz   decimation = 32
        //  96 kHz   decimation = 16
        // 192 kHz   decimation =  8
        // 384 kHz   decimation =  4
        decimation = 32 >> rate;
        for (i = 0; i < 2; ++i) {
            pointer = buffer + i * 516 - i % 2 * 4 + 8;
            memcpy(pointer, header + header_offset, 8);

            switch (header_offset) {
            case 0:
                // do not set PTT and CW in C0
                // do not set ADC overflow in C1
                if (OLDDEVICE == DEVICE_HERMES_LITE2) {
                    // C2/C3 is TX FIFO count
                    tx_fifo_count = txptr - rxptr;
                    if (tx_fifo_count < 0)
                        tx_fifo_count += OLDRTXLEN;
                    *(pointer + 5) = (tx_fifo_count >> 8) & 0x7F;
                    *(pointer + 6) = tx_fifo_count & 0xFF;
                }
                header_offset = 8;
                break;
            case 8:
                if (OLDDEVICE == DEVICE_HERMES_LITE2) {
                    // HL2: temperature
                    *(pointer + 4) = 0;
                    *(pointer + 5) = tx_fifo_count & 0x7F;  // pseudo random number
                } else {
                    // AIN5: Exciter power
                    *(pointer + 4) = 0;  // about 500 mW
                    *(pointer + 5) = txdrive;
                }
                // AIN1: Forward Power
                j = (int) ((4095.0 / c1) * sqrt(100.0 * txlevel * c2));
                *(pointer + 6) = (j >> 8) & 0xFF;
                *(pointer + 7) = (j) & 0xFF;
                header_offset = 16;
                break;
            case 16:
                // AIN2: Reverse power
                // AIN3:
                header_offset = 24;
                break;
            case 24:
                // AIN4:
                // AIN5: supply voltage
                *(pointer + 6) = 0;
                *(pointer + 7) = 63;
                header_offset = 32;
                break;
            case 32:
                header_offset = 0;
                break;
            }

            pointer += 8;
            memset(pointer, 0, 504);
            fac1 = rxatt_dbl[0] * 0.0002239;  // Amplitude of 800-Hz-signal to ADC1
            if (diversity) {
                fac2 = 0.0001 * rxatt_dbl[0];  // Amplitude of broad "man-made" noise to ADC1
                fac4 = 0.0002 * rxatt_dbl[1];  // Amplitude of broad "man-made" noise to ADC2
                // (phase shifted 90 deg., 6 dB stronger)
            }
            for (j = 0; j < n; j++) {
                // ADC1: noise + weak tone on RX, feedback sig. on TX (except STEMlab)
                if (ptt && (OLDDEVICE != DEVICE_C25)) {
                    i1 = isample[rxptr] * txdrv_dbl;
                    q1 = qsample[rxptr] * txdrv_dbl;
                    fac3 = IM3a + IM3b * (i1 * i1 + q1 * q1);
                    adc1isample = (txatt_dbl * i1 * fac3 + noiseItab[noiseIQpt]) * 8388607.0;
                    adc1qsample = (txatt_dbl * q1 * fac3 + noiseItab[noiseIQpt]) * 8388607.0;
                } else if (diversity) {
                    // man made noise only to I samples
                    adc1isample = (noiseItab[noiseIQpt] + toneItab[toneIQpt] * fac1 + divtab[divpt] * fac2) * 8388607.0;
                    adc1qsample = (noiseQtab[noiseIQpt] + toneQtab[toneIQpt] * fac1) * 8388607.0;
                } else {
                    adc1isample = (noiseItab[noiseIQpt] + toneItab[toneIQpt] * fac1) * 8388607.0;
                    adc1qsample = (noiseQtab[noiseIQpt] + toneQtab[toneIQpt] * fac1) * 8388607.0;
                }
                // ADC2: noise RX, feedback sig. on TX (only STEMlab)
                if (ptt && (OLDDEVICE == DEVICE_C25)) {
                    i1 = isample[rxptr] * txdrv_dbl;
                    q1 = qsample[rxptr] * txdrv_dbl;
                    fac3 = IM3a + IM3b * (i1 * i1 + q1 * q1);
                    adc2isample = (txatt_dbl * i1 * fac3 + noiseItab[noiseIQpt]) * 8388607.0;
                    adc2qsample = (txatt_dbl * q1 * fac3 + noiseItab[noiseIQpt]) * 8388607.0;
                } else if (diversity) {
                    // man made noise to Q channel only
                    adc2isample = noiseItab[noiseIQpt] * 8388607.0;  // Noise
                    adc2qsample = (noiseQtab[noiseIQpt] + divtab[divpt] * fac4) * 8388607.0;
                } else {
                    adc2isample = noiseItab[noiseIQpt] * 8388607.0;  // Noise
                    adc2qsample = noiseQtab[noiseIQpt] * 8388607.0;
                }

                // TX signal with peak=0.407
                if (OLDDEVICE == DEVICE_HERMES_LITE2) {
                    dacisample = isample[rxptr] * 0.230 * 8388607.0;
                    dacqsample = qsample[rxptr] * 0.230 * 8388607.0;
                } else {
                    dacisample = isample[rxptr] * 0.407 * 8388607.0;
                    dacqsample = qsample[rxptr] * 0.407 * 8388607.0;
                }

                for (k = 0; k < receivers; k++) {
                    myisample = 0;
                    myqsample = 0;
                    switch (rx_adc[k]) {
                    case 0: // ADC1
                        myisample = adc1isample;
                        myqsample = adc1qsample;
                        break;
                    case 1: // ADC2
                        myisample = adc2isample;
                        myqsample = adc2qsample;
                        break;
                    default:
                        myisample = 0;
                        myqsample = 0;
                        break;
                    }
                    if ((OLDDEVICE == DEVICE_METIS || OLDDEVICE == DEVICE_HERMES_LITE) && ptt && (k == 1)) {
                        // METIS: TX DAC signal goes to RX2 when TXing
                        myisample = dacisample;
                        myqsample = dacqsample;
                    }
                    if ((OLDDEVICE == DEVICE_HERMES || OLDDEVICE == DEVICE_GRIFFIN || OLDDEVICE == DEVICE_C25 || OLDDEVICE == DEVICE_HERMES_LITE2) && ptt
                            && (k == 3)) {
                        // HERMES: TX DAC signal goes to RX4 when TXing
                        myisample = dacisample;
                        myqsample = dacqsample;
                    }
                    if ((OLDDEVICE == DEVICE_ANGELIA || OLDDEVICE == DEVICE_ORION || OLDDEVICE == DEVICE_ORION2) && ptt && (k == 4)) {
                        // ANGELIA and beyond: TX DAC signal goes to RX5 when TXing
                        myisample = dacisample;
                        myqsample = dacqsample;
                    }
                    *pointer++ = (myisample >> 16) & 0xFF;
                    *pointer++ = (myisample >> 8) & 0xFF;
                    *pointer++ = (myisample >> 0) & 0xFF;
                    *pointer++ = (myqsample >> 16) & 0xFF;
                    *pointer++ = (myqsample >> 8) & 0xFF;
                    *pointer++ = (myqsample >> 0) & 0xFF;
                }
                // Microphone samples: silence
                pointer += 2;
                rxptr++;
                if (rxptr >= OLDRTXLEN)
                    rxptr = 0;
                noiseIQpt++;
                if (noiseIQpt >= LENNOISE)
                    noiseIQpt = rand_r(&seed) / NOISEDIV;
                toneIQpt += decimation;
                if (toneIQpt >= LENTONE)
                    toneIQpt = 0;
                divpt += decimation;
                if (divpt >= LENDIV)
                    divpt = 0;
            }
        }

        // Wait until the time has passed for all these samples
        delay.tv_nsec += wait;
        while (delay.tv_nsec >= 1000000000) {
            delay.tv_nsec -= 1000000000;
            delay.tv_sec++;
        }

        clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &delay, NULL);

        if (sock_TCP_Client > -1) {
            if (sendto(sock_TCP_Client, buffer, 1032, 0, (struct sockaddr*) &addr_old, sizeof(addr_old)) < 0) {
                dbg_printf(1, "TCP sendmsg error occurred at sequence number: %u !\n", counter);
            }
        } else {
            sendto(sock_udp, buffer, 1032, 0, (struct sockaddr*) &addr_old, sizeof(addr_old));
        }

    }
    active_thread = 0;
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
leaq 0x34(%rsp), %rax
movl %eax, %ecx
andl $0xfffffc, %ecx         # imm = 0xFFFFFC
movl %ecx, (%rax)
movl $0x601feef, 0x70(%rsp)  # imm = 0x601FEEF
movl 0x18ccd7a(%rip), %ebx   # 0x18d3a38
leaq 0x38(%rsp), %rsi
movl $0x1, %edi
callq 0x1090
cmpb $0x1, 0x18ccd84(%rip)   # 0x18d3a58
jne 0x7481
leal -0x1000(%rbx), %eax
leal 0xec00(%rbx), %r14d
cmpl $0x1000, %ebx           # imm = 0x1000
cmovgel %eax, %r14d
xorpd %xmm0, %xmm0
movsd %xmm0, 0x58(%rsp)
movsd %xmm0, 0x50(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %r10d, %r10d
xorl %ebx, %ebx
xorl %edi, %edi
movl 0x546c(%rip), %eax      # 0xc180
leal (%rax,%rax,2), %eax
leal 0x2(,%rax,2), %ecx
movl $0x1f8, %eax            # imm = 0x1F8
xorl %edx, %edx
idivl %ecx
movl 0x542f(%rip), %ecx      # 0xc15c
cmpl $0x1c, %ecx
movq %rax, 0x10(%rsp)
jb 0x6d44
addl %eax, %eax
cltq
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
jmp 0x6d5e
movl $0x30, %edx
shll %cl, %edx
addl %eax, %eax
cltq
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
movslq %edx, %rsi
cqto
idivq %rsi
movq %rax, 0x48(%rsp)
movl %edi, 0xc(%rsp)
movl %ebx, 0x24(%rsp)
movl $0x20, %edx
shrl %cl, %edx
movl %edx, 0x30(%rsp)
bswapl %ebx
movl %ebx, 0x74(%rsp)
movb $0x1, %cl
xorl %eax, %eax
movl %ecx, 0x2c(%rsp)
movq %rax, %rcx
shlq $0x9, %rcx
leaq (%rcx,%rax,4), %rcx
leaq (%rsp,%rcx), %rbp
addq $0x70, %rbp
shlq $0x2, %rax
subq %rax, %rbp
movl 0xc(%rsp), %r15d
movl %r15d, %eax
leaq 0x2383(%rip), %rcx      # 0x9130
movq (%rax,%rcx), %rax
movq %rax, 0x8(%rbp)
movl %r15d, %eax
roll $0x1d, %eax
cmpl $0x4, %eax
ja 0x6e4d
leaq 0x2339(%rip), %rcx      # 0x9104
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r10, %rbx
movl $0x8, %r15d
cmpl $0x3ee, 0x582d(%rip)    # imm = 0x3EE
jne 0x6ec7
movl 0x18ccc45(%rip), %ecx   # 0x18d3a38
subl %r14d, %ecx
movl %ecx, %eax
shrl $0x8, %eax
andb $0x7f, %al
movb %al, 0xd(%rbp)
movl %ecx, 0x28(%rsp)
movb %cl, 0xe(%rbp)
jmp 0x6ec7
movq %r10, %rbx
xorl %r15d, %r15d
jmp 0x6ec7
movq %r10, %rbx
movl $0x18, %r15d
jmp 0x6ec7
movq %r10, %rbx
movw $0x3f00, 0xe(%rbp)      # imm = 0x3F00
movl $0x20, %r15d
jmp 0x6ec7
cmpl $0x3ee, 0x57d1(%rip)    # imm = 0x3EE
je 0x6e52
movl 0x18ccc41(%rip), %eax   # 0x18d3a8c
jmp 0x6e5b
movq %r10, %rbx
jmp 0x6ec7
movl 0x28(%rsp), %eax
andb $0x7f, %al
movzbl %al, %eax
movb $0x0, 0xc(%rbp)
movb %al, 0xd(%rbp)
movsd 0x1276(%rip), %xmm1     # 0x80e0
divsd 0x57ae(%rip), %xmm1     # 0xc620
movsd 0x18ccbd6(%rip), %xmm0  # 0x18d3a50
mulsd 0x1266(%rip), %xmm0     # 0x80e8
mulsd 0x579e(%rip), %xmm0     # 0xc628
ucomisd 0x125e(%rip), %xmm0     # 0x80f0
jb 0x6e9d
movq %r10, %rbx
sqrtsd %xmm0, %xmm0
jmp 0x6eb1
movq %r10, %rbx
movsd %xmm1, 0x18(%rsp)
callq 0x11c0
movsd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
rolw $0x8, %ax
movw %ax, 0xe(%rbp)
movl $0x10, %r15d
addq $0x10, %rbp
movl $0x1f8, %edx            # imm = 0x1F8
movq %rbp, %rdi
xorl %esi, %esi
callq 0x10d0
movsd 0x52cd(%rip), %xmm8     # 0xc1b0
cmpl $0x0, 0x5726(%rip)      # 0xc610
movapd %xmm8, %xmm0
mulsd 0x11a9(%rip), %xmm0     # 0x80a0
movsd 0x52c1(%rip), %xmm1     # 0xc1c0
mulsd 0x1189(%rip), %xmm1     # 0x8090
je 0x6f15
movsd %xmm0, 0x50(%rsp)
movsd %xmm1, 0x58(%rsp)
movl %r15d, 0xc(%rsp)
mulsd 0x1175(%rip), %xmm8     # 0x8098
cmpl $0x0, 0x10(%rsp)
movapd 0x2100(%rip), %xmm7     # 0x9030
movq %rbx, %r10
jle 0x735d
xorl %r15d, %r15d
movsd %xmm8, 0x60(%rsp)
movl 0x18ccb3f(%rip), %esi   # 0x18d3a88
testl %esi, %esi
setne %cl
movl 0x56c0(%rip), %eax      # 0xc614
cmpl $0x64, %eax
setne %dl
andb %cl, %dl
movslq %r10d, %rcx
cmpb $0x1, %dl
movq %r10, 0x18(%rsp)
jne 0x6ffb
movslq %r14d, %rdx
movsd 0x51e8(%rip), %xmm0     # 0xc160
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
leaq 0x17d0aad(%rip), %rsi   # 0x17d7a30
movsd (%rsi,%rdx,8), %xmm1
leaq 0x184eaa1(%rip), %rsi   # 0x1855a30
movhpd (%rsi,%rdx,8), %xmm1    # xmm1 = xmm1[0],mem[0]
mulpd %xmm0, %xmm1
movapd %xmm1, %xmm0
movsd 0x530c(%rip), %xmm2     # 0xc2b0
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
mulpd %xmm1, %xmm2
mulpd %xmm1, %xmm1
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
mulsd 0x10e4(%rip), %xmm0     # 0x80a8
addsd 0x10e4(%rip), %xmm0     # 0x80b0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm2, %xmm0
leaq 0x5655(%rip), %rdx      # 0xc630
movsd (%rdx,%rcx,8), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
addpd %xmm0, %xmm1
mulpd %xmm7, %xmm1
cvttpd2dq %xmm1, %xmm0
movl 0x561a(%rip), %edx      # 0xc610
jmp 0x7109
movl 0x560f(%rip), %edx      # 0xc610
leaq 0x5628(%rip), %rdi      # 0xc630
movsd (%rdi,%rcx,8), %xmm1
movslq %r13d, %rdi
leaq 0x1793619(%rip), %r8    # 0x179a630
movsd (%r8,%rdi,8), %xmm0
mulsd %xmm8, %xmm0
addsd %xmm1, %xmm0
testl %edx, %edx
je 0x7044
movslq %r12d, %r8
leaq 0x17b15fc(%rip), %r9    # 0x17b8630
movsd (%r9,%r8,8), %xmm2
mulsd 0x50(%rsp), %xmm2
addsd %xmm2, %xmm0
testl %esi, %esi
setne %sil
leaq 0x17755df(%rip), %r8    # 0x177c630
movsd (%r8,%rdi,8), %xmm2
mulsd %xmm8, %xmm2
leaq 0xbbd5cd(%rip), %rdi    # 0xbc4630
addsd (%rdi,%rcx,8), %xmm2
unpcklpd %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0]
mulpd %xmm7, %xmm0
cvttpd2dq %xmm0, %xmm0
cmpl $0x64, %eax
sete %dil
andb %sil, %dil
cmpb $0x1, %dil
jne 0x7109
movslq %r14d, %rax
leaq 0x17d099e(%rip), %rcx   # 0x17d7a30
movsd (%rcx,%rax,8), %xmm2
leaq 0x184e992(%rip), %rcx   # 0x1855a30
movsd (%rcx,%rax,8), %xmm3
movsd 0x50b5(%rip), %xmm4     # 0xc160
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
movapd %xmm2, %xmm5
unpcklpd %xmm3, %xmm5            # xmm5 = xmm5[0],xmm3[0]
mulpd %xmm4, %xmm5
movapd %xmm5, %xmm4
movsd 0x51e9(%rip), %xmm6     # 0xc2b0
unpcklpd %xmm6, %xmm6            # xmm6 = xmm6[0,0]
mulpd %xmm5, %xmm6
mulpd %xmm5, %xmm5
unpckhpd %xmm5, %xmm5            # xmm5 = xmm5[1,1]
mulsd %xmm4, %xmm4
addsd %xmm5, %xmm4
mulsd 0xfc1(%rip), %xmm4      # 0x80a8
addsd 0xfc1(%rip), %xmm4      # 0x80b0
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
mulpd %xmm6, %xmm4
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
addpd %xmm4, %xmm1
mulpd %xmm7, %xmm1
cvttpd2dq %xmm1, %xmm1
jmp 0x7186
leaq 0xbbd520(%rip), %rsi    # 0xbc4630
movsd (%rsi,%rcx,8), %xmm1
testl %edx, %edx
je 0x7132
movslq %r12d, %rdx
leaq 0x17b150d(%rip), %rsi   # 0x17b8630
movsd (%rsi,%rdx,8), %xmm2
mulsd 0x58(%rsp), %xmm2
addsd %xmm2, %xmm1
leaq 0x54f7(%rip), %rdx      # 0xc630
movsd (%rdx,%rcx,8), %xmm2
unpcklpd %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0]
mulpd %xmm7, %xmm2
cvttpd2dq %xmm2, %xmm1
movslq %r14d, %rcx
leaq 0x17d08dc(%rip), %rdx   # 0x17d7a30
movsd (%rdx,%rcx,8), %xmm2
cmpl $0x3ee, %eax            # imm = 0x3EE
jne 0x717a
movsd 0x1e98(%rip), %xmm4     # 0x9000
mulsd %xmm4, %xmm2
leaq 0x184e8bd(%rip), %rax   # 0x1855a30
movsd (%rax,%rcx,8), %xmm3
jmp 0x7192
leaq 0x184e8af(%rip), %rax   # 0x1855a30
movsd (%rax,%rcx,8), %xmm3
movsd 0x1e6a(%rip), %xmm4     # 0x8ff8
mulsd %xmm4, %xmm2
mulsd %xmm4, %xmm3
cmpl $0x0, 0x4fe3(%rip)      # 0xc180
jle 0x72c7
movq %r14, 0x68(%rsp)
movsd 0xf10(%rip), %xmm4      # 0x80c0
mulsd %xmm4, %xmm3
cvttsd2si %xmm3, %r11d
mulsd %xmm4, %xmm2
cvttsd2si %xmm2, %ecx
leaq 0x50c8(%rip), %rsi      # 0xc290
xorl %edx, %edx
xorl %edi, %edi
movl (%rsi), %eax
movapd %xmm0, %xmm2
testl %eax, %eax
je 0x71e3
movapd %xmm1, %xmm2
cmpl $0x1, %eax
je 0x71e3
xorpd %xmm2, %xmm2
movl 0x542a(%rip), %r9d      # 0xc614
movl %r9d, %eax
subl $0x1, %eax
setb %r8b
cmpl $0x6, %r9d
sete %bl
orb %r8b, %bl
cmpl $0x0, 0x18cc883(%rip)   # 0x18d3a88
setne %r10b
cmpq $0x6, %rdx
sete %r8b
andb %r10b, %r8b
andb %bl, %r8b
cmpl $0x2, %eax
setb %al
cmpl $0x64, %r9d
sete %bl
cmpl $0x3ee, %r9d            # imm = 0x3EE
sete %r14b
orb %bl, %r14b
orb %al, %r14b
cmpq $0x12, %rdx
sete %al
andb %r10b, %al
andb %r14b, %al
movl %r9d, %ebx
andl $-0x2, %ebx
cmpl $0x4, %ebx
sete %bl
cmpl $0xa, %r9d
sete %r9b
orb %bl, %r9b
cmpq $0x18, %rdx
sete %bl
andb %r10b, %bl
andb %r9b, %bl
orb %al, %bl
orb %r8b, %bl
movd %xmm2, %eax
cmovnel %ecx, %eax
pshufd $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movd %xmm2, %ebx
cmovnel %r11d, %ebx
movl %eax, %r8d
shrl $0x10, %r8d
movb %r8b, (%rbp,%rdx)
movb %ah, 0x1(%rbp,%rdx)
movb %al, 0x2(%rbp,%rdx)
movl %ebx, %eax
shrl $0x10, %eax
movb %al, 0x3(%rbp,%rdx)
movb %bh, 0x4(%rbp,%rdx)
movb %bl, 0x5(%rbp,%rdx)
incq %rdi
movslq 0x4ed2(%rip), %rax      # 0xc180
addq $0x6, %rdx
addq $0x4, %rsi
cmpq %rax, %rdi
jl 0x71cc
addq %rdx, %rbp
movq 0x68(%rsp), %r14
cmpl $0xfbff, %r14d          # imm = 0xFBFF
leal 0x1(%r14), %eax
movl %eax, %r14d
movl $0x0, %ebx
cmovgel %ebx, %r14d
movq 0x18(%rsp), %r10
cmpl $0x176fff, %r10d        # imm = 0x176FFF
jl 0x7325
leaq 0x34(%rsp), %rdi
callq 0x10b0
movsd 0x60(%rsp), %xmm8
movapd 0x1d2b(%rip), %xmm7     # 0x9030
movslq %eax, %r10
imulq $-0x447c854f, %r10, %rax # imm = 0xBB837AB1
shrq $0x20, %rax
addl %eax, %r10d
movl %r10d, %eax
shrl $0x1f, %eax
sarl $0xb, %r10d
addl %eax, %r10d
jmp 0x7328
incl %r10d
movq 0x10(%rsp), %rax
addq $0x2, %rbp
movl 0x30(%rsp), %ecx
addl %ecx, %r13d
cmpl $0x3c00, %r13d          # imm = 0x3C00
cmovgel %ebx, %r13d
addl %ecx, %r12d
cmpl $0x3e80, %r12d          # imm = 0x3E80
cmovgel %ebx, %r12d
incl %r15d
cmpl %eax, %r15d
jne 0x6f43
movl $0x1, %eax
testb $0x1, 0x2c(%rsp)
movl $0x0, %ecx
jne 0x6d80
movq %r10, %r15
movq 0x48(%rsp), %rdi
addq 0x40(%rsp), %rdi
movq %rdi, 0x40(%rsp)
cmpq $0x3b9aca00, %rdi       # imm = 0x3B9ACA00
jl 0x73e9
movl $0x773593ff, %eax       # imm = 0x773593FF
cmpq %rax, %rdi
movl $0x773593ff, %ecx       # imm = 0x773593FF
cmovbq %rdi, %rcx
movq 0x38(%rsp), %rsi
movq %rdi, %rax
subq %rcx, %rax
addq $0x3b9ac9ff, %rax       # imm = 0x3B9AC9FF
shrq $0x9, %rax
movabsq $0x44b82fa09b5a53, %rcx # imm = 0x44B82FA09B5A53
mulq %rcx
shrq $0xb, %rdx
imulq $-0x3b9aca00, %rdx, %rax # imm = 0xC4653600
movq $-0x3b9aca00, %rcx      # imm = 0xC4653600
addq %rcx, %rdi
addq %rax, %rdi
leaq (%rsi,%rdx), %rax
incq %rax
movq %rdi, 0x40(%rsp)
movq %rax, 0x38(%rsp)
movl 0x24(%rsp), %ebx
incl %ebx
movl $0x1, %edi
movl $0x1, %esi
leaq 0x38(%rsp), %rdx
xorl %ecx, %ecx
callq 0x11b0
movl 0x4d4d(%rip), %edi      # 0xc158
testl %edi, %edi
js 0x7449
movl $0x408, %edx            # imm = 0x408
leaq 0x70(%rsp), %rsi
xorl %ecx, %ecx
leaq 0x18cc63a(%rip), %r8    # 0x18d3a5c
movl $0x10, %r9d
callq 0x10e0
testq %rax, %rax
jns 0x746d
movl $0x1, %edi
leaq 0x26e6(%rip), %rsi      # 0x9b24
movl %ebx, %edx
xorl %eax, %eax
callq 0x13ba
jmp 0x746d
movl 0x18cc5e1(%rip), %edi   # 0x18d3a30
movl $0x408, %edx            # imm = 0x408
leaq 0x70(%rsp), %rsi
xorl %ecx, %ecx
leaq 0x18cc5fa(%rip), %r8    # 0x18d3a5c
movl $0x10, %r9d
callq 0x10e0
cmpb $0x0, 0x18cc5e4(%rip)   # 0x18d3a58
movq %r15, %r10
movl 0xc(%rsp), %edi
jne 0x6d0e
movb $0x0, 0x18cc5ac(%rip)   # 0x18d3a34
xorl %eax, %eax
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq