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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned long);
int /*<<< orphan*/ read(int, unsigned long *, int);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  unsigned long key1_5 = 0;
  int key_fd = open("/dev/key_driver", O_RDWR);
  while (1) {
    read(key_fd, &key1_5, sizeof(key1_5));
    if (key1_5 != 0) {
      printf("you press the key%d\n", key1_5);
    } else {
      ;
    }
    usleep(200 * 1000);
  }
  close(key_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
lea    0xe92(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read@plt>
cmpq   $0x0,-0x18(%rbp)
je     11a7 <main+0x67>
mov    -0x18(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
jmp    11ac <main+0x6c>
jmp    11ac <main+0x6c>
mov    $0x30d40,%edi
call   1060 <usleep@plt>
jmp    1176 <main+0x36>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
lea    0xe9e(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
lea    0xe9b(%rip),%r15
jmp    118a <main+0x4a>
nopw   0x0(%rax,%rax,1)
mov    $0x30d40,%edi
call   1060 <usleep@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    0x8(%rsp),%rsi
test   %rsi,%rsi
je     1180 <main+0x40>
mov    %r15,%rdi
call   1030 <printf@plt>
jmp    1180 <main+0x40>

LLVM IR (-O0):
@.str = [16 x i8] c"/dev/key_driver\00"
@O_RDWR = global i32 0
@.str.1 = [21 x i8] c"you press the key%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %7
br label %10
10: ; preds = %2, %19
%11 = load i32, i32* %7
%12 = call i32 @read(i32 %11, i64* %6, i32 8)
%13 = load i64, i64* %6
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i64, i64* %6
%17 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %16)
br label %19
18: ; preds = %10
br label %19
19: ; preds = %18, %15
%20 = call i32 @usleep(i32 200000)
br label %10
}

LLVM IR (-O2):
@.str = [16 x i8] c"/dev/key_driver\00"
@O_RDWR = global i32 0
@.str.1 = [21 x i8] c"you press the key%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %7
7: ; preds = %13, %2
%8 = call i32 @read(i32 %6, i64* %3, i32 8)
%9 = load i64, i64* %3
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %9)
br label %13
13: ; preds = %7, %11
%14 = tail call i32 @usleep(i32 200000)
br label %7
}