// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/fglut/freeglut_input_devices.c
// Function: poll_dials
static void poll_dials ( int id )
{
    int data;
    static int dial_state = DIAL_NEW;
    static int dial_which;
    static int dial_value;
    // static int dials[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };

    if ( !dialbox_port ) return;

    while ( (data=serial_getchar(dialbox_port)) != EOF )
    {
        if ( ( dial_state > DIAL_WHICH_DEVICE ) || IS_DIAL_EVENT ( data ) )
        {
            switch ( dial_state )
            {
            case DIAL_WHICH_DEVICE:
                dial_which = data - DIAL_BASE;
                dial_state++;
                break;
            case DIAL_VALUE_HIGH:
                dial_value = ( data << 8 );
                dial_state++;
                break;
            case DIAL_VALUE_LOW:
                dial_value |= data;
                if ( dial_value & 0x8000 ) dial_value -= 0x10000;
                // dials[dial_which] = dial_value;
                send_dial_event ( dial_which + 1, dial_value * 360 / 256 );
                dial_state = DIAL_WHICH_DEVICE;
                break;
            default:
                /* error: Impossible state value! */
                break;
            }
        }
        else if ( data == DIAL_INITIALIZED )
        {
            fgState.InputDevsInitialised = GL_TRUE;
            dial_state = DIAL_WHICH_DEVICE;
            serial_putchar(dialbox_port,DIAL_SET_AUTO_DIALS);
            serial_putchar(dialbox_port,0xff);
            serial_putchar(dialbox_port,0xff);
        }
        else  /* Unknown data; try flushing. */
            serial_flush(dialbox_port);
    }

    glutTimerFunc ( 2, poll_dials, 0 );
}

// Assembly:
movq 0x77dc4(%rip), %rax     # 0x146818
testq %rax, %rax
je 0xcec26
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsp, %rbx
leaq 0x10(%rsp), %r15
leaq 0x208(%rip), %r14       # 0xcec7f
leaq 0x73742(%rip), %r12     # 0x1421c0
movl (%rax), %edi
movl $0x1, %edx
movq %rbx, %rsi
callq 0x21dc0
testq %rax, %rax
je 0xcec08
movzbl (%rsp), %eax
movl 0x737f0(%rip), %ecx     # 0x142290
testl %ecx, %ecx
setle %dl
movl %eax, %esi
andl $-0x8, %esi
cmpl $0x30, %esi
setne %sil
testb %sil, %dl
jne 0xceae8
cmpl $0x2, %ecx
je 0xceb9c
cmpl $0x1, %ecx
je 0xceb87
testl %ecx, %ecx
jne 0xcebf8
addl $-0x30, %eax
movl %eax, 0x77d47(%rip)     # 0x146820
movl $0x1, 0x737ad(%rip)     # 0x142290
jmp 0xcebf8
cmpl $0x20, %eax
jne 0xceb72
movb $0x1, 0xb1(%r12)
movl $0x0, 0x7378c(%rip)     # 0x142290
movq 0x77d0d(%rip), %rax     # 0x146818
movb $0x50, (%rsp)
testq %rax, %rax
je 0xcebf8
movl (%rax), %edi
movl $0x1, %edx
movq %rbx, %rsi
callq 0x212f0
movq 0x77cea(%rip), %rax     # 0x146818
movb $-0x1, (%rsp)
testq %rax, %rax
je 0xcebf8
movl (%rax), %edi
movl $0x1, %edx
movq %rbx, %rsi
callq 0x212f0
movq 0x77cc7(%rip), %rax     # 0x146818
movb $-0x1, (%rsp)
testq %rax, %rax
je 0xcebf8
movl (%rax), %edi
movl $0x1, %edx
movq %rbx, %rsi
callq 0x212f0
jmp 0xcebf8
movq 0x77c9f(%rip), %rax     # 0x146818
movl (%rax), %edi
movl $0x2, %esi
callq 0x21e90
jmp 0xcebf8
shll $0x8, %eax
movl %eax, 0x77c94(%rip)     # 0x146824
movl $0x2, 0x736f6(%rip)     # 0x142290
jmp 0xcebf8
movl 0x77c82(%rip), %ecx     # 0x146824
orl %ecx, %eax
leal -0x10000(%rax), %edx
testw %cx, %cx
cmovnsl %eax, %edx
movl %edx, 0x77c6e(%rip)     # 0x146824
movl 0x77c64(%rip), %eax     # 0x146820
incl %eax
imull $0x168, %edx, %ecx      # imm = 0x168
leal 0xff(%rcx), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
sarl $0x8, %edx
movl %eax, 0x10(%rsp)
movl %edx, 0x14(%rsp)
movb $0x0, (%rsp)
movq %r15, 0x8(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0xd2cb3
movl $0x0, 0x73698(%rip)     # 0x142290
movq 0x77c19(%rip), %rax     # 0x146818
testq %rax, %rax
jne 0xcea7e
leaq -0x1c2(%rip), %rsi      # 0xcea4d
movl $0x2, %edi
xorl %edx, %edx
callq 0xccde9
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq