// File: /workspace/github_cpp_makefile_star2_O1/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:
cmpq $0x0, 0x77eed(%rip)     # 0x148818
je 0xd0b03
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
leaq 0x18(%rsp), %r15
leaq 0x212(%rip), %rbx       # 0xd0b5c
leaq 0x8(%rsp), %r14
leaq 0x7386a(%rip), %r12     # 0x1441c0
movq 0x77ebb(%rip), %rax     # 0x148818
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0xd0982
movl (%rax), %edi
movl $0x1, %edx
movq %r14, %rsi
callq 0x21dd0
testq %rax, %rax
je 0xd0982
movzbl 0x8(%rsp), %r13d
cmpl $-0x1, %r13d
je 0xd0ae3
movl 0x738fe(%rip), %eax     # 0x144290
testl %eax, %eax
setle %cl
movl %r13d, %edx
andl $-0x8, %edx
cmpl $0x30, %edx
setne %dl
testb %cl, %dl
jne 0xd09cd
cmpl $0x2, %eax
je 0xd0a7f
cmpl $0x1, %eax
je 0xd0a67
testl %eax, %eax
jne 0xd0956
addl $-0x30, %r13d
movl %r13d, 0x77e58(%rip)    # 0x148820
jmp 0xd0a72
cmpl $0x20, %r13d
jne 0xd0a4f
movb $0x1, 0xb1(%r12)
movl $0x0, 0x738aa(%rip)     # 0x144290
movq 0x77e2b(%rip), %rax     # 0x148818
movb $0x50, 0x8(%rsp)
testq %rax, %rax
je 0xd0a06
movl (%rax), %edi
movl $0x1, %edx
movq %r14, %rsi
callq 0x212f0
movq 0x77e0b(%rip), %rax     # 0x148818
movb $-0x1, 0x8(%rsp)
testq %rax, %rax
je 0xd0a26
movl (%rax), %edi
movl $0x1, %edx
movq %r14, %rsi
callq 0x212f0
movq 0x77deb(%rip), %rax     # 0x148818
movb $-0x1, 0x8(%rsp)
testq %rax, %rax
je 0xd0956
movl (%rax), %edi
movl $0x1, %edx
movq %r14, %rsi
callq 0x212f0
jmp 0xd0956
movq 0x77dc2(%rip), %rax     # 0x148818
movl (%rax), %edi
movl $0x2, %esi
callq 0x21ea0
jmp 0xd0956
shll $0x8, %r13d
movl %r13d, 0x77db2(%rip)    # 0x148824
incl %eax
movl %eax, 0x73816(%rip)     # 0x144290
jmp 0xd0956
orl 0x77d9e(%rip), %r13d    # 0x148824
leal -0x10000(%r13), %eax
testw %r13w, %r13w
cmovnsl %r13d, %eax
movl %eax, 0x77d89(%rip)     # 0x148824
movl 0x77d7f(%rip), %ecx     # 0x148820
incl %ecx
imull $0x168, %eax, %eax      # imm = 0x168
leal 0xff(%rax), %edx
testl %eax, %eax
cmovnsl %eax, %edx
sarl $0x8, %edx
movl %ecx, 0x18(%rsp)
movl %edx, 0x1c(%rsp)
movb $0x0, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd4ba5
movl $0x0, 0x737b2(%rip)     # 0x144290
jmp 0xd0956
leaq -0x1c7(%rip), %rsi      # 0xd0923
movl $0x2, %edi
xorl %edx, %edx
callq 0xcec6d
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq