#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ USBNDebug(char *);
unsigned char USBNRead(int);
int /*<<< orphan*/ USBNWrite(int, int);
void _USBNAlternateEvent(void) {
  unsigned char event;
  event = USBNRead(0x08);
  USBNDebug("alt event\r\n");
  if (event & 0x40) {
    USBNWrite(0x05, 0x00);
    USBNWrite(0x04, 0x80 + 0);
    USBNWrite(0x20, 0x00);
    USBNWrite(0x23, 0x08);
    USBNWrite(0x27, 0x01);
    USBNWrite(0x05, 0x02);
    USBNDebug("reset\r\n");
  }
  if (event & 0x10) {
    USBNWrite(0x09, 0x80 + 0x40);
  }
  if (event & 0x80) {
    USBNWrite(0x09, 0x10 + 0x40 + 0x80);
  }
  if (event & 0x08) {
    USBNDebug("eop\r\n");
  }
}


x86 assembly (clang, -O0):
<_USBNAlternateEvent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x8,%edi
call   1030 <USBNRead@plt>
mov    %al,-0x1(%rbp)
lea    0xeb4(%rip),%rdi
call   1050 <USBNDebug@plt>
movzbl -0x1(%rbp),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     11c1 <_USBNAlternateEvent+0x91>
mov    $0x5,%edi
xor    %esi,%esi
call   1040 <USBNWrite@plt>
mov    $0x4,%edi
mov    $0x80,%esi
call   1040 <USBNWrite@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1040 <USBNWrite@plt>
mov    $0x23,%edi
mov    $0x8,%esi
call   1040 <USBNWrite@plt>
mov    $0x27,%edi
mov    $0x1,%esi
call   1040 <USBNWrite@plt>
mov    $0x5,%edi
mov    $0x2,%esi
call   1040 <USBNWrite@plt>
lea    0xe50(%rip),%rdi
call   1050 <USBNDebug@plt>
movzbl -0x1(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     11e0 <_USBNAlternateEvent+0xb0>
mov    $0x9,%edi
mov    $0xc0,%esi
call   1040 <USBNWrite@plt>
movzbl -0x1(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1201 <_USBNAlternateEvent+0xd1>
mov    $0x9,%edi
mov    $0xd0,%esi
call   1040 <USBNWrite@plt>
movzbl -0x1(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     121d <_USBNAlternateEvent+0xed>
lea    0xdfc(%rip),%rdi
call   1050 <USBNDebug@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_USBNAlternateEvent>:
push   %rbx
mov    $0x8,%edi
call   1030 <USBNRead@plt>
mov    %eax,%ebx
lea    0xebc(%rip),%rdi
call   1050 <USBNDebug@plt>
test   $0x40,%bl
jne    1167 <_USBNAlternateEvent+0x37>
test   $0x10,%bl
jne    11cc <_USBNAlternateEvent+0x9c>
test   $0x80,%bl
jne    11e4 <_USBNAlternateEvent+0xb4>
test   $0x8,%bl
jne    11fc <_USBNAlternateEvent+0xcc>
pop    %rbx
ret
mov    $0x5,%edi
xor    %esi,%esi
call   1040 <USBNWrite@plt>
mov    $0x4,%edi
mov    $0x80,%esi
call   1040 <USBNWrite@plt>
mov    $0x20,%edi
xor    %esi,%esi
call   1040 <USBNWrite@plt>
mov    $0x23,%edi
mov    $0x8,%esi
call   1040 <USBNWrite@plt>
mov    $0x27,%edi
mov    $0x1,%esi
call   1040 <USBNWrite@plt>
mov    $0x5,%edi
mov    $0x2,%esi
call   1040 <USBNWrite@plt>
lea    0xe4a(%rip),%rdi
call   1050 <USBNDebug@plt>
test   $0x10,%bl
je     1153 <_USBNAlternateEvent+0x23>
mov    $0x9,%edi
mov    $0xc0,%esi
call   1040 <USBNWrite@plt>
test   $0x80,%bl
je     115c <_USBNAlternateEvent+0x2c>
mov    $0x9,%edi
mov    $0xd0,%esi
call   1040 <USBNWrite@plt>
test   $0x8,%bl
je     1165 <_USBNAlternateEvent+0x35>
lea    0xe11(%rip),%rdi
pop    %rbx
jmp    1050 <USBNDebug@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"alt event\0D\0A\00"
@.str.1 = [8 x i8] c"reset\0D\0A\00"
@.str.2 = [6 x i8] c"eop\0D\0A\00"
define void @_USBNAlternateEvent() {
%1 = alloca i8
%2 = call zeroext i8 @USBNRead(i32 8)
store i8 %2, i8* %1
%3 = call i32 @USBNDebug(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = load i8, i8* %1
%5 = zext i8 %4 to i32
%6 = and i32 %5, 64
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %0
%9 = call i32 @USBNWrite(i32 5, i32 0)
%10 = call i32 @USBNWrite(i32 4, i32 128)
%11 = call i32 @USBNWrite(i32 32, i32 0)
%12 = call i32 @USBNWrite(i32 35, i32 8)
%13 = call i32 @USBNWrite(i32 39, i32 1)
%14 = call i32 @USBNWrite(i32 5, i32 2)
%15 = call i32 @USBNDebug(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %8, %0
%17 = load i8, i8* %1
%18 = zext i8 %17 to i32
%19 = and i32 %18, 16
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @USBNWrite(i32 9, i32 192)
br label %23
23: ; preds = %21, %16
%24 = load i8, i8* %1
%25 = zext i8 %24 to i32
%26 = and i32 %25, 128
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @USBNWrite(i32 9, i32 208)
br label %30
30: ; preds = %28, %23
%31 = load i8, i8* %1
%32 = zext i8 %31 to i32
%33 = and i32 %32, 8
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @USBNDebug(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %30
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"alt event\0D\0A\00"
@.str.1 = [8 x i8] c"reset\0D\0A\00"
@.str.2 = [6 x i8] c"eop\0D\0A\00"
define void @_USBNAlternateEvent() {
%1 = tail call zeroext i8 @USBNRead(i32 8)
%2 = tail call i32 @USBNDebug(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%3 = zext i8 %1 to i32
%4 = and i32 %3, 64
%5 = icmp eq i32 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %0
%7 = tail call i32 @USBNWrite(i32 5, i32 0)
%8 = tail call i32 @USBNWrite(i32 4, i32 128)
%9 = tail call i32 @USBNWrite(i32 32, i32 0)
%10 = tail call i32 @USBNWrite(i32 35, i32 8)
%11 = tail call i32 @USBNWrite(i32 39, i32 1)
%12 = tail call i32 @USBNWrite(i32 5, i32 2)
%13 = tail call i32 @USBNDebug(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %6, %0
%15 = and i32 %3, 16
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @USBNWrite(i32 9, i32 192)
br label %19
19: ; preds = %17, %14
%20 = and i32 %3, 128
%21 = icmp eq i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i32 @USBNWrite(i32 9, i32 208)
br label %24
24: ; preds = %22, %19
%25 = and i32 %3, 8
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = tail call i32 @USBNDebug(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %24
ret void
}