#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int get_raw_event(int fd, int *touchp, int *xp, int *yp) {
  unsigned char buf[32];
  if (read(fd, buf, sizeof(buf)) < 22)
    return (0);
  if (buf[0] != 170 || buf[6] != 187) {
    fprintf(stderr, "Bad framing from hidraw!\n");
    return (0);
  }
  *touchp = buf[1];
  *xp = (buf[2] << 8) + buf[3];
  *yp = (buf[4] << 8) + buf[5];
  return (1);
}


x86 assembly (clang, -O0):
<get_raw_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1030 <read@plt>
cmp    $0x16,%eax
jge    115d <get_raw_event+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <get_raw_event+0xb3>
movzbl -0x40(%rbp),%eax
cmp    $0xaa,%eax
jne    117b <get_raw_event+0x5b>
movzbl -0x3a(%rbp),%eax
cmp    $0xbb,%eax
je     119c <get_raw_event+0x7c>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <get_raw_event+0xb3>
movzbl -0x3f(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x3e(%rbp),%ecx
shl    $0x8,%ecx
movzbl -0x3d(%rbp),%eax
add    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movzbl -0x3c(%rbp),%ecx
shl    $0x8,%ecx
movzbl -0x3b(%rbp),%eax
add    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_raw_event>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rsp,%rsi
mov    $0x20,%edx
call   1030 <read@plt>
xor    %ebp,%ebp
cmp    $0x16,%eax
jl     1191 <get_raw_event+0x71>
cmpb   $0xaa,(%rsp)
jne    117c <get_raw_event+0x5c>
cmpb   $0xbb,0x6(%rsp)
jne    117c <get_raw_event+0x5c>
movzbl 0x1(%rsp),%eax
mov    %eax,(%rbx)
movzwl 0x2(%rsp),%eax
shl    $0x10,%eax
bswap  %eax
mov    %eax,(%r15)
movzwl 0x4(%rsp),%eax
shl    $0x10,%eax
bswap  %eax
mov    %eax,(%r14)
mov    $0x1,%ebp
jmp    1191 <get_raw_event+0x71>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1040 <fprintf@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Bad framing from hidraw!\0A\00"
define i32 @get_raw_event(i32 %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [32 x i8]
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%11 = load i32, i32* %6
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 32)
%14 = icmp slt i32 %13, 22
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 0, i32* %5
br label %52
16: ; preds = %4
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = icmp ne i32 %19, 170
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 6
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = icmp ne i32 %24, 187
br i1 %25, label %26, label %29
26: ; preds = %21, %16
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %52
29: ; preds = %21
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 1
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = load i32*, i32** %7
store i32 %32, i32* %33
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 2
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = shl i32 %36, 8
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 3
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = add nsw i32 %37, %40
%42 = load i32*, i32** %8
store i32 %41, i32* %42
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 4
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = shl i32 %45, 8
%47 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 5
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = add nsw i32 %46, %49
%51 = load i32*, i32** %9
store i32 %50, i32* %51
store i32 1, i32* %5
br label %52
52: ; preds = %29, %26, %15
%53 = load i32, i32* %5
ret i32 %53
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Bad framing from hidraw!\0A\00"
define i32 @get_raw_event(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%7 = call i32 @read(i32 %0, i8* %6, i32 32)
%8 = icmp slt i32 %7, 22
br i1 %8, label %39, label %9
9: ; preds = %4
%10 = load i8, i8* %6
%11 = icmp ne i8 %10, -86
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 6
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, -69
%15 = select i1 %11, i1 true, i1 %14
br i1 %15, label %16, label %19
16: ; preds = %9
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %39
19: ; preds = %9
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 1
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
store i32 %22, i32* %1
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 2
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = shl nuw nsw i32 %25, 8
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 3
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = or i32 %26, %29
store i32 %30, i32* %2
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 4
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = shl nuw nsw i32 %33, 8
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 5
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = or i32 %34, %37
store i32 %38, i32* %3
br label %39
39: ; preds = %4, %19, %16
%40 = phi i32 [ 0, %16 ], [ 1, %19 ], [ 0, %4 ]
ret i32 %40
}