#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*/ mini_printf(char *, int);
int /*<<< orphan*/ read(int, char *, int);
int gpm2_decode_ps2(int fd) {
  char data[3];
  data[0] = 0;
  data[1] = 0;
  data[2] = 0;
  read(fd, data, 3);
  if (data[0] & 0x01)
    mini_printf("left!\n", 1);
  if (data[0] & 0x02)
    mini_printf("right!\n", 1);
  if (data[0] & 0x04)
    mini_printf("middle!\n", 1);
  return 1;
}


x86 assembly (clang, -O0):
<gpm2_decode_ps2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x0,-0x7(%rbp)
movb   $0x0,-0x6(%rbp)
movb   $0x0,-0x5(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x7(%rbp),%rsi
mov    $0x3,%edx
call   1040 <read@plt>
movsbl -0x7(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1169 <gpm2_decode_ps2+0x49>
lea    0xea1(%rip),%rdi
mov    $0x1,%esi
call   1030 <mini_printf@plt>
movsbl -0x7(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     118a <gpm2_decode_ps2+0x6a>
lea    0xe87(%rip),%rdi
mov    $0x1,%esi
call   1030 <mini_printf@plt>
movsbl -0x7(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11ab <gpm2_decode_ps2+0x8b>
lea    0xe6e(%rip),%rdi
mov    $0x1,%esi
call   1030 <mini_printf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpm2_decode_ps2>:
push   %rbx
sub    $0x10,%rsp
movw   $0x0,0xd(%rsp)
movb   $0x0,0xf(%rsp)
lea    0xd(%rsp),%rsi
mov    $0x3,%edx
call   1040 <read@plt>
mov    0xd(%rsp),%bl
test   $0x1,%bl
jne    116f <gpm2_decode_ps2+0x4f>
test   $0x2,%bl
jne    1185 <gpm2_decode_ps2+0x65>
test   $0x4,%bl
je     1164 <gpm2_decode_ps2+0x44>
lea    0xeb5(%rip),%rdi
mov    $0x1,%esi
call   1030 <mini_printf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe8a(%rip),%rdi
mov    $0x1,%esi
call   1030 <mini_printf@plt>
test   $0x2,%bl
je     114e <gpm2_decode_ps2+0x2e>
lea    0xe7b(%rip),%rdi
mov    $0x1,%esi
call   1030 <mini_printf@plt>
test   $0x4,%bl
jne    1153 <gpm2_decode_ps2+0x33>
jmp    1164 <gpm2_decode_ps2+0x44>

LLVM IR (-O0):
@.str = [7 x i8] c"left!\0A\00"
@.str.1 = [8 x i8] c"right!\0A\00"
@.str.2 = [9 x i8] c"middle!\0A\00"
define i32 @gpm2_decode_ps2(i32 %0) {
%2 = alloca i32
%3 = alloca [3 x i8]
store i32 %0, i32* %2
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
store i8 0, i8* %4
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
store i8 0, i8* %5
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 0, i8* %6
%7 = load i32, i32* %2
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 3)
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = and i32 %12, 1
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @mini_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 1)
br label %17
17: ; preds = %15, %1
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = and i32 %20, 2
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @mini_printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %25
25: ; preds = %23, %17
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = and i32 %28, 4
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 @mini_printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %33
33: ; preds = %31, %25
ret i32 1
}

LLVM IR (-O2):
@.str = [7 x i8] c"left!\0A\00"
@.str.1 = [8 x i8] c"right!\0A\00"
@.str.2 = [9 x i8] c"middle!\0A\00"
define i32 @gpm2_decode_ps2(i32 %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
store i8 0, i8* %3
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
store i8 0, i8* %4
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
store i8 0, i8* %5
%6 = call i32 @read(i32 %0, i8* %3, i32 3)
%7 = load i8, i8* %3
%8 = and i8 %7, 1
%9 = icmp eq i8 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = tail call i32 @mini_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 1)
br label %12
12: ; preds = %10, %1
%13 = and i8 %7, 2
%14 = icmp eq i8 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @mini_printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %17
17: ; preds = %15, %12
%18 = and i8 %7, 4
%19 = icmp eq i8 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @mini_printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %22
22: ; preds = %20, %17
ret i32 1
}