#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 */
struct pollfd {
  int fd;
  int revents;
  int events;
};
struct input_event {
  int type;
  int code;
  int value;
};
typedef int /*<<< orphan*/ ie;

/* Variables and functions */
#define BTN_0 131
#define BTN_1 130
#define BTN_2 129
#define BTN_3 128
int EV_KEY;
void *EV_LED;
int EV_SND;
int LED_MISC;
int LED_MUTE;
int LED_SUSPEND;
int O_NONBLOCK;
int O_RDWR;
int POLLERR;
int POLLIN;
int SND_BELL;
int atoi(char *);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, struct input_event *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ write(int, struct input_event *, int);
int main(int argc, char *argv[]) {
  int ret;
  char f_name[30];
  int nr = 0;
  struct pollfd p_fd[1];
  int p_res;
  struct input_event ie;
  if (argc > 2) {
    printf("usage: pfbuttons_test [nr]\n where nr is the event device (from 0 "
           "to 31)");
    return 0;
  }
  if (argc > 1) {
    nr = atoi(argv[1]);
  }
  if (nr < 0 && nr > 31) {
    printf("usage: pfbuttons_test [nr]\n where nr is the event device (from 0 "
           "to 31)");
  }
  sprintf(f_name, "/dev/input/event%d", nr);
  printf("########################## PFBUTTONS TEST "
         "###############################\n");
  p_fd[0].fd = open(f_name, O_RDWR | O_NONBLOCK, 0);
  if (p_fd[0].fd == -1) {
    printf("%s open error %d\n", f_name, errno);
    exit(1);
  } else
    printf("open success %s \n", f_name);
  while (1) {
    p_fd[0].revents = 0;
    p_fd[0].events = POLLIN | POLLERR;
    p_res = poll(p_fd, 1, 10);
    if (p_res < 0) {
      perror("read!");
      exit(1);
    }
    if (p_res > 0) {
      if (p_fd[0].revents & POLLIN) {
        while (read(p_fd[0].fd, &ie, sizeof(ie)) > 0) {
          printf("Event. Type: %d, Code: %d, Value: %d\n", ie.type, ie.code,
                 ie.value);
          if (ie.type == EV_KEY) {
            switch (ie.code) {
            case BTN_0:
              printf("Take a look LED_MUTE ... %s\n",
                     ((ie.value) ? "on" : "off"));
              ie.type = EV_LED;
              ie.code = LED_MUTE;
              break;
            case BTN_1:
              printf("Hear SND_BELL ... %s\n", ((ie.value) ? "on" : "off"));
              ie.type = EV_SND;
              ie.code = SND_BELL;
              break;
            case BTN_2:
              printf("Take a look LED_MISC ... %s\n",
                     ((ie.value) ? "on" : "off"));
              ie.type = EV_LED;
              ie.code = LED_MISC;
              break;
            case BTN_3:
              printf("Take a look LED_SUSPEND ... %s\n",
                     ((ie.value) ? "on" : "off"));
              ie.type = EV_LED;
              ie.code = LED_SUSPEND;
              break;
            }
            if (ie.type != EV_KEY) {
              if (write(p_fd[0].fd, &ie, sizeof(ie)) < 0) {
                printf("Not handlet event!\n");
              }
            }
          }
        }
      } else if (p_fd[0].revents & POLLERR) {
        break;
      }
    }
  }
  printf("Exit\n");
  close(p_fd[0].fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11dd <main+0x3d>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret
cmpl   $0x1,-0x8(%rbp)
jle    11f7 <main+0x57>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1219 <main+0x79>
cmpl   $0x1f,-0x44(%rbp)
jle    1219 <main+0x79>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%edx
lea    0xe31(%rip),%rsi
call   10b0 <sprintf@plt>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    0x2d9b(%rip),%rax
mov    (%rax),%esi
mov    0x2d8a(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   1080 <open@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0xffffffff,-0x50(%rbp)
jne    1289 <main+0xe9>
lea    -0x40(%rbp),%rsi
mov    0x2d19(%rip),%rax
mov    (%rax),%edx
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x40(%rbp),%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a0 <main+0x100>
movl   $0x0,-0x4c(%rbp)
mov    0x2cfa(%rip),%rax
mov    (%rax),%eax
mov    0x2d19(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x48(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1070 <poll@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    12f2 <main+0x152>
lea    0xdf7(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpl   $0x0,-0x54(%rbp)
jle    1500 <main+0x360>
mov    -0x4c(%rbp),%eax
mov    0x2ca2(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     14dc <main+0x33c>
jmp    1316 <main+0x176>
mov    -0x50(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0xc,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
jle    14d7 <main+0x337>
mov    -0x60(%rbp),%esi
mov    -0x5c(%rbp),%edx
mov    -0x58(%rbp),%ecx
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x60(%rbp),%eax
mov    0x2c66(%rip),%rcx
cmp    (%rcx),%eax
jne    14d2 <main+0x332>
mov    -0x5c(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x68(%rbp)
sub    $0x3,%eax
ja     148d <main+0x2ed>
mov    -0x68(%rbp),%rax
lea    0xc86(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x58(%rbp),%ecx
lea    0xd99(%rip),%rsi
lea    0xd8f(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c18(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x60(%rbp)
mov    0x2bd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    148d <main+0x2ed>
mov    -0x58(%rbp),%ecx
lea    0xd55(%rip),%rsi
lea    0xd4b(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xd44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2bc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    148d <main+0x2ed>
mov    -0x58(%rbp),%ecx
lea    0xd12(%rip),%rsi
lea    0xd08(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2b91(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x60(%rbp)
mov    0x2b6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    148d <main+0x2ed>
mov    -0x58(%rbp),%ecx
lea    0xcce(%rip),%rsi
lea    0xcc4(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xcf0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2b4d(%rip),%rax
mov    (%rax),%rax
mov    %eax,-0x60(%rbp)
mov    0x2b18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x60(%rbp),%eax
mov    0x2b21(%rip),%rcx
cmp    (%rcx),%eax
je     14cd <main+0x32d>
mov    -0x50(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    14c8 <main+0x328>
lea    0xcbc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14cd <main+0x32d>
jmp    14d2 <main+0x332>
jmp    1316 <main+0x176>
jmp    14fb <main+0x35b>
mov    -0x4c(%rbp),%eax
mov    0x2aea(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     14f6 <main+0x356>
jmp    1505 <main+0x365>
jmp    14fb <main+0x35b>
jmp    1500 <main+0x360>
jmp    12a0 <main+0x100>
lea    0xc85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
cmp    $0x3,%edi
jl     11e2 <main+0x32>
lea    0xe46(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edx,%edx
cmp    $0x2,%edi
jne    11f4 <main+0x44>
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edx
lea    0xe5d(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   10c0 <sprintf@plt>
lea    0xf23(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dc5(%rip),%rax
mov    0x2db6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1090 <open@plt>
mov    %eax,(%rsp)
cmp    $0xffffffff,%eax
jne    125e <main+0xae>
mov    0x2d49(%rip),%rax
mov    (%rax),%edx
lea    0xe23(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xe18(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x0,0x4(%rsp)
mov    0x2d28(%rip),%rcx
mov    0x2d49(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %eax,0x8(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1080 <poll@plt>
test   %eax,%eax
jns    12bb <main+0x10b>
lea    0xde3(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0x10(%rsp),%rbx
lea    0xdce(%rip),%r15
mov    0x2cea(%rip),%r14
jmp    1313 <main+0x163>
mov    0x2cf9(%rip),%rcx
test   %eax,(%rcx)
jne    14a6 <main+0x2f6>
movl   $0x0,0x4(%rsp)
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
mov    0x2cb1(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x8(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1080 <poll@plt>
test   %eax,%eax
js     12a5 <main+0xf5>
test   %eax,%eax
je     12df <main+0x12f>
mov    0x4(%rsp),%eax
mov    0x2c86(%rip),%rcx
test   %eax,(%rcx)
je     12d0 <main+0x120>
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp),%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1070 <read@plt>
test   %rax,%rax
jle    12df <main+0x12f>
mov    0x10(%rsp),%ebp
mov    0x14(%rsp),%r13d
mov    0x18(%rsp),%r12d
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    (%r14),%ebp
jne    1330 <main+0x180>
add    $0xffffff80,%r13d
cmp    $0x3,%r13d
ja     1473 <main+0x2c3>
lea    0xc81(%rip),%rcx
movslq (%rcx,%r13,4),%rax
add    %rcx,%rax
jmp    *%rax
test   %r12d,%r12d
lea    0xd46(%rip),%rsi
lea    0xd42(%rip),%rax
cmove  %rax,%rsi
lea    0xd6e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2c16(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,0x10(%rsp)
mov    0x2be1(%rip),%rax
jmp    146d <main+0x2bd>
test   %r12d,%r12d
lea    0xd0a(%rip),%rsi
lea    0xd06(%rip),%rax
cmove  %rax,%rsi
lea    0xd15(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2bda(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,0x10(%rsp)
mov    0x2bb5(%rip),%rax
jmp    146d <main+0x2bd>
test   %r12d,%r12d
lea    0xcd1(%rip),%rsi
lea    0xccd(%rip),%rax
cmove  %rax,%rsi
lea    0xcc6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2bd1(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,0x10(%rsp)
mov    0x2b8c(%rip),%rax
jmp    146d <main+0x2bd>
test   %r12d,%r12d
lea    0xc98(%rip),%rsi
lea    0xc94(%rip),%rax
cmove  %rax,%rsi
lea    0xc69(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2b68(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,0x10(%rsp)
mov    0x2b23(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
cmp    (%r14),%ebp
je     1330 <main+0x180>
mov    (%rsp),%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    1330 <main+0x180>
lea    0xce5(%rip),%rdi
call   1030 <puts@plt>
jmp    1330 <main+0x180>
lea    0xccf(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
%struct.input_event = type { i32, i32, i32 }
@.str = [72 x i8] c"usage: pfbuttons_test [nr]\0A where nr is the event device (from 0 to 31)\00"
@.str.1 = [19 x i8] c"/dev/input/event%d\00"
@.str.2 = [75 x i8] c"########################## PFBUTTONS TEST ###############################\0A\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.3 = [18 x i8] c"%s open error %d\0A\00"
@errno = global i32 0
@.str.4 = [18 x i8] c"open success %s \0A\00"
@POLLIN = global i32 0
@POLLERR = global i32 0
@.str.5 = [6 x i8] c"read!\00"
@.str.6 = [38 x i8] c"Event. Type: %d, Code: %d, Value: %d\0A\00"
@EV_KEY = global i32 0
@.str.7 = [29 x i8] c"Take a look LED_MUTE ... %s\0A\00"
@.str.8 = [3 x i8] c"on\00"
@.str.9 = [4 x i8] c"off\00"
@EV_LED = global i8* null
@LED_MUTE = global i32 0
@.str.10 = [22 x i8] c"Hear SND_BELL ... %s\0A\00"
@EV_SND = global i32 0
@SND_BELL = global i32 0
@.str.11 = [29 x i8] c"Take a look LED_MISC ... %s\0A\00"
@LED_MISC = global i32 0
@.str.12 = [32 x i8] c"Take a look LED_SUSPEND ... %s\0A\00"
@LED_SUSPEND = global i32 0
@.str.13 = [20 x i8] c"Not handlet event!\0A\00"
@.str.14 = [6 x i8] c"Exit\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [30 x i8]
%8 = alloca i32
%9 = alloca [1 x %struct.pollfd]
%10 = alloca i32
%11 = alloca %struct.input_event
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0))
ret i32 0
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 1
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %8
br label %24
24: ; preds = %19, %16
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i32, i32* %8
%29 = icmp sgt i32 %28, 31
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %30, %27, %24
%33 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%34 = load i32, i32* %8
%35 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0))
%37 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%38 = load i32, i32* @O_RDWR
%39 = load i32, i32* @O_NONBLOCK
%40 = or i32 %38, %39
%41 = call i32 @open(i8* %37, i32 %40, i32 0)
%42 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %9, i64 0, i64 0
%43 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %42, i32 0, i32 0
store i32 %41, i32* %43
%44 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %9, i64 0, i64 0
%45 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %53
48: ; preds = %32
%49 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%50 = load i32, i32* @errno
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %49, i32 %50)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %32
%54 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %53
br label %57
57: ; preds = %56, %178
%58 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %9, i64 0, i64 0
%59 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %58, i32 0, i32 1
store i32 0, i32* %59
%60 = load i32, i32* @POLLIN
%61 = load i32, i32* @POLLERR
%62 = or i32 %60, %61
%63 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %9, i64 0, i64 0
%64 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %63, i32 0, i32 2
store i32 %62, i32* %64
%65 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %9, i64 0, i64 0
%66 = call i32 @poll(%struct.pollfd* %65, i32 1, i32 10)
store i32 %66, i32* %10
%67 = load i32, i32* %10
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %57
%70 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %57
%73 = load i32, i32* %10
%74 = icmp sgt i32 %73, 0
br i1 %74, label %75, label %178
75: ; preds = %72
%76 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %9, i64 0, i64 0
%77 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %76, i32 0, i32 1
%78 = load i32, i32* %77
%79 = load i32, i32* @POLLIN
%80 = and i32 %78, %79
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %168
82: ; preds = %75
br label %83
83: ; preds = %166, %82
%84 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %9, i64 0, i64 0
%85 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %84, i32 0, i32 0
%86 = load i32, i32* %85
%87 = call i64 @read(i32 %86, %struct.input_event* %11, i32 12)
%88 = icmp sgt i64 %87, 0
br i1 %88, label %89, label %167
89: ; preds = %83
%90 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 0
%91 = load i32, i32* %90
%92 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 1
%93 = load i32, i32* %92
%94 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 2
%95 = load i32, i32* %94
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %91, i32 %93, i32 %95)
%97 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 0
%98 = load i32, i32* %97
%99 = load i32, i32* @EV_KEY
%100 = icmp eq i32 %98, %99
br i1 %100, label %101, label %166
101: ; preds = %89
%102 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 1
%103 = load i32, i32* %102
switch i32 %103, label %151 [
i32 131, label %104
i32 130, label %116
i32 129, label %127
i32 128, label %139
]
104: ; preds = %101
%105 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 2
%106 = load i32, i32* %105
%107 = icmp ne i32 %106, 0
%108 = zext i1 %107 to i64
%109 = select i1 %107, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0)
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %109)
%111 = load i8*, i8** @EV_LED
%112 = ptrtoint i8* %111 to i32
%113 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 0
store i32 %112, i32* %113
%114 = load i32, i32* @LED_MUTE
%115 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 1
store i32 %114, i32* %115
br label %151
116: ; preds = %101
%117 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 2
%118 = load i32, i32* %117
%119 = icmp ne i32 %118, 0
%120 = zext i1 %119 to i64
%121 = select i1 %119, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0)
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %121)
%123 = load i32, i32* @EV_SND
%124 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 0
store i32 %123, i32* %124
%125 = load i32, i32* @SND_BELL
%126 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 1
store i32 %125, i32* %126
br label %151
127: ; preds = %101
%128 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 2
%129 = load i32, i32* %128
%130 = icmp ne i32 %129, 0
%131 = zext i1 %130 to i64
%132 = select i1 %130, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0)
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0), i8* %132)
%134 = load i8*, i8** @EV_LED
%135 = ptrtoint i8* %134 to i32
%136 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 0
store i32 %135, i32* %136
%137 = load i32, i32* @LED_MISC
%138 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 1
store i32 %137, i32* %138
br label %151
139: ; preds = %101
%140 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 2
%141 = load i32, i32* %140
%142 = icmp ne i32 %141, 0
%143 = zext i1 %142 to i64
%144 = select i1 %142, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0)
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i8* %144)
%146 = load i8*, i8** @EV_LED
%147 = ptrtoint i8* %146 to i32
%148 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 0
store i32 %147, i32* %148
%149 = load i32, i32* @LED_SUSPEND
%150 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 1
store i32 %149, i32* %150
br label %151
151: ; preds = %101, %139, %127, %116, %104
%152 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 0
%153 = load i32, i32* %152
%154 = load i32, i32* @EV_KEY
%155 = icmp ne i32 %153, %154
br i1 %155, label %156, label %165
156: ; preds = %151
%157 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %9, i64 0, i64 0
%158 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %157, i32 0, i32 0
%159 = load i32, i32* %158
%160 = call i64 @write(i32 %159, %struct.input_event* %11, i32 12)
%161 = icmp slt i64 %160, 0
br i1 %161, label %162, label %164
162: ; preds = %156
%163 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0))
br label %164
164: ; preds = %162, %156
br label %165
165: ; preds = %164, %151
br label %166
166: ; preds = %165, %89
br label %83
167: ; preds = %83
br label %177
168: ; preds = %75
%169 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %9, i64 0, i64 0
%170 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %169, i32 0, i32 1
%171 = load i32, i32* %170
%172 = load i32, i32* @POLLERR
%173 = and i32 %171, %172
%174 = icmp ne i32 %173, 0
br i1 %174, label %175, label %176
175: ; preds = %168
br label %179
176: ; preds = %168
br label %177
177: ; preds = %176, %167
br label %178
178: ; preds = %177, %72
br label %57
179: ; preds = %175
%180 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.14, i64 0, i64 0))
%181 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %9, i64 0, i64 0
%182 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %181, i32 0, i32 0
%183 = load i32, i32* %182
%184 = call i32 @close(i32 %183)
%185 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
%struct.input_event = type { i32, i32, i32 }
@.str = [72 x i8] c"usage: pfbuttons_test [nr]\0A where nr is the event device (from 0 to 31)\00"
@.str.1 = [19 x i8] c"/dev/input/event%d\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.3 = [18 x i8] c"%s open error %d\0A\00"
@errno = global i32 0
@.str.4 = [18 x i8] c"open success %s \0A\00"
@POLLIN = global i32 0
@POLLERR = global i32 0
@.str.5 = [6 x i8] c"read!\00"
@.str.6 = [38 x i8] c"Event. Type: %d, Code: %d, Value: %d\0A\00"
@EV_KEY = global i32 0
@.str.7 = [29 x i8] c"Take a look LED_MUTE ... %s\0A\00"
@.str.8 = [3 x i8] c"on\00"
@.str.9 = [4 x i8] c"off\00"
@EV_LED = global i8* null
@LED_MUTE = global i32 0
@.str.10 = [22 x i8] c"Hear SND_BELL ... %s\0A\00"
@EV_SND = global i32 0
@SND_BELL = global i32 0
@.str.11 = [29 x i8] c"Take a look LED_MISC ... %s\0A\00"
@LED_MISC = global i32 0
@.str.12 = [32 x i8] c"Take a look LED_SUSPEND ... %s\0A\00"
@LED_SUSPEND = global i32 0
@str = [74 x i8] c"########################## PFBUTTONS TEST ###############################\00"
@str.15 = [5 x i8] c"Exit\00"
@str.16 = [19 x i8] c"Not handlet event!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [30 x i8]
%4 = alloca [1 x %struct.pollfd]
%5 = alloca %struct.input_event
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%7 = bitcast [1 x %struct.pollfd]* %4 to i8*
%8 = bitcast %struct.input_event* %5 to i8*
%9 = icmp sgt i32 %0, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0))
ret i32 0
12: ; preds = %2
%13 = icmp eq i32 %0, 2
br i1 %13, label %14, label %18
14: ; preds = %12
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
br label %18
18: ; preds = %12, %14
%19 = phi i32 [ %17, %14 ], [ 0, %12 ]
%20 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str, i64 0, i64 0))
%22 = load i32, i32* @O_RDWR
%23 = load i32, i32* @O_NONBLOCK
%24 = or i32 %23, %22
%25 = call i32 @open(i8* %6, i32 %24, i32 0)
%26 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0
%27 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0, i32 0
store i32 %25, i32* %27
%28 = icmp eq i32 %25, -1
br i1 %28, label %29, label %33
29: ; preds = %18
%30 = load i32, i32* @errno
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %6, i32 %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %18
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%35 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0, i32 1
%36 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0, i32 2
store i32 0, i32* %35
%37 = load i32, i32* @POLLIN
%38 = load i32, i32* @POLLERR
%39 = or i32 %38, %37
store i32 %39, i32* %36
%40 = call i32 @poll(%struct.pollfd* %26, i32 1, i32 10)
%41 = icmp slt i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %33
%43 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i64 0, i32 0
%44 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i64 0, i32 1
%45 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i64 0, i32 2
br label %49
46: ; preds = %117, %33
%47 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %42, %117
%50 = phi i32 [ %40, %42 ], [ %121, %117 ]
%51 = icmp eq i32 %50, 0
br i1 %51, label %117, label %52
52: ; preds = %49
%53 = load i32, i32* %35
%54 = load i32, i32* @POLLIN
%55 = and i32 %54, %53
%56 = icmp eq i32 %55, 0
br i1 %56, label %113, label %57
57: ; preds = %52
%58 = load i32, i32* %27
%59 = call i64 @read(i32 %58, %struct.input_event* %5, i32 12)
%60 = icmp sgt i64 %59, 0
br i1 %60, label %61, label %117
61: ; preds = %57, %109
%62 = load i32, i32* %43
%63 = load i32, i32* %44
%64 = load i32, i32* %45
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i32 %62, i32 %63, i32 %64)
%66 = load i32, i32* @EV_KEY
%67 = icmp eq i32 %62, %66
br i1 %67, label %68, label %109
68: ; preds = %61
switch i32 %63, label %99 [
i32 131, label %69
i32 130, label %76
i32 129, label %81
i32 128, label %88
]
69: ; preds = %68
%70 = icmp eq i32 %64, 0
%71 = select i1 %70, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0)
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %71)
%73 = load i8*, i8** @EV_LED
%74 = ptrtoint i8* %73 to i64
%75 = trunc i64 %74 to i32
store i32 %75, i32* %43
br label %95
76: ; preds = %68
%77 = icmp eq i32 %64, 0
%78 = select i1 %77, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0)
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* %78)
%80 = load i32, i32* @EV_SND
store i32 %80, i32* %43
br label %95
81: ; preds = %68
%82 = icmp eq i32 %64, 0
%83 = select i1 %82, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0)
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0), i8* %83)
%85 = load i8*, i8** @EV_LED
%86 = ptrtoint i8* %85 to i64
%87 = trunc i64 %86 to i32
store i32 %87, i32* %43
br label %95
88: ; preds = %68
%89 = icmp eq i32 %64, 0
%90 = select i1 %89, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0)
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i8* %90)
%92 = load i8*, i8** @EV_LED
%93 = ptrtoint i8* %92 to i64
%94 = trunc i64 %93 to i32
store i32 %94, i32* %43
br label %95
95: ; preds = %69, %76, %81, %88
%96 = phi i32* [ @LED_SUSPEND, %88 ], [ @LED_MISC, %81 ], [ @SND_BELL, %76 ], [ @LED_MUTE, %69 ]
%97 = phi i32 [ %94, %88 ], [ %87, %81 ], [ %80, %76 ], [ %75, %69 ]
%98 = load i32, i32* %96
store i32 %98, i32* %44
br label %99
99: ; preds = %95, %68
%100 = phi i32 [ %62, %68 ], [ %97, %95 ]
%101 = load i32, i32* @EV_KEY
%102 = icmp eq i32 %100, %101
br i1 %102, label %109, label %103
103: ; preds = %99
%104 = load i32, i32* %27
%105 = call i64 @write(i32 %104, %struct.input_event* %5, i32 12)
%106 = icmp slt i64 %105, 0
br i1 %106, label %107, label %109
107: ; preds = %103
%108 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.16, i64 0, i64 0))
br label %109
109: ; preds = %99, %107, %103, %61
%110 = load i32, i32* %27
%111 = call i64 @read(i32 %110, %struct.input_event* %5, i32 12)
%112 = icmp sgt i64 %111, 0
br i1 %112, label %61, label %117
113: ; preds = %52
%114 = load i32, i32* @POLLERR
%115 = and i32 %114, %53
%116 = icmp eq i32 %115, 0
br i1 %116, label %117, label %123
117: ; preds = %109, %57, %113, %49
store i32 0, i32* %35
%118 = load i32, i32* @POLLIN
%119 = load i32, i32* @POLLERR
%120 = or i32 %119, %118
store i32 %120, i32* %36
%121 = call i32 @poll(%struct.pollfd* %26, i32 1, i32 10)
%122 = icmp slt i32 %121, 0
br i1 %122, label %46, label %49
123: ; preds = %113
%124 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.15, i64 0, i64 0))
%125 = load i32, i32* %27
%126 = call i32 @close(i32 %125)
%127 = call i32 @exit(i32 0)
unreachable
}