#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 rand();
int /*<<< orphan*/ sendKey(int, int /*<<< orphan*/);
int /*<<< orphan*/ sendRel(int, int);
int send_gpio_keys(int, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ usleep(int);
int test_uinput(void) {
  int dx, dy;
  int i, k;
  srand(time(NULL));
  while (1) {
    switch (rand() % 4) {
    case 0:
      dx = -10;
      dy = -1;
      break;
    case 1:
      dx = 10;
      dy = 1;
      break;
    case 2:
      dx = -1;
      dy = 10;
      break;
    case 3:
      dx = 1;
      dy = -10;
      break;
    }
    k = send_gpio_keys(21, 1);
    sendKey(k, 0);
    for (i = 0; i < 20; i++) {
      sendRel(dx, dy);
      usleep(15000);
    }
    sleep(10);
  }
}


x86 assembly (clang, -O0):
<test_uinput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%edx
add    $0x3,%edx
test   %eax,%eax
mov    %eax,%ecx
cmovs  %edx,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     121a <test_uinput+0x9a>
mov    -0x18(%rbp),%rax
lea    0xe36(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xfffffff6,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
jmp    121a <test_uinput+0x9a>
movl   $0xa,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
jmp    121a <test_uinput+0x9a>
movl   $0xffffffff,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
jmp    121a <test_uinput+0x9a>
movl   $0x1,-0x4(%rbp)
movl   $0xfffffff6,-0x8(%rbp)
mov    $0x15,%edi
mov    $0x1,%esi
call   1030 <send_gpio_keys@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
xor    %esi,%esi
call   1060 <sendKey@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x14,-0xc(%rbp)
jge    126a <test_uinput+0xea>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    123d <test_uinput+0xbd>
mov    $0xa,%edi
call   1080 <sleep@plt>
jmp    1198 <test_uinput+0x18>

x86 assembly (clang, -O2):
<test_uinput>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
lea    0xe64(%rip),%r14
lea    0xe6d(%rip),%r15
jmp    134e <test_uinput+0x1ce>
nopl   0x0(%rax,%rax,1)
mov    $0x15,%edi
mov    $0x1,%esi
call   1030 <send_gpio_keys@plt>
mov    %eax,%edi
xor    %esi,%esi
call   1060 <sendKey@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1070 <sendRel@plt>
mov    $0x3a98,%edi
call   10a0 <usleep@plt>
mov    $0xa,%edi
call   1080 <sleep@plt>
xor    %eax,%eax
call   1090 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
cmp    $0x3,%eax
ja     11b0 <test_uinput+0x30>
cltq
mov    (%r14,%rax,4),%ebx
mov    (%r15,%rax,4),%ebp
jmp    11b0 <test_uinput+0x30>

LLVM IR (-O0):
define i32 @test_uinput() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
br label %7
7: ; preds = %0, %29
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 4
switch i32 %9, label %14 [
i32 0, label %10
i32 1, label %11
i32 2, label %12
i32 3, label %13
]
10: ; preds = %7
store i32 -10, i32* %1
store i32 -1, i32* %2
br label %14
11: ; preds = %7
store i32 10, i32* %1
store i32 1, i32* %2
br label %14
12: ; preds = %7
store i32 -1, i32* %1
store i32 10, i32* %2
br label %14
13: ; preds = %7
store i32 1, i32* %1
store i32 -10, i32* %2
br label %14
14: ; preds = %7, %13, %12, %11, %10
%15 = call i32 @send_gpio_keys(i32 21, i32 1)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = call i32 @sendKey(i32 %16, i32 0)
store i32 0, i32* %3
br label %18
18: ; preds = %26, %14
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 20
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = load i32, i32* %1
%23 = load i32, i32* %2
%24 = call i32 @sendRel(i32 %22, i32 %23)
%25 = call i32 @usleep(i32 15000)
br label %26
26: ; preds = %21
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %18
29: ; preds = %18
%30 = call i32 @sleep(i32 10)
br label %7
}

LLVM IR (-O2):
@switch.table.test_uinput = [4 x i32] [i32 -1, i32 1, i32 10, i32 -10]
@switch.table.test_uinput.1 = [4 x i32] [i32 -10, i32 10, i32 -1, i32 1]
define i32 @test_uinput() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
br label %3
3: ; preds = %16, %0
%4 = phi i32 [ undef, %0 ], [ %17, %16 ]
%5 = phi i32 [ undef, %0 ], [ %18, %16 ]
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 4
%8 = icmp ult i32 %7, 4
br i1 %8, label %9, label %16
9: ; preds = %3
%10 = sext i32 %7 to i64
%11 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.test_uinput, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = sext i32 %7 to i64
%14 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.test_uinput.1, i64 0, i64 %13
%15 = load i32, i32* %14
br label %16
16: ; preds = %9, %3
%17 = phi i32 [ %4, %3 ], [ %12, %9 ]
%18 = phi i32 [ %5, %3 ], [ %15, %9 ]
%19 = tail call i32 @send_gpio_keys(i32 21, i32 1)
%20 = tail call i32 @sendKey(i32 %19, i32 0)
%21 = tail call i32 @sendRel(i32 %18, i32 %17)
%22 = tail call i32 @usleep(i32 15000)
%23 = tail call i32 @sendRel(i32 %18, i32 %17)
%24 = tail call i32 @usleep(i32 15000)
%25 = tail call i32 @sendRel(i32 %18, i32 %17)
%26 = tail call i32 @usleep(i32 15000)
%27 = tail call i32 @sendRel(i32 %18, i32 %17)
%28 = tail call i32 @usleep(i32 15000)
%29 = tail call i32 @sendRel(i32 %18, i32 %17)
%30 = tail call i32 @usleep(i32 15000)
%31 = tail call i32 @sendRel(i32 %18, i32 %17)
%32 = tail call i32 @usleep(i32 15000)
%33 = tail call i32 @sendRel(i32 %18, i32 %17)
%34 = tail call i32 @usleep(i32 15000)
%35 = tail call i32 @sendRel(i32 %18, i32 %17)
%36 = tail call i32 @usleep(i32 15000)
%37 = tail call i32 @sendRel(i32 %18, i32 %17)
%38 = tail call i32 @usleep(i32 15000)
%39 = tail call i32 @sendRel(i32 %18, i32 %17)
%40 = tail call i32 @usleep(i32 15000)
%41 = tail call i32 @sendRel(i32 %18, i32 %17)
%42 = tail call i32 @usleep(i32 15000)
%43 = tail call i32 @sendRel(i32 %18, i32 %17)
%44 = tail call i32 @usleep(i32 15000)
%45 = tail call i32 @sendRel(i32 %18, i32 %17)
%46 = tail call i32 @usleep(i32 15000)
%47 = tail call i32 @sendRel(i32 %18, i32 %17)
%48 = tail call i32 @usleep(i32 15000)
%49 = tail call i32 @sendRel(i32 %18, i32 %17)
%50 = tail call i32 @usleep(i32 15000)
%51 = tail call i32 @sendRel(i32 %18, i32 %17)
%52 = tail call i32 @usleep(i32 15000)
%53 = tail call i32 @sendRel(i32 %18, i32 %17)
%54 = tail call i32 @usleep(i32 15000)
%55 = tail call i32 @sendRel(i32 %18, i32 %17)
%56 = tail call i32 @usleep(i32 15000)
%57 = tail call i32 @sendRel(i32 %18, i32 %17)
%58 = tail call i32 @usleep(i32 15000)
%59 = tail call i32 @sendRel(i32 %18, i32 %17)
%60 = tail call i32 @usleep(i32 15000)
%61 = tail call i32 @sleep(i32 10)
br label %3
}