// File: /workspace/github_c_makefile_star2_O2/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 $0x4a8, %rsp            # imm = 0x4A8
leaq 0x3c(%rsp), %rcx
movl %ecx, %eax
andl $0xfffffc, %eax         # imm = 0xFFFFFC
movl %eax, (%rcx)
leaq 0xa0(%rsp), %rax
movl $0x601feef, (%rax)      # imm = 0x601FEEF
movl 0x18ce1d2(%rip), %eax   # 0x18d4a38
leal -0x1000(%rax), %ecx
leal 0xec00(%rax), %edx
cmpl $0x1000, %eax           # imm = 0x1000
cmovgel %ecx, %edx
movq %rdx, 0x10(%rsp)
pushq $0x1
popq %rdi
leaq 0x40(%rsp), %rsi
callq 0x1090
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
leaq 0x17d2193(%rip), %rbx   # 0x17d8a30
xorl %r12d, %r12d
movl $0x0, 0xc(%rsp)
xorl %r14d, %r14d
xorl %ebp, %ebp
xorl %r15d, %r15d
cmpb $0x1, 0x18ce1a1(%rip)   # 0x18d4a58
jne 0x6ff1
imull $0x6, 0x68bc(%rip), %ecx # 0xd180
addl $0x2, %ecx
movl $0x1f8, %eax            # imm = 0x1F8
xorl %edx, %edx
idivl %ecx
movl %eax, %edi
movl 0x6884(%rip), %ecx      # 0xd15c
cmpl $0x1c, %ecx
jb 0x68eb
leal (%rdi,%rdi), %eax
cltq
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
jmp 0x6904
pushq $0x30
popq %rdx
shll %cl, %edx
leal (%rdi,%rdi), %eax
cltq
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
movslq %edx, %rsi
cqto
idivq %rsi
movq %rax, 0x50(%rsp)
movl 0xc(%rsp), %eax
bswapl %eax
movl %eax, 0xa4(%rsp)
pushq $0x20
popq %rax
shrl %cl, %eax
movl %eax, 0x34(%rsp)
testl %edi, %edi
movl $0x0, %eax
cmovlel %eax, %edi
movq %rdi, 0x18(%rsp)
xorl %edi, %edi
movl %ebp, %r11d
movl %r14d, %edx
movl %r12d, %esi
cmpq $0x2, %rdi
je 0x6f2a
imulq $0x204, %rdi, %rax      # imm = 0x204
leaq (%rsp,%rax), %rbp
addq $0xa0, %rbp
leaq (,%rdi,4), %rax
subq %rax, %rbp
movl %esi, %eax
leaq 0x27e7(%rip), %rcx      # 0x9150
movq (%rax,%rcx), %rax
movq %rax, 0x8(%rbp)
movl %esi, %eax
roll $0x1d, %eax
cmpl $0x4, %eax
movq %rdi, 0x58(%rsp)
ja 0x6a0e
leaq 0x2799(%rip), %rcx      # 0x9124
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl %edx, %r12d
movl %r11d, %r14d
cmpl $0x3ee, 0x6c70(%rip)    # imm = 0x3EE
pushq $0x8
popq %rsi
jne 0x6a8e
movl 0x18ce085(%rip), %ecx   # 0x18d4a38
subl 0x10(%rsp), %ecx
movl %ecx, %eax
shrl $0x8, %eax
andb $0x7f, %al
movb %al, 0xd(%rbp)
movl %ecx, 0x2c(%rsp)
movb %cl, 0xe(%rbp)
jmp 0x6a8e
movl %edx, %r12d
movl %r11d, %r14d
xorl %esi, %esi
jmp 0x6a8e
movl %edx, %r12d
movl %r11d, %r14d
pushq $0x18
jmp 0x6a8d
movl %edx, %r12d
movl %r11d, %r14d
movw $0x3f00, 0xe(%rbp)      # imm = 0x3F00
pushq $0x20
jmp 0x6a8d
cmpl $0x3ee, 0x6c10(%rip)    # imm = 0x3EE
je 0x6a16
movl 0x18ce080(%rip), %eax   # 0x18d4a8c
jmp 0x6a1f
movl %edx, %r12d
movl %r11d, %r14d
jmp 0x6a8e
movl 0x2c(%rsp), %eax
andb $0x7f, %al
movzbl %al, %eax
movb $0x0, 0xc(%rbp)
movb %al, 0xd(%rbp)
movsd 0x16ba(%rip), %xmm1     # 0x80e8
divsd 0x6bea(%rip), %xmm1     # 0xd620
movsd 0x18ce012(%rip), %xmm0  # 0x18d4a50
mulsd 0x16aa(%rip), %xmm0     # 0x80f0
mulsd 0x6bda(%rip), %xmm0     # 0xd628
ucomisd 0x16a2(%rip), %xmm0     # 0x80f8
jb 0x6a64
movl %edx, %r12d
movl %r11d, %r14d
sqrtsd %xmm0, %xmm0
jmp 0x6a7b
movl %edx, %r12d
movl %r11d, %r14d
movsd %xmm1, 0x20(%rsp)
callq 0x11c0
movsd 0x20(%rsp), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
rolw $0x8, %ax
movw %ax, 0xe(%rbp)
pushq $0x10
popq %rsi
movl %esi, 0x30(%rsp)
addq $0x10, %rbp
movl $0x1f8, %edx            # imm = 0x1F8
movq %rbp, %rdi
xorl %esi, %esi
callq 0x10d0
movsd 0x6703(%rip), %xmm0     # 0xd1b0
movapd %xmm0, %xmm6
mulsd 0x2547(%rip), %xmm6     # 0x9000
xorl %eax, %eax
cmpl $0x0, 0x6b4e(%rip)      # 0xd610
sete %al
movhpd 0x66f3(%rip), %xmm0     # xmm0 = xmm0[0],mem[0]
mulpd 0x255b(%rip), %xmm0     # 0x9030
movd %eax, %xmm1
movl $0x0, %eax
movdqa 0x60(%rsp), %xmm2
pshufd $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0]
pslld $0x1f, %xmm1
psrad $0x1f, %xmm1
pand %xmm1, %xmm2
pandn %xmm0, %xmm1
por %xmm2, %xmm1
movdqa %xmm1, %xmm0
punpcklqdq %xmm6, %xmm0    # xmm0 = xmm0[0],xmm6[0]
movdqa %xmm0, 0x80(%rsp)
movdqa %xmm1, 0x60(%rsp)
pshufd $0xee, %xmm1, %xmm0     # xmm0 = xmm1[2,3,2,3]
movdqa %xmm0, 0x70(%rsp)
leaq 0x184ff08(%rip), %r9    # 0x1856a30
movapd 0x2510(%rip), %xmm5     # 0x9040
movl %r14d, %r11d
movl %r12d, %edx
movq 0x18(%rsp), %rcx
movaps %xmm6, 0x90(%rsp)
cmpl %ecx, %eax
je 0x6f19
movl %eax, 0x38(%rsp)
movl 0x18cdf33(%rip), %edi   # 0x18d4a88
testl %edi, %edi
setne %al
movl 0x6ab4(%rip), %ecx      # 0xd614
cmpl $0x64, %ecx
setne %r8b
andb %al, %r8b
movl %edx, 0x20(%rsp)
movslq %edx, %rsi
movslq %r15d, %rdx
movslq 0x10(%rsp), %rax
cmpb $0x1, %r8b
jne 0x6bf4
leaq 0x6aaa(%rip), %r8       # 0xd630
movsd (%r8,%rsi,8), %xmm0
movsd 0x65cc(%rip), %xmm1     # 0xd160
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movsd (%rbx,%rax,8), %xmm2
movhpd (%r9,%rax,8), %xmm2     # xmm2 = xmm2[0],mem[0]
mulpd %xmm1, %xmm2
movapd %xmm2, %xmm3
movsd 0x66fd(%rip), %xmm1     # 0xd2b0
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm2, %xmm1
mulpd %xmm2, %xmm2
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
mulsd %xmm3, %xmm3
addsd %xmm2, %xmm3
mulsd 0x14cd(%rip), %xmm3     # 0x80a0
addsd 0x14cd(%rip), %xmm3     # 0x80a8
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
mulpd %xmm1, %xmm3
movapd %xmm0, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
addpd %xmm3, %xmm1
jmp 0x6c7a
cmpl $0x0, 0x6a15(%rip)      # 0xd610
leaq 0x6a2e(%rip), %r8       # 0xd630
movsd (%r8,%rsi,8), %xmm0
movslq %r11d, %r8
leaq 0x1794a1e(%rip), %r10   # 0x179b630
movsd (%r10,%r8,8), %xmm1
mulsd %xmm6, %xmm1
addsd %xmm0, %xmm1
je 0x6c58
leaq 0x17b2a07(%rip), %r10   # 0x17b9630
movsd (%r10,%rdx,8), %xmm2
leaq 0x17769fa(%rip), %r10   # 0x177d630
movhpd (%r10,%r8,8), %xmm2     # xmm2 = xmm2[0],mem[0]
mulpd 0x80(%rsp), %xmm2
leaq 0xbbe9e4(%rip), %r8     # 0xbc5630
movhpd (%r8,%rsi,8), %xmm1     # xmm1 = xmm1[0],mem[0]
addpd %xmm2, %xmm1
jmp 0x6c7a
leaq 0x17769d1(%rip), %r10   # 0x177d630
movsd (%r10,%r8,8), %xmm2
mulsd %xmm6, %xmm2
leaq 0xbbe9c0(%rip), %r8     # 0xbc5630
addsd (%r8,%rsi,8), %xmm2
unpcklpd %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0]
testl %edi, %edi
setne %dil
mulpd %xmm5, %xmm1
cmpl $0x64, %ecx
sete %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
jne 0x6cf8
movl %r11d, %r12d
movsd 0x64c1(%rip), %xmm2     # 0xd160
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
movsd (%rbx,%rax,8), %xmm3
movhpd (%r9,%rax,8), %xmm3     # xmm3 = xmm3[0],mem[0]
mulpd %xmm2, %xmm3
movapd %xmm3, %xmm2
movsd 0x65f2(%rip), %xmm4     # 0xd2b0
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
mulpd %xmm3, %xmm4
mulpd %xmm3, %xmm3
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
mulsd %xmm2, %xmm2
addsd %xmm3, %xmm2
mulsd 0x13c2(%rip), %xmm2     # 0x80a0
addsd 0x13c2(%rip), %xmm2     # 0x80a8
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
mulpd %xmm4, %xmm2
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
addpd %xmm2, %xmm0
jmp 0x6d2e
cmpl $0x0, 0x6911(%rip)      # 0xd610
leaq 0xbbe92a(%rip), %rdi    # 0xbc5630
movsd (%rdi,%rsi,8), %xmm2
unpcklpd %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0]
movl %r11d, %r12d
je 0x6d2e
leaq 0x17b2915(%rip), %rsi   # 0x17b9630
movsd (%rsi,%rdx,8), %xmm3
mulsd 0x70(%rsp), %xmm3
addsd %xmm2, %xmm3
unpcklpd %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0]
cvttpd2dq %xmm1, %xmm1
mulpd %xmm5, %xmm0
cvttpd2dq %xmm0, %xmm0
xorl %edx, %edx
cmpl $0x3ee, %ecx            # imm = 0x3EE
sete %dl
leaq 0x2304(%rip), %rcx      # 0x9050
movsd (%rcx,%rdx,8), %xmm2
movq %rbx, %r14
movsd (%rbx,%rax,8), %xmm3
mulsd %xmm2, %xmm3
mulsd (%r9,%rax,8), %xmm2
movsd 0x135d(%rip), %xmm4     # 0x80c8
mulsd %xmm4, %xmm2
cvttsd2si %xmm2, %r10d
mulsd %xmm4, %xmm3
cvttsd2si %xmm3, %r11d
xorl %ebx, %ebx
leaq 0x650a(%rip), %rdx      # 0xd290
xorl %esi, %esi
movslq 0x63f1(%rip), %rax      # 0xd180
cmpq %rax, %rsi
jge 0x6e7f
movl (%rdx), %eax
movapd %xmm1, %xmm2
testl %eax, %eax
je 0x6daf
movapd %xmm0, %xmm2
cmpl $0x1, %eax
je 0x6daf
xorpd %xmm2, %xmm2
movl 0x685e(%rip), %r8d      # 0xd614
movl %r8d, %eax
subl $0x1, %eax
setb %cl
cmpl $0x6, %r8d
sete %r13b
orb %cl, %r13b
cmpl $0x0, 0x18cdcb7(%rip)   # 0x18d4a88
setne %r9b
cmpq $0x6, %rbx
sete %dil
andb %r9b, %dil
andb %r13b, %dil
cmpl $0x2, %eax
setb %al
cmpl $0x64, %r8d
sete %cl
cmpl $0x3ee, %r8d            # imm = 0x3EE
sete %r13b
orb %cl, %r13b
orb %al, %r13b
cmpq $0x12, %rbx
sete %al
andb %r9b, %al
andb %r13b, %al
movl %r8d, %ecx
andl $-0x2, %ecx
cmpl $0x4, %ecx
sete %cl
cmpl $0xa, %r8d
sete %r8b
orb %cl, %r8b
cmpq $0x18, %rbx
sete %cl
andb %r9b, %cl
andb %r8b, %cl
orb %al, %cl
orb %dil, %cl
movd %xmm2, %ecx
cmovnel %r11d, %ecx
pshufd $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movd %xmm2, %eax
cmovnel %r10d, %eax
movl %ecx, %edi
shrl $0x10, %edi
movb %dil, (%rbp,%rbx)
movb %ch, 0x1(%rbp,%rbx)
movb %cl, 0x2(%rbp,%rbx)
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0x3(%rbp,%rbx)
movb %ah, 0x4(%rbp,%rbx)
movb %al, 0x5(%rbp,%rbx)
incq %rsi
addq $0x4, %rdx
addq $0x6, %rbx
jmp 0x6d88
movq 0x10(%rsp), %rax
cmpl $0xfbff, %eax           # imm = 0xFBFF
leal 0x1(%rax), %eax
movl %eax, %ecx
movl $0x0, %eax
cmovgel %eax, %ecx
movq %rcx, 0x10(%rsp)
movl 0x20(%rsp), %edx
cmpl $0x176fff, %edx         # imm = 0x176FFF
jl 0x6ece
leaq 0x3c(%rsp), %rdi
callq 0x10b0
movapd 0x90(%rsp), %xmm6
movapd 0x217e(%rip), %xmm5     # 0x9040
cltd
movl $0xaec, %ecx            # imm = 0xAEC
idivl %ecx
movl %eax, %edx
jmp 0x6ed0
incl %edx
leaq 0x184fb59(%rip), %r9    # 0x1856a30
movl %r12d, %r11d
movq 0x18(%rsp), %rcx
addq %rbx, %rbp
addq $0x2, %rbp
movl 0x34(%rsp), %esi
addl %esi, %r11d
cmpl $0x3c00, %r11d          # imm = 0x3C00
movl $0x0, %eax
cmovgel %eax, %r11d
addl %esi, %r15d
cmpl $0x3e80, %r15d          # imm = 0x3E80
cmovgel %eax, %r15d
movl 0x38(%rsp), %eax
incl %eax
movq %r14, %rbx
jmp 0x6b43
movq 0x58(%rsp), %rdi
incq %rdi
movl 0x30(%rsp), %esi
jmp 0x6939
movq 0x50(%rsp), %rcx
addq 0x48(%rsp), %rcx
movq %rcx, 0x48(%rsp)
movq 0x40(%rsp), %rax
incq %rax
cmpq $0x3b9aca00, %rcx       # imm = 0x3B9ACA00
jl 0x6f5d
addq $-0x3b9aca00, %rcx      # imm = 0xC4653600
movq %rcx, 0x48(%rsp)
movq %rax, 0x40(%rsp)
jmp 0x6f3e
movl %esi, %r12d
movl %edx, %r14d
movl %r11d, %ebp
incl 0xc(%rsp)
pushq $0x1
popq %rdi
movl %edi, %esi
leaq 0x40(%rsp), %rdx
xorl %ecx, %ecx
callq 0x11b0
movl 0x61d7(%rip), %edi      # 0xd158
testl %edi, %edi
js 0x6fc7
movl $0x408, %edx            # imm = 0x408
leaq 0xa0(%rsp), %rsi
xorl %ecx, %ecx
leaq 0x18cdac1(%rip), %r8    # 0x18d4a5c
pushq $0x10
popq %r9
callq 0x10e0
testq %rax, %rax
jns 0x68b0
pushq $0x1
popq %rdi
leaq 0x2b8d(%rip), %rsi      # 0x9b44
movl 0xc(%rsp), %edx
xorl %eax, %eax
callq 0x131a
jmp 0x68b0
movl 0x18cda63(%rip), %edi   # 0x18d4a30
movl $0x408, %edx            # imm = 0x408
leaq 0xa0(%rsp), %rsi
xorl %ecx, %ecx
leaq 0x18cda79(%rip), %r8    # 0x18d4a5c
pushq $0x10
popq %r9
callq 0x10e0
jmp 0x68b0
movb $0x0, 0x18cda3c(%rip)   # 0x18d4a34
xorl %eax, %eax
addq $0x4a8, %rsp            # imm = 0x4A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq