#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct tm {
  int dummy;
};
struct TYPE_2__ {
  int /*<<< orphan*/ tv_sec;
};
struct input_event {
  scalar_t__ code;
  int type;
  int value;
  TYPE_1__ time;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ KEY_A;
scalar_t__ KEY_RIGHTCTRL;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(struct input_event *, int, int, int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int main() {
  char *device = "/dev/input/event2";
  FILE *f = fopen(device, "r");
  if (f == NULL) {
    perror(device);
    exit(1);
  }
  bool right_ctrl_press = false;
  struct input_event evt;
  size_t sz;
  while ((sz = fread(&evt, sizeof(struct input_event), 1, f) != 0)) {
    if (evt.code == KEY_RIGHTCTRL) {
      right_ctrl_press = evt.type;
    }
    bool pressed = (evt.value == 1 || evt.value == 2);
    if (evt.code == KEY_A && pressed && right_ctrl_press) {
      struct tm *nowtm = localtime(&evt.time.tv_sec);
      char buf[64] = {0};
      strftime(buf, sizeof(buf), "%Y-%m-%d @ %H:%M:%S", nowtm);
      printf("%s Ctrl A!\n", buf);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cf <main+0x4f>
mov    -0x10(%rbp),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x38(%rbp),%rdi
mov    $0x18,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
cltq
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     12d0 <main+0x150>
mov    -0x38(%rbp),%rax
mov    0x2dd4(%rip),%rcx
cmp    (%rcx),%rax
jne    1223 <main+0xa3>
mov    -0x30(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x1,%al
cmpl   $0x1,-0x2c(%rbp)
mov    %al,-0x91(%rbp)
je     1242 <main+0xc2>
cmpl   $0x2,-0x2c(%rbp)
sete   %al
mov    %al,-0x91(%rbp)
mov    -0x91(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rax
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%rax
jne    12cb <main+0x14b>
cmpl   $0x0,-0x44(%rbp)
je     12cb <main+0x14b>
cmpl   $0x0,-0x1c(%rbp)
je     12cb <main+0x14b>
lea    -0x38(%rbp),%rdi
add    $0x10,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x50(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
lea    -0x90(%rbp),%rdi
mov    -0x50(%rbp),%rcx
mov    $0x40,%esi
lea    0xd61(%rip),%rdx
call   1070 <strftime@plt>
lea    -0x90(%rbp),%rsi
lea    0xd62(%rip),%rdi
call   1050 <printf@plt>
jmp    11d6 <main+0x56>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe7b(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     127d <main+0x10d>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x18,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     126c <main+0xfc>
xor    %r14d,%r14d
mov    0x2e21(%rip),%r15
mov    0x2e12(%rip),%r13
lea    0x20(%rsp),%r12
lea    0x8(%rsp),%rbp
jmp    11fa <main+0x8a>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x18,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     126c <main+0xfc>
mov    0x8(%rsp),%rax
cmp    (%r15),%rax
jne    1209 <main+0x99>
mov    0x10(%rsp),%r14d
cmp    0x0(%r13),%rax
jne    11e0 <main+0x70>
mov    0x14(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x1,%eax
ja     11e0 <main+0x70>
test   %r14d,%r14d
je     11e0 <main+0x70>
lea    0x18(%rsp),%rdi
call   1030 <localtime@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
mov    %r12,%rdi
mov    $0x40,%esi
lea    0xdc4(%rip),%rdx
mov    %rax,%rcx
call   1060 <strftime@plt>
lea    0xdc9(%rip),%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
jmp    11e0 <main+0x70>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd7c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.input_event = type { i64, i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.tm = type { i32 }
@.str = [18 x i8] c"/dev/input/event2\00"
@.str.1 = [2 x i8] c"r\00"
@KEY_RIGHTCTRL = global i64 0
@KEY_A = global i64 0
@.str.2 = [20 x i8] c"%Y-%m-%d @ %H:%M:%S\00"
@.str.3 = [12 x i8] c"%s Ctrl A!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca %struct.input_event
%6 = alloca i64
%7 = alloca i32
%8 = alloca %struct.tm*
%9 = alloca [64 x i8]
store i32 0, i32* %1
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %2
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = load i8*, i8** %2
%16 = call i32 @perror(i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
store i32 0, i32* %4
br label %19
19: ; preds = %65, %18
%20 = load i32*, i32** %3
%21 = call i64 @fread(%struct.input_event* %5, i32 24, i32 1, i32* %20)
%22 = icmp ne i64 %21, 0
%23 = zext i1 %22 to i32
%24 = sext i32 %23 to i64
store i64 %24, i64* %6
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %66
26: ; preds = %19
%27 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 0
%28 = load i64, i64* %27
%29 = load i64, i64* @KEY_RIGHTCTRL
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 1
%33 = load i32, i32* %32
store i32 %33, i32* %4
br label %34
34: ; preds = %31, %26
%35 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 2
%36 = load i32, i32* %35
%37 = icmp eq i32 %36, 1
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 2
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, 2
br label %42
42: ; preds = %38, %34
%43 = phi i1 [ true, %34 ], [ %41, %38 ]
%44 = zext i1 %43 to i32
store i32 %44, i32* %7
%45 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 0
%46 = load i64, i64* %45
%47 = load i64, i64* @KEY_A
%48 = icmp eq i64 %46, %47
br i1 %48, label %49, label %65
49: ; preds = %42
%50 = load i32, i32* %7
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %65
52: ; preds = %49
%53 = load i32, i32* %4
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %65
55: ; preds = %52
%56 = getelementptr inbounds %struct.input_event, %struct.input_event* %5, i32 0, i32 3
%57 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %56, i32 0, i32 0
%58 = call %struct.tm* @localtime(i32* %57)
store %struct.tm* %58, %struct.tm** %8
%59 = bitcast [64 x i8]* %9 to i8*
%60 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%61 = load %struct.tm*, %struct.tm** %8
%62 = call i32 @strftime(i8* %60, i32 64, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %61)
%63 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%64 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %55, %52, %49, %42
br label %19
66: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
%struct.input_event = type { i64, i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.tm = type { i32 }
@.str = [18 x i8] c"/dev/input/event2\00"
@.str.1 = [2 x i8] c"r\00"
@KEY_RIGHTCTRL = global i64 0
@KEY_A = global i64 0
@.str.2 = [20 x i8] c"%Y-%m-%d @ %H:%M:%S\00"
@.str.3 = [12 x i8] c"%s Ctrl A!\0A\00"
define i32 @main() {
%1 = alloca %struct.input_event
%2 = alloca [64 x i8]
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = bitcast %struct.input_event* %1 to i8*
%10 = call i64 @fread(%struct.input_event* %1, i32 24, i32 1, i32* %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %40, label %12
12: ; preds = %8
%13 = getelementptr inbounds %struct.input_event, %struct.input_event* %1, i64 0, i32 0
%14 = getelementptr inbounds %struct.input_event, %struct.input_event* %1, i64 0, i32 1
%15 = getelementptr inbounds %struct.input_event, %struct.input_event* %1, i64 0, i32 2
%16 = getelementptr inbounds %struct.input_event, %struct.input_event* %1, i64 0, i32 3, i32 0
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
br label %18
18: ; preds = %12, %37
%19 = phi i32 [ 0, %12 ], [ %24, %37 ]
%20 = load i64, i64* %13
%21 = load i64, i64* @KEY_RIGHTCTRL
%22 = icmp eq i64 %20, %21
%23 = load i32, i32* %14
%24 = select i1 %22, i32 %23, i32 %19
%25 = load i32, i32* %15
%26 = add i32 %25, -1
%27 = icmp ult i32 %26, 2
%28 = load i64, i64* @KEY_A
%29 = icmp eq i64 %20, %28
%30 = select i1 %29, i1 %27, i1 false
%31 = icmp ne i32 %24, 0
%32 = select i1 %30, i1 %31, i1 false
br i1 %32, label %33, label %37
33: ; preds = %18
%34 = call %struct.tm* @localtime(i32* %16)
%35 = call i32 @strftime(i8* %17, i32 64, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %34)
%36 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %17)
br label %37
37: ; preds = %33, %18
%38 = call i64 @fread(%struct.input_event* %1, i32 24, i32 1, i32* %3)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %18
40: ; preds = %37, %8
ret i32 0
}