#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 input_event {
  int type;
  int code;
  int value;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ event4;
typedef int /*<<< orphan*/ event3;
typedef int /*<<< orphan*/ event2;
typedef int /*<<< orphan*/ event1;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ getc(int /*<<< orphan*/ *);
char *malloc(long);
int /*<<< orphan*/ memset(struct input_event *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
char *regexp(char *, char *, int *, int *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
scalar_t__ write(int, struct input_event *, int);
void power_key(void) {
  FILE *devfile;
  int fd;
  int b, e;
  long s = 0;
  ssize_t ret;
  char *devstr;
  char *matchblock;
  char *eventres;
  char eventstr[20];
  struct input_event event1;
  struct input_event event2;
  struct input_event event3;
  struct input_event event4;
  if ((devfile = fopen("/proc/bus/input/devices", "rb")) == NULL) {
    printf("Error reading devices file!\n");
    exit(0);
  } else {
    devfile = fopen("/proc/bus/input/devices", "rb");
    if (devfile != NULL) {
      while (getc(devfile) != EOF) {
        s++;
      }
      rewind(devfile);
      devstr = malloc(s);
      if (devstr != NULL) {
        fread(devstr, s, 1, devfile);
        fclose(devfile);
        devfile = NULL;
        if ((matchblock =
                 regexp(devstr,
                        "event[0-9]*[A-z0-9 ]*(\n)B:[ ]*PROP=[A-z0-9]*(\n)B:[ "
                        "]*EV=[A-z0-9]*(\n)B:[ ]*KEY=[0-9 ]*1c0[0-9]00 ",
                        &b, &e)) != NULL) {
          matchblock =
              regexp(devstr,
                     "event[0-9]*[A-z0-9 ]*(\n)B:[ ]*PROP=[A-z0-9]*(\n)B:[ "
                     "]*EV=[A-z0-9]*(\n)B:[ ]*KEY=[0-9 ]*1c0[0-9]00 ",
                     &b, &e);
        } else if ((matchblock =
                        regexp(devstr,
                               "event[0-9]*[A-z0-9 ]*(\n)B:[ "
                               "]*EV=[A-z0-9]*(\n)B:[ ]*KEY=[0-9 ]*1c0[0-9]00 ",
                               &b, &e)) != NULL) {
          matchblock = regexp(devstr,
                              "event[0-9]*[A-z0-9 ]*(\n)B:[ "
                              "]*EV=[A-z0-9]*(\n)B:[ ]*KEY=[0-9 ]*1c0[0-9]00 ",
                              &b, &e);
        } else {
          printf("Error finding input device!\n");
          exit(0);
        }
        if ((eventres = regexp(matchblock, "event[0-9]*", &b, &e)) != NULL) {
          eventres = regexp(matchblock, "event[0-9]*", &b, &e);
          snprintf(eventstr, sizeof eventstr, "%s%s", "/dev/input/", eventres);
        } else {
          printf("Error finding input event number!\n");
          exit(0);
        }
        free(devstr);
      }
    }
    if (devfile != NULL) {
      fclose(devfile);
    }
  }
  fd = open(eventstr, O_RDWR);
  if (fd < 0) {
    printf("Error reading input device!\n");
    exit(0);
  }
  memset(&event1, 0, sizeof(event1));
  event1.type = 1;
  event1.code = 116;
  event1.value = 1;
  ret = write(fd, &event1, sizeof(event1));
  if (ret < (ssize_t)sizeof(event1)) {
    printf("Error writing to event!\n");
    exit(0);
  }
  memset(&event2, 0, sizeof(event2));
  event2.type = 0;
  event2.code = 0;
  event2.value = 0;
  ret = write(fd, &event2, sizeof(event2));
  if (ret < (ssize_t)sizeof(event2)) {
    printf("Error writing to event!\n");
    exit(0);
  }
  memset(&event3, 0, sizeof(event3));
  event3.type = 1;
  event3.code = 116;
  event3.value = 0;
  ret = write(fd, &event3, sizeof(event3));
  if (ret < (ssize_t)sizeof(event3)) {
    printf("Error writing to event!\n");
    exit(0);
  }
  memset(&event4, 0, sizeof(event4));
  event4.type = 0;
  event4.code = 0;
  event4.value = 0;
  ret = write(fd, &event4, sizeof(event4));
  if (ret < (ssize_t)sizeof(event4)) {
    printf("Error writing to event!\n");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<power_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movq   $0x0,-0x20(%rbp)
lea    0xe06(%rip),%rdi
lea    0xe17(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1227 <power_key+0x47>
lea    0xe00(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    0xdd2(%rip),%rdi
lea    0xde3(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     13ee <power_key+0x20e>
jmp    124e <power_key+0x6e>
mov    -0x8(%rbp),%rdi
call   10f0 <getc@plt>
mov    0x2d82(%rip),%rcx
cmp    (%rcx),%rax
je     1278 <power_key+0x98>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    124e <power_key+0x6e>
mov    -0x8(%rbp),%rdi
call   1080 <rewind@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     13e9 <power_key+0x209>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x8(%rbp),%rdi
call   1060 <fclose@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xd6d(%rip),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1100 <regexp@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1307 <power_key+0x127>
mov    -0x30(%rbp),%rdi
lea    0xd47(%rip),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1100 <regexp@plt>
mov    %rax,-0x38(%rbp)
jmp    1366 <power_key+0x186>
mov    -0x30(%rbp),%rdi
lea    0xd87(%rip),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1100 <regexp@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     134e <power_key+0x16e>
mov    -0x30(%rbp),%rdi
lea    0xd61(%rip),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1100 <regexp@plt>
mov    %rax,-0x38(%rbp)
jmp    1361 <power_key+0x181>
lea    0xd8e(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
jmp    1366 <power_key+0x186>
mov    -0x38(%rbp),%rdi
lea    0xd8f(%rip),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1100 <regexp@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     13cd <power_key+0x1ed>
mov    -0x38(%rbp),%rdi
lea    0xd69(%rip),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1100 <regexp@plt>
mov    %rax,-0x40(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x40(%rbp),%r8
mov    $0x14,%esi
lea    0xd50(%rip),%rdx
lea    0xd4e(%rip),%rcx
call   1090 <snprintf@plt>
jmp    13e0 <power_key+0x200>
lea    0xd49(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    13ee <power_key+0x20e>
cmpq   $0x0,-0x8(%rbp)
je     1402 <power_key+0x222>
mov    -0x8(%rbp),%rdi
call   1060 <fclose@plt>
jmp    1407 <power_key+0x227>
lea    -0x60(%rbp),%rdi
mov    0x2bd6(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1439 <power_key+0x259>
lea    0xd13(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
movl   $0x1,-0x70(%rbp)
movl   $0x74,-0x6c(%rbp)
movl   $0x1,-0x68(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0xc,%edx
call   1050 <write@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xc,-0x28(%rbp)
jge    1491 <power_key+0x2b1>
lea    0xcd8(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
movl   $0x0,-0x80(%rbp)
movl   $0x0,-0x7c(%rbp)
movl   $0x0,-0x78(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0xc,%edx
call   1050 <write@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xc,-0x28(%rbp)
jge    14e9 <power_key+0x309>
lea    0xc80(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
movl   $0x1,-0x90(%rbp)
movl   $0x74,-0x8c(%rbp)
movl   $0x0,-0x88(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0xc,%edx
call   1050 <write@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xc,-0x28(%rbp)
jge    1550 <power_key+0x370>
lea    0xc19(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
movl   $0x0,-0xa0(%rbp)
movl   $0x0,-0x9c(%rbp)
movl   $0x0,-0x98(%rbp)
mov    -0xc(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0xc,%edx
call   1050 <write@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xc,-0x28(%rbp)
jge    15b7 <power_key+0x3d7>
lea    0xbb2(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<power_key>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe0e(%rip),%rdi
lea    0xe1f(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1475 <power_key+0x295>
lea    0xdf2(%rip),%rdi
lea    0xe03(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1355 <power_key+0x175>
mov    %rax,%r15
mov    $0xffffffffffffffff,%rbx
mov    0x2dac(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
call   10f0 <getc@plt>
add    $0x1,%rbx
cmp    (%r14),%rax
jne    1240 <power_key+0x60>
mov    %r15,%rdi
call   1080 <rewind@plt>
mov    %rbx,%rdi
call   10b0 <malloc@plt>
test   %rax,%rax
je     134d <power_key+0x16d>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
mov    %r15,%rdi
call   1070 <fclose@plt>
lea    0xd8c(%rip),%rbx
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1100 <regexp@plt>
test   %rax,%rax
jne    12ce <power_key+0xee>
lea    0xdcc(%rip),%rbx
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1100 <regexp@plt>
test   %rax,%rax
je     1490 <power_key+0x2b0>
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r12
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1100 <regexp@plt>
mov    %rax,%rbx
lea    0xdd3(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
call   1100 <regexp@plt>
test   %rax,%rax
je     1487 <power_key+0x2a7>
lea    0xdb5(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
call   1100 <regexp@plt>
lea    0xda8(%rip),%rdx
lea    0xda6(%rip),%rcx
lea    0x50(%rsp),%rdi
mov    $0x14,%esi
mov    %rax,%r8
call   1090 <snprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1355 <power_key+0x175>
mov    %r15,%rdi
call   1070 <fclose@plt>
mov    0x2c8c(%rip),%rax
mov    (%rax),%esi
lea    0x50(%rsp),%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     147e <power_key+0x29e>
mov    %eax,%ebx
lea    0x40(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
movabs $0x7400000001,%r15
mov    %r15,0x40(%rsp)
movl   $0x1,0x48(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1060 <write@plt>
cmp    $0xb,%rax
jle    146c <power_key+0x28c>
lea    0x30(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
movq   $0x0,0x30(%rsp)
movl   $0x0,0x38(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1060 <write@plt>
cmp    $0xb,%rax
jle    146c <power_key+0x28c>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    %r15,0x20(%rsp)
movl   $0x0,0x28(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1060 <write@plt>
cmp    $0xb,%rax
jle    146c <power_key+0x28c>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
movq   $0x0,0x10(%rsp)
movl   $0x0,0x18(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1060 <write@plt>
cmp    $0xb,%rax
jle    146c <power_key+0x28c>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xc70(%rip),%rdi
jmp    1497 <power_key+0x2b7>
lea    0xcd9(%rip),%rdi
jmp    1497 <power_key+0x2b7>
lea    0xc76(%rip),%rdi
jmp    1497 <power_key+0x2b7>
lea    0xca5(%rip),%rdi
jmp    1497 <power_key+0x2b7>
lea    0xc80(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.input_event = type { i32, i32, i32 }
@.str = [24 x i8] c"/proc/bus/input/devices\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [29 x i8] c"Error reading devices file!\0A\00"
@EOF = global i64 0
@.str.3 = [97 x i8] c"event[0-9]*[A-z0-9 ]*(\0A)B:[ ]*PROP=[A-z0-9]*(\0A)B:[ ]*EV=[A-z0-9]*(\0A)B:[ ]*KEY=[0-9 ]*1c0[0-9]00 \00"
@.str.4 = [74 x i8] c"event[0-9]*[A-z0-9 ]*(\0A)B:[ ]*EV=[A-z0-9]*(\0A)B:[ ]*KEY=[0-9 ]*1c0[0-9]00 \00"
@.str.5 = [29 x i8] c"Error finding input device!\0A\00"
@.str.6 = [12 x i8] c"event[0-9]*\00"
@.str.7 = [5 x i8] c"%s%s\00"
@.str.8 = [12 x i8] c"/dev/input/\00"
@.str.9 = [35 x i8] c"Error finding input event number!\0A\00"
@O_RDWR = global i32 0
@.str.10 = [29 x i8] c"Error reading input device!\0A\00"
@.str.11 = [25 x i8] c"Error writing to event!\0A\00"
define void @power_key() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [20 x i8]
%11 = alloca %struct.input_event
%12 = alloca %struct.input_event
%13 = alloca %struct.input_event
%14 = alloca %struct.input_event
store i64 0, i64* %5
%15 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %1
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %0
%21 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %1
%22 = load i32*, i32** %1
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %81
24: ; preds = %20
br label %25
25: ; preds = %30, %24
%26 = load i32*, i32** %1
%27 = call i64 @getc(i32* %26)
%28 = load i64, i64* @EOF
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i64, i64* %5
%32 = add nsw i64 %31, 1
store i64 %32, i64* %5
br label %25
33: ; preds = %25
%34 = load i32*, i32** %1
%35 = call i32 @rewind(i32* %34)
%36 = load i64, i64* %5
%37 = call i8* @malloc(i64 %36)
store i8* %37, i8** %7
%38 = load i8*, i8** %7
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %80
40: ; preds = %33
%41 = load i8*, i8** %7
%42 = load i64, i64* %5
%43 = load i32*, i32** %1
%44 = call i32 @fread(i8* %41, i64 %42, i32 1, i32* %43)
%45 = load i32*, i32** %1
%46 = call i32 @fclose(i32* %45)
store i32* null, i32** %1
%47 = load i8*, i8** %7
%48 = call i8* @regexp(i8* %47, i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4)
store i8* %48, i8** %8
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %53
50: ; preds = %40
%51 = load i8*, i8** %7
%52 = call i8* @regexp(i8* %51, i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4)
store i8* %52, i8** %8
br label %64
53: ; preds = %40
%54 = load i8*, i8** %7
%55 = call i8* @regexp(i8* %54, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.4, i64 0, i64 0), i32* %3, i32* %4)
store i8* %55, i8** %8
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = load i8*, i8** %7
%59 = call i8* @regexp(i8* %58, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.4, i64 0, i64 0), i32* %3, i32* %4)
store i8* %59, i8** %8
br label %63
60: ; preds = %53
%61 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%62 = call i32 @exit(i32 0)
unreachable
63: ; preds = %57
br label %64
64: ; preds = %63, %50
%65 = load i8*, i8** %8
%66 = call i8* @regexp(i8* %65, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32* %3, i32* %4)
store i8* %66, i8** %9
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %74
68: ; preds = %64
%69 = load i8*, i8** %8
%70 = call i8* @regexp(i8* %69, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32* %3, i32* %4)
store i8* %70, i8** %9
%71 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%72 = load i8*, i8** %9
%73 = call i32 @snprintf(i8* %71, i32 20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %72)
br label %77
74: ; preds = %64
%75 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0))
%76 = call i32 @exit(i32 0)
unreachable
77: ; preds = %68
%78 = load i8*, i8** %7
%79 = call i32 @free(i8* %78)
br label %80
80: ; preds = %77, %33
br label %81
81: ; preds = %80, %20
%82 = load i32*, i32** %1
%83 = icmp ne i32* %82, null
br i1 %83, label %84, label %87
84: ; preds = %81
%85 = load i32*, i32** %1
%86 = call i32 @fclose(i32* %85)
br label %87
87: ; preds = %84, %81
br label %88
88: ; preds = %87
%89 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%90 = load i32, i32* @O_RDWR
%91 = call i32 @open(i8* %89, i32 %90)
store i32 %91, i32* %2
%92 = load i32, i32* %2
%93 = icmp slt i32 %92, 0
br i1 %93, label %94, label %97
94: ; preds = %88
%95 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%96 = call i32 @exit(i32 0)
unreachable
97: ; preds = %88
%98 = call i32 @memset(%struct.input_event* %11, i32 0, i32 12)
%99 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 0
store i32 1, i32* %99
%100 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 1
store i32 116, i32* %100
%101 = getelementptr inbounds %struct.input_event, %struct.input_event* %11, i32 0, i32 2
store i32 1, i32* %101
%102 = load i32, i32* %2
%103 = call i64 @write(i32 %102, %struct.input_event* %11, i32 12)
store i64 %103, i64* %6
%104 = load i64, i64* %6
%105 = icmp slt i64 %104, 12
br i1 %105, label %106, label %109
106: ; preds = %97
%107 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0))
%108 = call i32 @exit(i32 0)
unreachable
109: ; preds = %97
%110 = call i32 @memset(%struct.input_event* %12, i32 0, i32 12)
%111 = getelementptr inbounds %struct.input_event, %struct.input_event* %12, i32 0, i32 0
store i32 0, i32* %111
%112 = getelementptr inbounds %struct.input_event, %struct.input_event* %12, i32 0, i32 1
store i32 0, i32* %112
%113 = getelementptr inbounds %struct.input_event, %struct.input_event* %12, i32 0, i32 2
store i32 0, i32* %113
%114 = load i32, i32* %2
%115 = call i64 @write(i32 %114, %struct.input_event* %12, i32 12)
store i64 %115, i64* %6
%116 = load i64, i64* %6
%117 = icmp slt i64 %116, 12
br i1 %117, label %118, label %121
118: ; preds = %109
%119 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0))
%120 = call i32 @exit(i32 0)
unreachable
121: ; preds = %109
%122 = call i32 @memset(%struct.input_event* %13, i32 0, i32 12)
%123 = getelementptr inbounds %struct.input_event, %struct.input_event* %13, i32 0, i32 0
store i32 1, i32* %123
%124 = getelementptr inbounds %struct.input_event, %struct.input_event* %13, i32 0, i32 1
store i32 116, i32* %124
%125 = getelementptr inbounds %struct.input_event, %struct.input_event* %13, i32 0, i32 2
store i32 0, i32* %125
%126 = load i32, i32* %2
%127 = call i64 @write(i32 %126, %struct.input_event* %13, i32 12)
store i64 %127, i64* %6
%128 = load i64, i64* %6
%129 = icmp slt i64 %128, 12
br i1 %129, label %130, label %133
130: ; preds = %121
%131 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0))
%132 = call i32 @exit(i32 0)
unreachable
133: ; preds = %121
%134 = call i32 @memset(%struct.input_event* %14, i32 0, i32 12)
%135 = getelementptr inbounds %struct.input_event, %struct.input_event* %14, i32 0, i32 0
store i32 0, i32* %135
%136 = getelementptr inbounds %struct.input_event, %struct.input_event* %14, i32 0, i32 1
store i32 0, i32* %136
%137 = getelementptr inbounds %struct.input_event, %struct.input_event* %14, i32 0, i32 2
store i32 0, i32* %137
%138 = load i32, i32* %2
%139 = call i64 @write(i32 %138, %struct.input_event* %14, i32 12)
store i64 %139, i64* %6
%140 = load i64, i64* %6
%141 = icmp slt i64 %140, 12
br i1 %141, label %142, label %145
142: ; preds = %133
%143 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0))
%144 = call i32 @exit(i32 0)
unreachable
145: ; preds = %133
ret void
}

LLVM IR (-O2):
%struct.input_event = type { i32, i32, i32 }
@.str = [24 x i8] c"/proc/bus/input/devices\00"
@.str.1 = [3 x i8] c"rb\00"
@EOF = global i64 0
@.str.3 = [97 x i8] c"event[0-9]*[A-z0-9 ]*(\0A)B:[ ]*PROP=[A-z0-9]*(\0A)B:[ ]*EV=[A-z0-9]*(\0A)B:[ ]*KEY=[0-9 ]*1c0[0-9]00 \00"
@.str.4 = [74 x i8] c"event[0-9]*[A-z0-9 ]*(\0A)B:[ ]*EV=[A-z0-9]*(\0A)B:[ ]*KEY=[0-9 ]*1c0[0-9]00 \00"
@.str.6 = [12 x i8] c"event[0-9]*\00"
@.str.7 = [5 x i8] c"%s%s\00"
@.str.8 = [12 x i8] c"/dev/input/\00"
@O_RDWR = global i32 0
@str.14 = [24 x i8] c"Error writing to event!\00"
@str.15 = [28 x i8] c"Error reading input device!\00"
@str.16 = [28 x i8] c"Error finding input device!\00"
@str.17 = [34 x i8] c"Error finding input event number!\00"
@str.18 = [28 x i8] c"Error reading devices file!\00"
define void @power_key() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [20 x i8]
%4 = alloca %struct.input_event
%5 = alloca %struct.input_event
%6 = alloca %struct.input_event
%7 = alloca %struct.input_event
%8 = bitcast i32* %1 to i8*
%9 = bitcast i32* %2 to i8*
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%11 = bitcast %struct.input_event* %4 to i8*
%12 = bitcast %struct.input_event* %5 to i8*
%13 = bitcast %struct.input_event* %6 to i8*
%14 = bitcast %struct.input_event* %7 to i8*
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.18, i64 0, i64 0))
%19 = tail call i32 @exit(i32 0)
unreachable
20: ; preds = %0
%21 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %58, label %23
23: ; preds = %20, %23
%24 = phi i64 [ %28, %23 ], [ 0, %20 ]
%25 = tail call i64 @getc(i32* %21)
%26 = load i64, i64* @EOF
%27 = icmp eq i64 %25, %26
%28 = add nuw nsw i64 %24, 1
br i1 %27, label %29, label %23
29: ; preds = %23
%30 = tail call i32 @rewind(i32* %21)
%31 = tail call i8* @malloc(i64 %24)
%32 = icmp eq i8* %31, null
br i1 %32, label %56, label %33
33: ; preds = %29
%34 = tail call i32 @fread(i8* %31, i64 %24, i32 1, i32* %21)
%35 = tail call i32 @fclose(i32* %21)
%36 = call i8* @regexp(i8* %31, i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.3, i64 0, i64 0), i32* %1, i32* %2)
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %44
38: ; preds = %33
%39 = call i8* @regexp(i8* %31, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.4, i64 0, i64 0), i32* %1, i32* %2)
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.16, i64 0, i64 0))
%43 = call i32 @exit(i32 0)
unreachable
44: ; preds = %38, %33
%45 = phi i8* [ getelementptr inbounds ([97 x i8], [97 x i8]* @.str.3, i64 0, i64 0), %33 ], [ getelementptr inbounds ([74 x i8], [74 x i8]* @.str.4, i64 0, i64 0), %38 ]
%46 = call i8* @regexp(i8* %31, i8* %45, i32* %1, i32* %2)
%47 = call i8* @regexp(i8* %46, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32* %1, i32* %2)
%48 = icmp eq i8* %47, null
br i1 %48, label %53, label %49
49: ; preds = %44
%50 = call i8* @regexp(i8* %46, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32* %1, i32* %2)
%51 = call i32 @snprintf(i8* %10, i32 20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %50)
%52 = call i32 @free(i8* %31)
br label %58
53: ; preds = %44
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.17, i64 0, i64 0))
%55 = call i32 @exit(i32 0)
unreachable
56: ; preds = %29
%57 = tail call i32 @fclose(i32* %21)
br label %58
58: ; preds = %20, %49, %56
%59 = load i32, i32* @O_RDWR
%60 = call i32 @open(i8* %10, i32 %59)
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %58
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.15, i64 0, i64 0))
%64 = call i32 @exit(i32 0)
unreachable
65: ; preds = %58
%66 = call i32 @memset(%struct.input_event* %4, i32 0, i32 12)
%67 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 0
store i32 1, i32* %67
%68 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 1
store i32 116, i32* %68
%69 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 2
store i32 1, i32* %69
%70 = call i64 @write(i32 %60, %struct.input_event* %4, i32 12)
%71 = icmp slt i64 %70, 12
br i1 %71, label %72, label %75
72: ; preds = %65
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.14, i64 0, i64 0))
%74 = call i32 @exit(i32 0)
unreachable
75: ; preds = %65
%76 = call i32 @memset(%struct.input_event* %5, i32 0, i32 12)
%77 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i64 0, i32 0
store i32 0, i32* %77
%78 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i64 0, i32 1
store i32 0, i32* %78
%79 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i64 0, i32 2
store i32 0, i32* %79
%80 = call i64 @write(i32 %60, %struct.input_event* %5, i32 12)
%81 = icmp slt i64 %80, 12
br i1 %81, label %82, label %85
82: ; preds = %75
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.14, i64 0, i64 0))
%84 = call i32 @exit(i32 0)
unreachable
85: ; preds = %75
%86 = call i32 @memset(%struct.input_event* %6, i32 0, i32 12)
%87 = getelementptr inbounds %struct.input_event, %struct.input_event* %6, i64 0, i32 0
store i32 1, i32* %87
%88 = getelementptr inbounds %struct.input_event, %struct.input_event* %6, i64 0, i32 1
store i32 116, i32* %88
%89 = getelementptr inbounds %struct.input_event, %struct.input_event* %6, i64 0, i32 2
store i32 0, i32* %89
%90 = call i64 @write(i32 %60, %struct.input_event* %6, i32 12)
%91 = icmp slt i64 %90, 12
br i1 %91, label %92, label %95
92: ; preds = %85
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.14, i64 0, i64 0))
%94 = call i32 @exit(i32 0)
unreachable
95: ; preds = %85
%96 = call i32 @memset(%struct.input_event* %7, i32 0, i32 12)
%97 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i64 0, i32 0
store i32 0, i32* %97
%98 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i64 0, i32 1
store i32 0, i32* %98
%99 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i64 0, i32 2
store i32 0, i32* %99
%100 = call i64 @write(i32 %60, %struct.input_event* %7, i32 12)
%101 = icmp slt i64 %100, 12
br i1 %101, label %102, label %105
102: ; preds = %95
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.14, i64 0, i64 0))
%104 = call i32 @exit(i32 0)
unreachable
105: ; preds = %95
ret void
}