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

/* Variables and functions */
int /*<<< orphan*/ EV_KEY;
int KEY_LEFTSHIFT;
int ev_emit(int, int /*<<< orphan*/, int, int);
scalar_t__ ev_syn(int);
int ev_key(int fd, int key, int value) {
  int ret;
  if (value && (0x10000 & key)) {
    if (ev_key(fd, KEY_LEFTSHIFT, 1) < 0)
      return -1;
  }
  ret = ev_emit(fd, EV_KEY, key & 0xfff, value);
  if (ev_syn(fd) < 0)
    return -1;
  if (!value && (0x10000 & key)) {
    if (ev_key(fd, KEY_LEFTSHIFT, 0) < 0)
      return -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<ev_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     118c <ev_key+0x5c>
mov    -0xc(%rbp),%eax
and    $0x10000,%eax
cmp    $0x0,%eax
je     118c <ev_key+0x5c>
mov    -0x8(%rbp),%edi
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1030 <ev_key@plt>
cmp    $0x0,%eax
jge    1187 <ev_key+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <ev_key+0xe8>
jmp    118c <ev_key+0x5c>
mov    -0x8(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
and    $0xfff,%edx
mov    -0x10(%rbp),%ecx
call   1040 <ev_emit@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <ev_syn@plt>
cmp    $0x0,%rax
jge    11ca <ev_key+0x9a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <ev_key+0xe8>
cmpl   $0x0,-0x10(%rbp)
jne    1212 <ev_key+0xe2>
mov    -0xc(%rbp),%eax
and    $0x10000,%eax
cmp    $0x0,%eax
je     1212 <ev_key+0xe2>
mov    -0x8(%rbp),%edi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <ev_key@plt>
cmp    $0x0,%eax
jge    120d <ev_key+0xdd>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <ev_key+0xe8>
jmp    1212 <ev_key+0xe2>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ev_key>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r14d
test   %edx,%edx
je     1166 <ev_key+0x36>
mov    %ebx,%eax
and    $0x10000,%eax
je     1166 <ev_key+0x36>
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    $0x1,%edx
call   1030 <ev_key@plt>
test   %eax,%eax
js     11bf <ev_key+0x8f>
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edx
and    $0xfff,%edx
mov    %r14d,%edi
mov    %ebp,%ecx
call   1040 <ev_emit@plt>
mov    %eax,%r12d
mov    %r14d,%edi
call   1050 <ev_syn@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
js     11c5 <ev_key+0x95>
test   $0x10000,%ebx
je     11ba <ev_key+0x8a>
test   %ebp,%ebp
jne    11ba <ev_key+0x8a>
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
xor    %edx,%edx
call   1030 <ev_key@plt>
test   %eax,%eax
js     11c5 <ev_key+0x95>
mov    %r12d,%r15d
jmp    11c5 <ev_key+0x95>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@KEY_LEFTSHIFT = global i32 0
@EV_KEY = global i32 0
define i32 @ev_key(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %3
%12 = load i32, i32* %6
%13 = and i32 65536, %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %11
%16 = load i32, i32* %5
%17 = load i32, i32* @KEY_LEFTSHIFT
%18 = call i32 @ev_key(i32 %16, i32 %17, i32 1)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 -1, i32* %4
br label %49
21: ; preds = %15
br label %22
22: ; preds = %21, %11, %3
%23 = load i32, i32* %5
%24 = load i32, i32* @EV_KEY
%25 = load i32, i32* %6
%26 = and i32 %25, 4095
%27 = load i32, i32* %7
%28 = call i32 @ev_emit(i32 %23, i32 %24, i32 %26, i32 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %5
%30 = call i64 @ev_syn(i32 %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %22
store i32 -1, i32* %4
br label %49
33: ; preds = %22
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 0
br i1 %35, label %47, label %36
36: ; preds = %33
%37 = load i32, i32* %6
%38 = and i32 65536, %37
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %36
%41 = load i32, i32* %5
%42 = load i32, i32* @KEY_LEFTSHIFT
%43 = call i32 @ev_key(i32 %41, i32 %42, i32 0)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %40
store i32 -1, i32* %4
br label %49
46: ; preds = %40
br label %47
47: ; preds = %46, %36, %33
%48 = load i32, i32* %8
store i32 %48, i32* %4
br label %49
49: ; preds = %47, %45, %32, %20
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
@KEY_LEFTSHIFT = global i32 0
@EV_KEY = global i32 0
define i32 @ev_key(i32 %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
%5 = and i32 %1, 65536
%6 = icmp eq i32 %5, 0
%7 = or i1 %4, %6
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = load i32, i32* @KEY_LEFTSHIFT
%10 = tail call i32 @ev_key(i32 %0, i32 %9, i32 1)
%11 = icmp slt i32 %10, 0
br i1 %11, label %26, label %12
12: ; preds = %8, %3
%13 = load i32, i32* @EV_KEY
%14 = and i32 %1, 4095
%15 = tail call i32 @ev_emit(i32 %0, i32 %13, i32 %14, i32 %2)
%16 = tail call i64 @ev_syn(i32 %0)
%17 = icmp slt i64 %16, 0
br i1 %17, label %26, label %18
18: ; preds = %12
%19 = xor i1 %4, true
%20 = or i1 %6, %19
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* @KEY_LEFTSHIFT
%23 = tail call i32 @ev_key(i32 %0, i32 %22, i32 0)
%24 = icmp slt i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %21, %18
br label %26
26: ; preds = %21, %12, %8, %25
%27 = phi i32 [ %15, %25 ], [ -1, %8 ], [ -1, %12 ], [ -1, %21 ]
ret i32 %27
}