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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned char);
int /*<<< orphan*/ read(int, unsigned char *, int);
int main() {
  char *devname = "/dev/key1_eint";
  int fd;
  unsigned char key;
  fd = open(devname, O_RDWR);
  while (1) {
    read(fd, &key, sizeof(key));
    if (key)
      printf("the key = %d\n", key);
    key = 0;
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmpb   $0x0,-0x15(%rbp)
je     118a <main+0x5a>
lea    0xe8e(%rip),%rdi
movzbl -0x15(%rbp),%esi
call   1030 <printf@plt>
movb   $0x0,-0x15(%rbp)
jmp    115f <main+0x2f>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
lea    0xeb7(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
lea    0xf(%rsp),%r14
lea    0xeb3(%rip),%r15
jmp    1165 <main+0x35>
xchg   %ax,%ax
movb   $0x0,0xf(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
movzbl 0xf(%rsp),%eax
test   %al,%al
je     1160 <main+0x30>
movzbl %al,%esi
mov    %r15,%rdi
call   1030 <printf@plt>
jmp    1160 <main+0x30>

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

LLVM IR (-O2):
@.str = [15 x i8] c"/dev/key1_eint\00"
@O_RDWR = global i32 0
@.str.1 = [14 x i8] c"the key = %d\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %4
4: ; preds = %10, %0
%5 = call i32 @read(i32 %3, i8* %1, i32 1)
%6 = load i8, i8* %1
%7 = icmp eq i8 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %6)
br label %10
10: ; preds = %8, %4
store i8 0, i8* %1
br label %4
}