#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 value;
  unsigned int code;
  int /*<<< orphan*/ type;
};
typedef int /*<<< orphan*/ ev;

/* Variables and functions */
#define BTN_LEFT 130
#define BTN_MIDDLE 129
#define BTN_RIGHT 128
int /*<<< orphan*/ EV_KEY;
int /*<<< orphan*/ memset(struct input_event *, int /*<<< orphan*/, int);
int /*<<< orphan*/ write(int, struct input_event *, int);
void uinput_click(int fd, int up_down, int buttons) {
  static unsigned codes[] = {BTN_LEFT, BTN_MIDDLE, BTN_RIGHT};
  struct input_event ev;
  int x;
  memset(&ev, 0, sizeof(ev));
  for (x = 0; x < 3; ++x) {
    ev.type = EV_KEY;
    ev.value = up_down;
    if (buttons & (1 << x)) {
      ev.code = codes[x];
      write(fd, &ev, sizeof(ev));
    }
  }
}


x86 assembly (clang, -O0):
<uinput_click>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    11b3 <uinput_click+0x93>
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x1c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11a0 <uinput_click+0x80>
movslq -0x1c(%rbp),%rcx
lea    0x2ea7(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
jmp    11a5 <uinput_click+0x85>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1148 <uinput_click+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uinput_click>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r14d
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e9f(%rip),%r15
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    %ebx,0x8(%rsp)
test   $0x1,%bpl
je     1177 <uinput_click+0x57>
movl   $0x82,0xc(%rsp)
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1030 <write@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    %ebx,0x8(%rsp)
test   $0x2,%bpl
je     11a2 <uinput_click+0x82>
movl   $0x81,0xc(%rsp)
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1030 <write@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    %ebx,0x8(%rsp)
test   $0x4,%bpl
je     11ca <uinput_click+0xaa>
movl   $0x80,0xc(%rsp)
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1030 <write@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.input_event = type { i32, i32, i32 }
@uinput_click.codes = internal global [3 x i32] [i32 130, i32 129, i32 128]
@EV_KEY = global i32 0
define void @uinput_click(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.input_event
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = call i32 @memset(%struct.input_event* %7, i32 0, i32 12)
store i32 0, i32* %8
br label %10
10: ; preds = %32, %3
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %35
13: ; preds = %10
%14 = load i32, i32* @EV_KEY
%15 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* %5
%17 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* %6
%19 = load i32, i32* %8
%20 = shl i32 1, %19
%21 = and i32 %18, %20
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %13
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [3 x i32], [3 x i32]* @uinput_click.codes, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.input_event, %struct.input_event* %7, i32 0, i32 1
store i32 %27, i32* %28
%29 = load i32, i32* %4
%30 = call i32 @write(i32 %29, %struct.input_event* %7, i32 12)
br label %31
31: ; preds = %23, %13
br label %32
32: ; preds = %31
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %10
35: ; preds = %10
ret void
}

LLVM IR (-O2):
%struct.input_event = type { i32, i32, i32 }
@EV_KEY = global i32 0
define void @uinput_click(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.input_event
%5 = bitcast %struct.input_event* %4 to i8*
%6 = call i32 @memset(%struct.input_event* %4, i32 0, i32 12)
%7 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 2
%8 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 0
%9 = getelementptr inbounds %struct.input_event, %struct.input_event* %4, i64 0, i32 1
%10 = load i32, i32* @EV_KEY
store i32 %10, i32* %7
store i32 %1, i32* %8
%11 = and i32 %2, 1
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %3
store i32 130, i32* %9
%14 = call i32 @write(i32 %0, %struct.input_event* %4, i32 12)
%15 = load i32, i32* @EV_KEY
br label %16
16: ; preds = %3, %13
%17 = phi i32 [ %10, %3 ], [ %15, %13 ]
store i32 %17, i32* %7
store i32 %1, i32* %8
%18 = and i32 %2, 2
%19 = icmp eq i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
store i32 129, i32* %9
%21 = call i32 @write(i32 %0, %struct.input_event* %4, i32 12)
%22 = load i32, i32* @EV_KEY
br label %23
23: ; preds = %20, %16
%24 = phi i32 [ %22, %20 ], [ %17, %16 ]
store i32 %24, i32* %7
store i32 %1, i32* %8
%25 = and i32 %2, 4
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %23
store i32 128, i32* %9
%28 = call i32 @write(i32 %0, %struct.input_event* %4, i32 12)
br label %29
29: ; preds = %27, %23
ret void
}