#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 read_port(int, unsigned char *, int);
int /*<<< orphan*/ setBaud(int, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write_port(int, unsigned char *, int);
int OW_detectKey(int fd) {
  int bytesRead;
  unsigned char out;
  unsigned char inBuf[64];
  setBaud(fd, 9600);
  out = 0xF0;
  write_port(fd, &out, 1);
  usleep(1000 * 10);
  bytesRead = read_port(fd, inBuf, 64);
  if (bytesRead == 1) {
    if (inBuf[0] == 0xe0) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<OW_detectKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x2580,%esi
call   1050 <setBaud@plt>
movb   $0xf0,-0xd(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write_port@plt>
mov    $0x2710,%edi
call   1060 <usleep@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
call   1030 <read_port@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    11b5 <OW_detectKey+0x75>
movzbl -0x50(%rbp),%eax
cmp    $0xe0,%eax
jne    11b0 <OW_detectKey+0x70>
movl   $0x1,-0x4(%rbp)
jmp    11bc <OW_detectKey+0x7c>
jmp    11b5 <OW_detectKey+0x75>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OW_detectKey>:
push   %rbx
sub    $0x50,%rsp
mov    %edi,%ebx
mov    $0x2580,%esi
call   1050 <setBaud@plt>
movb   $0xf0,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <write_port@plt>
mov    $0x2710,%edi
call   1060 <usleep@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x40,%edx
call   1030 <read_port@plt>
cmp    $0x1,%eax
sete   %al
cmpb   $0xe0,0x10(%rsp)
sete   %cl
and    %al,%cl
movzbl %cl,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @OW_detectKey(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca [64 x i8]
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = call i32 @setBaud(i32 %7, i32 9600)
store i8 -16, i8* %5
%9 = load i32, i32* %3
%10 = call i32 @write_port(i32 %9, i8* %5, i32 1)
%11 = call i32 @usleep(i32 10000)
%12 = load i32, i32* %3
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%14 = call i32 @read_port(i32 %12, i8* %13, i32 64)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %24
17: ; preds = %1
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = icmp eq i32 %20, 224
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 1, i32* %2
br label %25
23: ; preds = %17
br label %24
24: ; preds = %23, %1
store i32 0, i32* %2
br label %25
25: ; preds = %24, %22
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @OW_detectKey(i32 %0) {
%2 = alloca i8
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @setBaud(i32 %0, i32 9600)
store i8 -16, i8* %2
%6 = call i32 @write_port(i32 %0, i8* %2, i32 1)
%7 = call i32 @usleep(i32 10000)
%8 = call i32 @read_port(i32 %0, i8* %4, i32 64)
%9 = icmp eq i32 %8, 1
%10 = load i8, i8* %4
%11 = icmp eq i8 %10, -32
%12 = select i1 %9, i1 %11, i1 false
%13 = zext i1 %12 to i32
ret i32 %13
}