#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*/ read_key;

/* Variables and functions */
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ key_led_ctl(int);
int open_dev(char *);
int /*<<< orphan*/ perror(char *);
int read(int, int *, int);
int key_deal() {
  int fd_dev = 0;
  fd_dev = open_dev("/dev/key4+5");
  int read_key = 0;
  int ret_read = -1;
  ret_read = read(fd_dev, &read_key, sizeof(read_key));
  if (ret_read < 0) {
    perror("read");
    _exit(0);
  }
  if (read_key == 2) {
    key_led_ctl(1);
  } else if (read_key == 4) {
    key_led_ctl(2);
  } else if (read_key == 5) {
    key_led_ctl(3);
  } else if (read_key == 6) {
    key_led_ctl(4);
  } else if (read_key == 3) {
    return read_key;
  } else {
    ;
  }
  close(fd_dev);
  return read_key;
}


x86 assembly (clang, -O0):
<key_deal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
lea    0xe8a(%rip),%rdi
call   1040 <open_dev@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11bd <key_deal+0x5d>
lea    0xe5b(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
cmpl   $0x2,-0xc(%rbp)
jne    11d6 <key_deal+0x76>
mov    $0x1,%edi
call   1080 <key_led_ctl@plt>
jmp    124f <key_deal+0xef>
cmpl   $0x4,-0xc(%rbp)
jne    11ef <key_deal+0x8f>
mov    $0x2,%edi
call   1080 <key_led_ctl@plt>
jmp    124a <key_deal+0xea>
cmpl   $0x5,-0xc(%rbp)
jne    1208 <key_deal+0xa8>
mov    $0x3,%edi
call   1080 <key_led_ctl@plt>
jmp    1245 <key_deal+0xe5>
cmpl   $0x6,-0xc(%rbp)
jne    1221 <key_deal+0xc1>
mov    $0x4,%edi
call   1080 <key_led_ctl@plt>
jmp    1240 <key_deal+0xe0>
cmpl   $0x3,-0xc(%rbp)
jne    1236 <key_deal+0xd6>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125d <key_deal+0xfd>
jmp    123b <key_deal+0xdb>
jmp    1240 <key_deal+0xe0>
jmp    1245 <key_deal+0xe5>
jmp    124a <key_deal+0xea>
jmp    124f <key_deal+0xef>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<key_deal>:
push   %rbp
push   %rbx
push   %rax
lea    0xeaa(%rip),%rdi
call   1040 <open_dev@plt>
mov    %eax,%ebp
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1060 <read@plt>
test   %eax,%eax
js     11d7 <key_deal+0x77>
mov    0x4(%rsp),%ebx
lea    -0x2(%rbx),%eax
cmp    $0x4,%eax
ja     11c7 <key_deal+0x67>
mov    $0x1,%edi
lea    0xe5a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x2,%edi
jmp    11c2 <key_deal+0x62>
mov    $0x4,%edi
jmp    11c2 <key_deal+0x62>
mov    $0x3,%edi
call   1080 <key_led_ctl@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe42(%rip),%rdi
call   1070 <perror@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/key4+5\00"
@.str.1 = [5 x i8] c"read\00"
define i32 @key_deal() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %2
%5 = call i32 @open_dev(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %5, i32* %2
store i32 0, i32* %3
store i32 -1, i32* %4
%6 = load i32, i32* %2
%7 = call i32 @read(i32 %6, i32* %3, i32 4)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @_exit(i32 0)
unreachable
13: ; preds = %0
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @key_led_ctl(i32 1)
br label %43
18: ; preds = %13
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 4
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @key_led_ctl(i32 2)
br label %42
23: ; preds = %18
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 5
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @key_led_ctl(i32 3)
br label %41
28: ; preds = %23
%29 = load i32, i32* %3
%30 = icmp eq i32 %29, 6
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @key_led_ctl(i32 4)
br label %40
33: ; preds = %28
%34 = load i32, i32* %3
%35 = icmp eq i32 %34, 3
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = load i32, i32* %3
store i32 %37, i32* %1
br label %47
38: ; preds = %33
br label %39
39: ; preds = %38
br label %40
40: ; preds = %39, %31
br label %41
41: ; preds = %40, %26
br label %42
42: ; preds = %41, %21
br label %43
43: ; preds = %42, %16
%44 = load i32, i32* %2
%45 = call i32 @close(i32 %44)
%46 = load i32, i32* %3
store i32 %46, i32* %1
br label %47
47: ; preds = %43, %36
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/key4+5\00"
@.str.1 = [5 x i8] c"read\00"
define i32 @key_deal() {
%1 = alloca i32
%2 = tail call i32 @open_dev(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = call i32 @read(i32 %2, i32* %1, i32 4)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @_exit(i32 0)
unreachable
9: ; preds = %0
%10 = load i32, i32* %1
switch i32 %10, label %17 [
i32 2, label %14
i32 4, label %11
i32 5, label %12
i32 6, label %13
i32 3, label %19
]
11: ; preds = %9
br label %14
12: ; preds = %9
br label %14
13: ; preds = %9
br label %14
14: ; preds = %9, %12, %13, %11
%15 = phi i32 [ 2, %11 ], [ 4, %13 ], [ 3, %12 ], [ 1, %9 ]
%16 = tail call i32 @key_led_ctl(i32 %15)
br label %17
17: ; preds = %14, %9
%18 = tail call i32 @close(i32 %2)
br label %19
19: ; preds = %9, %17
ret i32 %10
}