// File: /workspace/github_c_makefile_star2_O1/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 $0x488, %rsp            # imm = 0x488
leaq 0x2c(%rsp), %rax
movl %eax, %ecx
andl $0xfffffc, %ecx         # imm = 0xFFFFFC
movl %ecx, (%rax)
movl $0x601feef, 0x80(%rsp) # imm = 0x601FEEF
movl 0x18cce1e(%rip), %ebx   # 0x18d3a38
leaq 0x30(%rsp), %rsi
movl $0x1, %edi
callq 0x1090
cmpb $0x1, 0x18cce28(%rip)   # 0x18d3a58
jne 0x740e
leal -0x1000(%rbx), %eax
leal 0xec00(%rbx), %ecx
cmpl $0x1000, %ebx           # imm = 0x1000
movq %rcx, %rbx
cmovgel %eax, %ebx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x48(%rsp)
movsd %xmm0, 0x50(%rsp)
xorl %r10d, %r10d
xorl %edi, %edi
xorl %r11d, %r11d
movl $0x0, 0x4(%rsp)
xorl %esi, %esi
movl 0x550a(%rip), %eax      # 0xc180
leal (%rax,%rax,2), %eax
leal 0x2(,%rax,2), %ecx
movl $0x1f8, %eax            # imm = 0x1F8
xorl %edx, %edx
idivl %ecx
movl 0x54cd(%rip), %ecx      # 0xc15c
cmpl $0x1c, %ecx
movq %rax, 0x58(%rsp)
movl %esi, (%rsp)
jb 0x6ca9
addl %eax, %eax
cltq
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
jmp 0x6cc3
movl $0x30, %edx
shll %cl, %edx
addl %eax, %eax
cltq
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
movslq %edx, %rsi
cqto
idivq %rsi
movq %rax, 0x40(%rsp)
movl 0x4(%rsp), %eax
bswapl %eax
movl %eax, 0x84(%rsp)
movl $0x20, %eax
shrl %cl, %eax
movl %eax, 0x1c(%rsp)
xorl %ecx, %ecx
movq %rcx, %rax
shlq $0x9, %rax
leaq (%rax,%rcx,4), %rax
leaq (%rsp,%rax), %rbp
addq $0x80, %rbp
movq %rcx, 0x60(%rsp)
leaq (,%rcx,4), %rax
subq %rax, %rbp
movl (%rsp), %edx
movl %edx, %eax
leaq 0x241c(%rip), %rcx      # 0x9130
movq (%rax,%rcx), %rax
movq %rax, 0x8(%rbp)
movl %edx, %eax
roll $0x1d, %eax
cmpl $0x4, %eax
ja 0x6dd5
leaq 0x23d3(%rip), %rcx      # 0x9104
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r11, %r12
movl %edi, %r15d
movl %r10d, %r14d
movl $0x8, (%rsp)
cmpl $0x3ee, 0x58c0(%rip)    # imm = 0x3EE
jne 0x6e5e
movl 0x18cccd8(%rip), %ecx   # 0x18d3a38
subl %ebx, %ecx
movl %ecx, %eax
shrl $0x8, %eax
andb $0x7f, %al
movb %al, 0xd(%rbp)
movl %ecx, 0x18(%rsp)
movb %cl, 0xe(%rbp)
jmp 0x6e5e
movq %r11, %r12
movl %edi, %r15d
movl %r10d, %r14d
movl $0x0, (%rsp)
jmp 0x6e5e
movq %r11, %r12
movl %edi, %r15d
movl %r10d, %r14d
movl $0x18, (%rsp)
jmp 0x6e5e
movq %r11, %r12
movl %edi, %r15d
movl %r10d, %r14d
movw $0x3f00, 0xe(%rbp)      # imm = 0x3F00
movl $0x20, (%rsp)
jmp 0x6e5e
cmpl $0x3ee, 0x584d(%rip)    # imm = 0x3EE
movb $0x0, 0xc(%rbp)
je 0x6de0
movl 0x18cccb9(%rip), %eax   # 0x18d3a8c
jmp 0x6de9
movq %r11, %r12
movl %edi, %r15d
movl %r10d, %r14d
jmp 0x6e5e
movl 0x18(%rsp), %eax
andb $0x7f, %al
movzbl %al, %eax
movb %al, 0xd(%rbp)
movsd 0x12ec(%rip), %xmm1     # 0x80e0
divsd 0x5824(%rip), %xmm1     # 0xc620
movsd 0x18ccc4c(%rip), %xmm0  # 0x18d3a50
mulsd 0x12dc(%rip), %xmm0     # 0x80e8
mulsd 0x5814(%rip), %xmm0     # 0xc628
ucomisd 0x12d4(%rip), %xmm0     # 0x80f0
jb 0x6e2d
movq %r11, %r12
movl %edi, %r15d
movl %r10d, %r14d
sqrtsd %xmm0, %xmm0
jmp 0x6e47
movq %r11, %r12
movl %edi, %r15d
movl %r10d, %r14d
movsd %xmm1, 0x10(%rsp)
callq 0x11c0
movsd 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
rolw $0x8, %ax
movw %ax, 0xe(%rbp)
movl $0x10, (%rsp)
addq $0x10, %rbp
movl $0x1f8, %edx            # imm = 0x1F8
movq %rbp, %rdi
xorl %esi, %esi
callq 0x10d0
movsd 0x5337(%rip), %xmm7     # 0xc1b0
cmpl $0x0, 0x5790(%rip)      # 0xc610
movapd %xmm7, %xmm0
mulsd 0x1224(%rip), %xmm0     # 0x80b0
movsd 0x532c(%rip), %xmm1     # 0xc1c0
mulsd 0x121c(%rip), %xmm1     # 0x80b8
je 0x6eaa
movsd %xmm0, 0x50(%rsp)
movsd %xmm1, 0x48(%rsp)
mulsd 0x11de(%rip), %xmm7     # 0x8090
cmpl $0x0, 0x58(%rsp)
movl %r14d, %r10d
movl %r15d, %edi
movq %r12, %r11
jle 0x72d9
xorl %edx, %edx
movsd %xmm7, 0x68(%rsp)
movl %edx, 0x8(%rsp)
movl 0x18ccbb0(%rip), %edx   # 0x18d3a88
testl %edx, %edx
setne %al
movl 0x5731(%rip), %ecx      # 0xc614
cmpl $0x64, %ecx
setne %sil
andb %al, %sil
movslq %ebx, %rax
cmpb $0x1, %sil
movl %edi, 0xc(%rsp)
jne 0x6f73
movsd 0x525e(%rip), %xmm1     # 0xc160
leaq 0x17d0b27(%rip), %rsi   # 0x17d7a30
movsd (%rsi,%rax,8), %xmm0
mulsd %xmm1, %xmm0
leaq 0x184eb17(%rip), %rsi   # 0x1855a30
mulsd (%rsi,%rax,8), %xmm1
movapd %xmm1, %xmm2
mulsd %xmm1, %xmm2
movapd %xmm0, %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
mulsd 0x115e(%rip), %xmm3     # 0x8098
addsd 0x115e(%rip), %xmm3     # 0x80a0
movsd 0x5366(%rip), %xmm2     # 0xc2b0
mulsd %xmm2, %xmm0
movslq %r11d, %rsi
leaq 0x56d8(%rip), %rdi      # 0xc630
movsd (%rdi,%rsi,8), %xmm4
mulsd %xmm3, %xmm0
addsd %xmm4, %xmm0
mulsd %xmm2, %xmm1
mulsd %xmm3, %xmm1
addsd %xmm4, %xmm1
jmp 0x6fd7
cmpl $0x0, 0x5696(%rip)      # 0xc610
movslq %r11d, %rsi
movslq %edi, %rdi
leaq 0x17936a9(%rip), %r8    # 0x179a630
movsd (%r8,%rdi,8), %xmm0
mulsd %xmm7, %xmm0
leaq 0x5698(%rip), %r8       # 0xc630
addsd (%r8,%rsi,8), %xmm0
je 0x6fba
movslq %r10d, %r8
leaq 0x17b1686(%rip), %r9    # 0x17b8630
movsd (%r9,%r8,8), %xmm1
mulsd 0x50(%rsp), %xmm1
addsd %xmm1, %xmm0
leaq 0x177566f(%rip), %r8    # 0x177c630
movsd (%r8,%rdi,8), %xmm1
mulsd %xmm7, %xmm1
leaq 0xbbd65e(%rip), %rdi    # 0xbc4630
addsd (%rdi,%rsi,8), %xmm1
testl %edx, %edx
setne %dl
cmpl $0x64, %ecx
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
movq %rbx, 0x78(%rsp)
jne 0x706a
movsd 0x5167(%rip), %xmm3     # 0xc160
leaq 0x17d0a30(%rip), %rdx   # 0x17d7a30
movsd (%rdx,%rax,8), %xmm2
mulsd %xmm3, %xmm2
leaq 0x184ea20(%rip), %rdx   # 0x1855a30
mulsd (%rdx,%rax,8), %xmm3
movapd %xmm3, %xmm4
mulsd %xmm3, %xmm4
movapd %xmm2, %xmm5
mulsd %xmm2, %xmm5
addsd %xmm4, %xmm5
mulsd 0x1067(%rip), %xmm5     # 0x8098
addsd 0x1067(%rip), %xmm5     # 0x80a0
movsd 0x526f(%rip), %xmm4     # 0xc2b0
mulsd %xmm4, %xmm2
movslq %r11d, %rdx
leaq 0x55e1(%rip), %rsi      # 0xc630
movsd (%rsi,%rdx,8), %xmm6
mulsd %xmm5, %xmm2
addsd %xmm6, %xmm2
mulsd %xmm4, %xmm3
mulsd %xmm5, %xmm3
addsd %xmm6, %xmm3
jmp 0x70a7
cmpl $0x0, 0x559f(%rip)      # 0xc610
movslq %r11d, %rdx
leaq 0x55b5(%rip), %rsi      # 0xc630
movsd (%rsi,%rdx,8), %xmm2
leaq 0xbbd5a9(%rip), %rsi    # 0xbc4630
movsd (%rsi,%rdx,8), %xmm3
je 0x70a7
movslq %r10d, %rdx
leaq 0x17b1598(%rip), %rsi   # 0x17b8630
movsd (%rsi,%rdx,8), %xmm4
mulsd 0x48(%rsp), %xmm4
addsd %xmm4, %xmm3
xorl %r8d, %r8d
cmpl $0x3ee, %ecx            # imm = 0x3EE
sete %cl
cmpl $0x0, 0x50c6(%rip)      # 0xc180
jle 0x7246
movq %r11, 0x70(%rsp)
movl %r10d, 0x20(%rsp)
movsd 0xfee(%rip), %xmm4      # 0x80c0
mulsd %xmm4, %xmm1
cvttsd2si %xmm1, %edx
movl %edx, 0x10(%rsp)
mulsd %xmm4, %xmm0
cvttsd2si %xmm0, %edi
mulsd %xmm4, %xmm3
cvttsd2si %xmm3, %edx
movl %edx, 0x28(%rsp)
mulsd %xmm4, %xmm2
cvttsd2si %xmm2, %edx
movl %edx, 0x24(%rsp)
movb %cl, %r8b
leaq 0x1f28(%rip), %rcx      # 0x9030
movsd (%rcx,%r8,8), %xmm0
leaq 0x17d091b(%rip), %rcx   # 0x17d7a30
movsd (%rcx,%rax,8), %xmm1
mulsd %xmm0, %xmm1
leaq 0x184e90b(%rip), %rcx   # 0x1855a30
mulsd (%rcx,%rax,8), %xmm0
mulsd %xmm4, %xmm0
cvttsd2si %xmm0, %esi
mulsd %xmm4, %xmm1
cvttsd2si %xmm1, %r8d
leaq 0x514e(%rip), %r9       # 0xc290
xorl %ebx, %ebx
xorl %r10d, %r10d
movl (%r9), %eax
movl %edi, %r11d
movl 0x10(%rsp), %ecx
testl %eax, %eax
je 0x7168
movl 0x24(%rsp), %r11d
movl 0x28(%rsp), %ecx
cmpl $0x1, %eax
je 0x7168
xorl %r11d, %r11d
xorl %ecx, %ecx
movl 0x54a5(%rip), %r13d     # 0xc614
movl %r13d, %eax
subl $0x1, %eax
setb %dl
cmpl $0x6, %r13d
sete %r14b
orb %dl, %r14b
cmpl $0x0, 0x18cc8fe(%rip)   # 0x18d3a88
setne %r12b
cmpq $0x6, %rbx
sete %r15b
andb %r12b, %r15b
andb %r14b, %r15b
cmpl $0x2, %eax
setb %al
cmpl $0x64, %r13d
sete %dl
cmpl $0x3ee, %r13d           # imm = 0x3EE
sete %r14b
orb %dl, %r14b
orb %al, %r14b
cmpq $0x12, %rbx
sete %al
andb %r12b, %al
andb %r14b, %al
movl %r13d, %edx
andl $-0x2, %edx
cmpl $0x4, %edx
sete %dl
cmpl $0xa, %r13d
sete %r14b
orb %dl, %r14b
cmpq $0x18, %rbx
sete %dl
andb %r12b, %dl
andb %r14b, %dl
orb %al, %dl
orb %r15b, %dl
movl %r8d, %edx
movl %esi, %eax
jne 0x71fc
movl %r11d, %edx
movl %ecx, %eax
movl %edx, %ecx
shrl $0x10, %ecx
movb %cl, (%rbp,%rbx)
movb %dh, 0x1(%rbp,%rbx)
movb %dl, 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 %r10
movslq 0x4f58(%rip), %rax      # 0xc180
addq $0x6, %rbx
addq $0x4, %r9
cmpq %rax, %r10
jl 0x7147
addq %rbx, %rbp
movl 0x20(%rsp), %r10d
movq 0x70(%rsp), %r11
movq 0x78(%rsp), %rax
cmpl $0xfbff, %eax           # imm = 0xFBFF
leal 0x1(%rax), %eax
movl %eax, %ebx
movl $0x0, %eax
cmovgel %eax, %ebx
cmpl $0x176fff, %r11d        # imm = 0x176FFF
jl 0x729c
leaq 0x2c(%rsp), %rdi
movl %r10d, %r14d
callq 0x10b0
movsd 0x68(%rsp), %xmm7
movl %r14d, %r10d
movslq %eax, %r11
imulq $-0x447c854f, %r11, %rax # imm = 0xBB837AB1
shrq $0x20, %rax
addl %eax, %r11d
movl %r11d, %eax
shrl $0x1f, %eax
sarl $0xb, %r11d
addl %eax, %r11d
jmp 0x729f
incl %r11d
movl 0xc(%rsp), %edi
movl 0x8(%rsp), %edx
addq $0x2, %rbp
movl 0x1c(%rsp), %ecx
addl %ecx, %edi
cmpl $0x3c00, %edi           # imm = 0x3C00
movl $0x0, %eax
cmovgel %eax, %edi
addl %ecx, %r10d
cmpl $0x3e80, %r10d          # imm = 0x3E80
cmovgel %eax, %r10d
incl %edx
cmpl 0x58(%rsp), %edx
jne 0x6ece
movq 0x60(%rsp), %rcx
leaq 0x1(%rcx), %rax
testq %rcx, %rcx
movq %rax, %rcx
je 0x6ce2
movq %r11, %r15
movl %edi, %r14d
movl %r10d, %ebp
movq 0x40(%rsp), %rdi
addq 0x38(%rsp), %rdi
movq %rdi, 0x38(%rsp)
cmpq $0x3b9aca00, %rdi       # imm = 0x3B9ACA00
jl 0x736b
movl $0x773593ff, %eax       # imm = 0x773593FF
cmpq %rax, %rdi
movl $0x773593ff, %ecx       # imm = 0x773593FF
cmovlq %rdi, %rcx
movq 0x30(%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, 0x38(%rsp)
movq %rax, 0x30(%rsp)
incl 0x4(%rsp)
movl $0x1, %edi
movl $0x1, %esi
leaq 0x30(%rsp), %rdx
xorl %ecx, %ecx
callq 0x11b0
movl 0x4dcd(%rip), %edi      # 0xc158
testl %edi, %edi
js 0x73ce
movl $0x408, %edx            # imm = 0x408
leaq 0x80(%rsp), %rsi
xorl %ecx, %ecx
leaq 0x18cc6b7(%rip), %r8    # 0x18d3a5c
movl $0x10, %r9d
callq 0x10e0
testq %rax, %rax
jns 0x73f5
movl $0x1, %edi
leaq 0x2779(%rip), %rsi      # 0x9b3a
movl 0x4(%rsp), %edx
xorl %eax, %eax
callq 0x13aa
jmp 0x73f5
movl 0x18cc65c(%rip), %edi   # 0x18d3a30
movl $0x408, %edx            # imm = 0x408
leaq 0x80(%rsp), %rsi
xorl %ecx, %ecx
leaq 0x18cc672(%rip), %r8    # 0x18d3a5c
movl $0x10, %r9d
callq 0x10e0
cmpb $0x0, 0x18cc65c(%rip)   # 0x18d3a58
movl %ebp, %r10d
movl %r14d, %edi
movq %r15, %r11
movl (%rsp), %esi
jne 0x6c70
movb $0x0, 0x18cc61f(%rip)   # 0x18d3a34
xorl %eax, %eax
addq $0x488, %rsp            # imm = 0x488
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq