// File: /workspace/github_cpp_makefile_star2_O2/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 0x7dc9b(%rip), %rax     # 0x137838
testq %rax, %rax
je 0xb9d27
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x8(%rsp), %rbx
pushq $0x1
popq %r14
movq %rsp, %r13
leaq 0x1c0(%rip), %r15       # 0xb9d87
leaq 0x79612(%rip), %r12     # 0x1331e0
pushq $0x50
popq %rbp
testq %rax, %rax
je 0xb9d08
movl (%rax), %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x21de0
testq %rax, %rax
je 0xb9d08
movzbl 0x8(%rsp), %eax
movl 0x796b5(%rip), %ecx     # 0x1332b0
testl %ecx, %ecx
setle %dl
movl %eax, %esi
andl $-0x8, %esi
cmpl $0x30, %esi
setne %sil
testb %sil, %dl
jne 0xb9c3f
cmpl $0x2, %ecx
je 0xb9ca9
cmpl $0x1, %ecx
je 0xb9c94
testl %ecx, %ecx
jne 0xb9cfc
addl $-0x30, %eax
movl %eax, 0x7dc10(%rip)     # 0x137840
movl $0x1, 0x79676(%rip)     # 0x1332b0
jmp 0xb9cfc
cmpl $0x20, %eax
jne 0xb9c86
movb $0x1, 0xb1(%r12)
andl $0x0, 0x7965c(%rip)     # 0x1332b0
movq 0x7dbdd(%rip), %rdi     # 0x137838
movl %ebp, %esi
callq 0xb9b7a
movq 0x7dbcf(%rip), %rdi     # 0x137838
movl $0xff, %esi
callq 0xb9b7a
movq 0x7dbbe(%rip), %rdi     # 0x137838
movl $0xff, %esi
callq 0xb9b7a
jmp 0xb9cfc
movq 0x7dbab(%rip), %rdi     # 0x137838
callq 0xb9d7d
jmp 0xb9cfc
shll $0x8, %eax
movl %eax, 0x7dba7(%rip)     # 0x137844
movl $0x2, 0x79609(%rip)     # 0x1332b0
jmp 0xb9cfc
movl 0x7db95(%rip), %ecx     # 0x137844
orl %ecx, %eax
leal -0x10000(%rax), %edx
testw %cx, %cx
cmovnsl %eax, %edx
movl %edx, 0x7db81(%rip)     # 0x137844
movl 0x7db77(%rip), %ecx     # 0x137840
incl %ecx
imull $0x168, %edx, %eax      # imm = 0x168
cltd
movl $0x100, %esi            # imm = 0x100
idivl %esi
movl %ecx, (%rsp)
movl %eax, 0x4(%rsp)
movb $0x0, 0x8(%rsp)
movq %r13, 0x10(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0xbd9c1
andl $0x0, 0x795b4(%rip)     # 0x1332b0
movq 0x7db35(%rip), %rax     # 0x137838
jmp 0xb9bd1
leaq -0x179(%rip), %rsi      # 0xb9b96
pushq $0x2
popq %rdi
xorl %edx, %edx
callq 0xb7fe9
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq