#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_REL;
int /*<<< orphan*/ EV_SYN;
int /*<<< orphan*/ REL_HWHEEL;
int /*<<< orphan*/ REL_WHEEL;
int /*<<< orphan*/ SYN_REPORT;
int /*<<< orphan*/ dbg(int, char *, char *);
int /*<<< orphan*/ input_event(int /*<<< orphan*/, int /*<<< orphan*/, int);
void send_a_scroll(int x, int y) {
  if (x) {
    dbg(1, "scroll %s", y > 0 ? "left" : "right");
    input_event(EV_REL, REL_HWHEEL, x > 0 ? -1 : 1);
  }
  if (y) {
    dbg(1, "scroll %s", y > 0 ? "up" : "down");
    input_event(EV_REL, REL_WHEEL, y > 0 ? -1 : 1);
  }
  input_event(EV_SYN, SYN_REPORT, 0);
}


x86 assembly (clang, -O0):
<send_a_scroll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     118b <send_a_scroll+0x6b>
mov    -0x8(%rbp),%ecx
lea    0xecd(%rip),%rdx
lea    0xec1(%rip),%rax
cmp    $0x0,%ecx
cmovg  %rax,%rdx
mov    $0x1,%edi
lea    0xea4(%rip),%rsi
call   1030 <dbg@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    -0x4(%rbp),%ecx
mov    $0x1,%edx
mov    $0xffffffff,%eax
cmp    $0x0,%ecx
cmovg  %eax,%edx
call   1040 <input_event@plt>
cmpl   $0x0,-0x8(%rbp)
je     11e8 <send_a_scroll+0xc8>
mov    -0x8(%rbp),%ecx
lea    0xe79(%rip),%rdx
lea    0xe6f(%rip),%rax
cmp    $0x0,%ecx
cmovg  %rax,%rdx
mov    $0x1,%edi
lea    0xe47(%rip),%rsi
call   1030 <dbg@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
mov    $0xffffffff,%eax
cmp    $0x0,%ecx
cmovg  %eax,%edx
call   1040 <input_event@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <input_event@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_a_scroll>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
test   %edi,%edi
je     1174 <send_a_scroll+0x54>
mov    %edi,%ebp
test   %ebx,%ebx
lea    0xed6(%rip),%rax
lea    0xed4(%rip),%rdx
cmovg  %rax,%rdx
lea    0xeba(%rip),%rsi
mov    $0x1,%edi
call   1030 <dbg@plt>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
test   %ebp,%ebp
setle  %al
lea    (%rax,%rax,1),%edx
add    $0xffffffff,%edx
call   1040 <input_event@plt>
test   %ebx,%ebx
je     11be <send_a_scroll+0x9e>
setle  %bl
lea    0xe93(%rip),%rax
lea    0xe8f(%rip),%rdx
cmovg  %rax,%rdx
lea    0xe6c(%rip),%rsi
mov    $0x1,%edi
call   1030 <dbg@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
movzbl %bl,%eax
lea    (%rax,%rax,1),%edx
add    $0xffffffff,%edx
call   1040 <input_event@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <input_event@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"scroll %s\00"
@.str.1 = [5 x i8] c"left\00"
@.str.2 = [6 x i8] c"right\00"
@EV_REL = global i32 0
@REL_HWHEEL = global i32 0
@.str.3 = [3 x i8] c"up\00"
@.str.4 = [5 x i8] c"down\00"
@REL_WHEEL = global i32 0
@EV_SYN = global i32 0
@SYN_REPORT = global i32 0
define void @send_a_scroll(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %2
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 0
%10 = zext i1 %9 to i64
%11 = select i1 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%12 = call i32 @dbg(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EV_REL
%14 = load i32, i32* @REL_HWHEEL
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i32 -1, i32 1
%19 = call i32 @input_event(i32 %13, i32 %14, i32 %18)
br label %20
20: ; preds = %7, %2
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %20
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%28 = call i32 @dbg(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EV_REL
%30 = load i32, i32* @REL_WHEEL
%31 = load i32, i32* %4
%32 = icmp sgt i32 %31, 0
%33 = zext i1 %32 to i64
%34 = select i1 %32, i32 -1, i32 1
%35 = call i32 @input_event(i32 %29, i32 %30, i32 %34)
br label %36
36: ; preds = %23, %20
%37 = load i32, i32* @EV_SYN
%38 = load i32, i32* @SYN_REPORT
%39 = call i32 @input_event(i32 %37, i32 %38, i32 0)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"scroll %s\00"
@.str.1 = [5 x i8] c"left\00"
@.str.2 = [6 x i8] c"right\00"
@EV_REL = global i32 0
@REL_HWHEEL = global i32 0
@.str.3 = [3 x i8] c"up\00"
@.str.4 = [5 x i8] c"down\00"
@REL_WHEEL = global i32 0
@EV_SYN = global i32 0
@SYN_REPORT = global i32 0
define void @send_a_scroll(i32 %0, i32 %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = icmp sgt i32 %1, 0
%6 = select i1 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%7 = tail call i32 @dbg(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EV_REL
%9 = load i32, i32* @REL_HWHEEL
%10 = icmp slt i32 %0, 1
%11 = select i1 %10, i32 1, i32 -1
%12 = tail call i32 @input_event(i32 %8, i32 %9, i32 %11)
br label %13
13: ; preds = %4, %2
%14 = icmp eq i32 %1, 0
br i1 %14, label %23, label %15
15: ; preds = %13
%16 = icmp sgt i32 %1, 0
%17 = select i1 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
%18 = tail call i32 @dbg(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EV_REL
%20 = load i32, i32* @REL_WHEEL
%21 = select i1 %16, i32 -1, i32 1
%22 = tail call i32 @input_event(i32 %19, i32 %20, i32 %21)
br label %23
23: ; preds = %15, %13
%24 = load i32, i32* @EV_SYN
%25 = load i32, i32* @SYN_REPORT
%26 = tail call i32 @input_event(i32 %24, i32 %25, i32 0)
ret void
}