#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_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  int keycode;
  int /*<<< orphan*/ window;
  int /*<<< orphan*/ display;
  void *type;
  scalar_t__ state;
};
struct TYPE_6__ {
  TYPE_1__ xkey;
  void *type;
};
typedef TYPE_2__ XEvent;
typedef scalar_t__ KeySym;

/* Variables and functions */
int /*<<< orphan*/ False;
void *KeyPress;
int /*<<< orphan*/ KeyPressMask;
void *KeyRelease;
int /*<<< orphan*/ KeyReleaseMask;
int /*<<< orphan*/ True;
int /*<<< orphan*/ XChangeKeyboardMapping(int /*<<< orphan*/, int, int,
                                          scalar_t__ *, int);
int /*<<< orphan*/ XSendEvent(int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              TYPE_2__ *);
void sendKey(XEvent *xev, KeySym keysym, int numBS, int victim) {
  int i;
  if (keysym == 0)
    return;
  xev->xkey.keycode = 0x16;
  xev->type = KeyPress;
  xev->xkey.type = KeyPress;
  xev->xkey.state = 0;
  for (i = 0; i < numBS; ++i)
    XSendEvent(xev->xkey.display, xev->xkey.window, False, KeyPressMask,
               (XEvent *)xev);
  XChangeKeyboardMapping(xev->xkey.display, victim, 1, &keysym, 1);
  xev->xkey.keycode = victim;
  xev->type = KeyPress;
  xev->xkey.type = KeyPress;
  XSendEvent(xev->xkey.display, xev->xkey.window, True, KeyPressMask,
             (XEvent *)xev);
  xev->type = KeyRelease;
  xev->xkey.type = KeyRelease;
  XSendEvent(xev->xkey.display, xev->xkey.window, True, KeyReleaseMask,
             (XEvent *)xev);
}


x86 assembly (clang, -O0):
<sendKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1146 <sendKey+0x26>
jmp    1289 <sendKey+0x169>
mov    -0x8(%rbp),%rax
movl   $0x16,(%rax)
mov    0x2e79(%rip),%rax
mov    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    0x2e67(%rip),%rax
mov    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x18(%rax)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ca <sendKey+0xaa>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
mov    0x2e2f(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8
call   1030 <XSendEvent@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1187 <sendKey+0x67>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x18(%rbp),%esi
mov    $0x1,%r8d
lea    -0x10(%rbp),%rcx
mov    %r8d,%edx
call   1040 <XChangeKeyboardMapping@plt>
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2dda(%rip),%rax
mov    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    0x2dc8(%rip),%rax
mov    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
mov    0x2db0(%rip),%rax
mov    (%rax),%edx
mov    0x2daf(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8
call   1030 <XSendEvent@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x20(%rax)
mov    0x2d6b(%rip),%rax
mov    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
mov    0x2d63(%rip),%rax
mov    (%rax),%edx
mov    0x2d3a(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8
call   1030 <XSendEvent@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendKey>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,(%rsp)
test   %rsi,%rsi
je     120f <sendKey+0xef>
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rdi,%rbx
movl   $0x16,(%rdi)
mov    0x2e83(%rip),%r15
mov    (%r15),%rax
mov    %rax,0x20(%rdi)
mov    %rax,0x10(%rdi)
movq   $0x0,0x18(%rdi)
test   %edx,%edx
jle    119b <sendKey+0x7b>
mov    0x2e7d(%rip),%r12
mov    0x2e6e(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x4(%rbx),%esi
mov    0x8(%rbx),%edi
mov    (%r12),%edx
mov    0x0(%r13),%ecx
mov    %rbx,%r8
call   1030 <XSendEvent@plt>
add    $0xffffffff,%ebp
jne    1180 <sendKey+0x60>
mov    0x8(%rbx),%edi
mov    %rsp,%rcx
mov    %r14d,%esi
mov    $0x1,%edx
mov    $0x1,%r8d
call   1040 <XChangeKeyboardMapping@plt>
mov    %r14d,(%rbx)
mov    (%r15),%rax
mov    %rax,0x20(%rbx)
mov    %rax,0x10(%rbx)
mov    0x4(%rbx),%esi
mov    0x8(%rbx),%edi
mov    0x2e09(%rip),%rbp
mov    0x0(%rbp),%edx
mov    0x2e07(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%r8
call   1030 <XSendEvent@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x20(%rbx)
mov    %rax,0x10(%rbx)
mov    0x4(%rbx),%esi
mov    0x8(%rbx),%edi
mov    0x0(%rbp),%edx
mov    0x2db3(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%r8
call   1030 <XSendEvent@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { %struct.TYPE_5__, i8* }
%struct.TYPE_5__ = type { i32, i32, i32, i8*, i64 }
@KeyPress = global i8* null
@False = global i32 0
@KeyPressMask = global i32 0
@True = global i32 0
@KeyRelease = global i8* null
@KeyReleaseMask = global i32 0
define void @sendKey(%struct.TYPE_6__* %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca %struct.TYPE_6__*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.TYPE_6__* %0, %struct.TYPE_6__** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i64, i64* %6
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %4
br label %96
13: ; preds = %4
%14 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%15 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %14, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %15, i32 0, i32 0
store i32 22, i32* %16
%17 = load i8*, i8** @KeyPress
%18 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%19 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %18, i32 0, i32 1
store i8* %17, i8** %19
%20 = load i8*, i8** @KeyPress
%21 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%22 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %21, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %22, i32 0, i32 3
store i8* %20, i8** %23
%24 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%25 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %24, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %25, i32 0, i32 4
store i64 0, i64* %26
store i32 0, i32* %9
br label %27
27: ; preds = %44, %13
%28 = load i32, i32* %9
%29 = load i32, i32* %7
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %47
31: ; preds = %27
%32 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%33 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %32, i32 0, i32 0
%34 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %33, i32 0, i32 2
%35 = load i32, i32* %34
%36 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%37 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %36, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %37, i32 0, i32 1
%39 = load i32, i32* %38
%40 = load i32, i32* @False
%41 = load i32, i32* @KeyPressMask
%42 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%43 = call i32 @XSendEvent(i32 %35, i32 %39, i32 %40, i32 %41, %struct.TYPE_6__* %42)
br label %44
44: ; preds = %31
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %27
47: ; preds = %27
%48 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%49 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %48, i32 0, i32 0
%50 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %49, i32 0, i32 2
%51 = load i32, i32* %50
%52 = load i32, i32* %8
%53 = call i32 @XChangeKeyboardMapping(i32 %51, i32 %52, i32 1, i64* %6, i32 1)
%54 = load i32, i32* %8
%55 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%56 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %55, i32 0, i32 0
%57 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %56, i32 0, i32 0
store i32 %54, i32* %57
%58 = load i8*, i8** @KeyPress
%59 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%60 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %59, i32 0, i32 1
store i8* %58, i8** %60
%61 = load i8*, i8** @KeyPress
%62 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%63 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %62, i32 0, i32 0
%64 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %63, i32 0, i32 3
store i8* %61, i8** %64
%65 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%66 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %65, i32 0, i32 0
%67 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %66, i32 0, i32 2
%68 = load i32, i32* %67
%69 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%70 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %69, i32 0, i32 0
%71 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %70, i32 0, i32 1
%72 = load i32, i32* %71
%73 = load i32, i32* @True
%74 = load i32, i32* @KeyPressMask
%75 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%76 = call i32 @XSendEvent(i32 %68, i32 %72, i32 %73, i32 %74, %struct.TYPE_6__* %75)
%77 = load i8*, i8** @KeyRelease
%78 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%79 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %78, i32 0, i32 1
store i8* %77, i8** %79
%80 = load i8*, i8** @KeyRelease
%81 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%82 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %81, i32 0, i32 0
%83 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %82, i32 0, i32 3
store i8* %80, i8** %83
%84 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%85 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %84, i32 0, i32 0
%86 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %85, i32 0, i32 2
%87 = load i32, i32* %86
%88 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%89 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %88, i32 0, i32 0
%90 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %89, i32 0, i32 1
%91 = load i32, i32* %90
%92 = load i32, i32* @True
%93 = load i32, i32* @KeyReleaseMask
%94 = load %struct.TYPE_6__*, %struct.TYPE_6__** %5
%95 = call i32 @XSendEvent(i32 %87, i32 %91, i32 %92, i32 %93, %struct.TYPE_6__* %94)
br label %96
96: ; preds = %47, %12
ret void
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { %struct.TYPE_5__, i8* }
%struct.TYPE_5__ = type { i32, i32, i32, i8*, i64 }
@KeyPress = global i8* null
@False = global i32 0
@KeyPressMask = global i32 0
@True = global i32 0
@KeyRelease = global i8* null
@KeyReleaseMask = global i32 0
define void @sendKey(%struct.TYPE_6__* %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca i64
store i64 %1, i64* %5
%6 = icmp eq i64 %1, 0
br i1 %6, label %43, label %7
7: ; preds = %4
%8 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 0, i32 0
store i32 22, i32* %8
%9 = load i8*, i8** @KeyPress
%10 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 1
store i8* %9, i8** %10
%11 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 0, i32 3
store i8* %9, i8** %11
%12 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 0, i32 4
store i64 0, i64* %12
%13 = icmp sgt i32 %2, 0
br i1 %13, label %14, label %26
14: ; preds = %7
%15 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 0, i32 2
%16 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 0, i32 1
br label %17
17: ; preds = %14, %17
%18 = phi i32 [ 0, %14 ], [ %24, %17 ]
%19 = load i32, i32* %15
%20 = load i32, i32* %16
%21 = load i32, i32* @False
%22 = load i32, i32* @KeyPressMask
%23 = tail call i32 @XSendEvent(i32 %19, i32 %20, i32 %21, i32 %22, %struct.TYPE_6__* %0)
%24 = add nuw nsw i32 %18, 1
%25 = icmp eq i32 %24, %2
br i1 %25, label %26, label %17
26: ; preds = %17, %7
%27 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 0, i32 2
%28 = load i32, i32* %27
%29 = call i32 @XChangeKeyboardMapping(i32 %28, i32 %3, i32 1, i64* %5, i32 1)
store i32 %3, i32* %8
%30 = load i8*, i8** @KeyPress
store i8* %30, i8** %10
store i8* %30, i8** %11
%31 = load i32, i32* %27
%32 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %0, i64 0, i32 0, i32 1
%33 = load i32, i32* %32
%34 = load i32, i32* @True
%35 = load i32, i32* @KeyPressMask
%36 = call i32 @XSendEvent(i32 %31, i32 %33, i32 %34, i32 %35, %struct.TYPE_6__* %0)
%37 = load i8*, i8** @KeyRelease
store i8* %37, i8** %10
store i8* %37, i8** %11
%38 = load i32, i32* %27
%39 = load i32, i32* %32
%40 = load i32, i32* @True
%41 = load i32, i32* @KeyReleaseMask
%42 = call i32 @XSendEvent(i32 %38, i32 %39, i32 %40, i32 %41, %struct.TYPE_6__* %0)
br label %43
43: ; preds = %4, %26
ret void
}