#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 timeval {
  int dummy;
};
struct input_event {
  int value;
  int code;
  int /*<<< orphan*/ type;
  struct timeval time;
};
typedef int /*<<< orphan*/ ev;

/* Variables and functions */
int /*<<< orphan*/ EV_REL;
int /*<<< orphan*/ O_WRONLY;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ write(int, struct input_event *, int);
main(int argc, char **argv) {
  if (argc != 4) {
    printf("Usage: %s fifo axis amount\n\n", argv[0]);
    printf("Populates an input_event struct and writes it to the file\n"
           "fifo (which will generally be a named pipe), with type set\n"
           "to EV_REL, code set to axis (0,1,2,3,4,5 = x,y,z,pitch,yaw,roll)\n"
           "and amount set to the specified (integer) amount.\n\n"
           "Example: %s my-named-pipe 0 100\n"
           " writes a relative input_event with x=100\n\n"
           "Example: %s my-named-pipe 3 -10\n"
           " writes a relative input_event with pitch=-10\n",
           argv[0], argv[0]);
    exit(2);
  }
  int fd;
  if ((fd = open(argv[1], O_WRONLY)) < 0) {
    perror("opening the file you specified");
    exit(1);
  }
  int axis = atoi(argv[2]);
  int amount = atoi(argv[3]);
  struct input_event ev;
  struct input_event *event_data = &ev;
  struct timeval timestamp;
  gettimeofday(&timestamp, NULL);
  ev.time = timestamp;
  ev.type = EV_REL;
  ev.value = amount;
  ev.code = axis;
  printf("Writing an input_event with type=EV_REL, value=%d and code=%d\n",
         ev.value, ev.code);
  write(fd, event_data, sizeof(ev));
  printf("Done.\n");
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x4(%rbp)
je     11d4 <main+0x54>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    120c <main+0x8c>
lea    0xfa3(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x40(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xf53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
lea    0xf73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    1238 <main+0xa8>
mov    0x8(%rbx),%rdi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     1267 <main+0xd7>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebp
mov    0x18(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebx
lea    0xc(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %ebx,(%rsp)
mov    %ebp,0x4(%rsp)
lea    0xfc1(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x10,%edx
call   1040 <write@plt>
lea    0xfde(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xdbe(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rdx
lea    0xdca(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
lea    0xf32(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.input_event = type { i32, i32, i32, %struct.timeval }
%struct.timeval = type { i32 }
@.str = [29 x i8] c"Usage: %s fifo axis amount\0A\0A\00"
@.str.1 = [387 x i8] c"Populates an input_event struct and writes it to the file\0Afifo (which will generally be a named pipe), with type set\0Ato EV_REL, code set to axis (0,1,2,3,4,5 = x,y,z,pitch,yaw,roll)\0Aand amount set to the specified (integer) amount.\0A\0AExample: %s my-named-pipe 0 100\0A writes a relative input_event with x=100\0A\0AExample: %s my-named-pipe 3 -10\0A writes a relative input_event with pitch=-10\0A\00"
@O_WRONLY = global i32 0
@.str.2 = [31 x i8] c"opening the file you specified\00"
@EV_REL = global i32 0
@.str.3 = [63 x i8] c"Writing an input_event with type=EV_REL, value=%d and code=%d\0A\00"
@.str.4 = [7 x i8] c"Done.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.input_event
%9 = alloca %struct.input_event*
%10 = alloca %struct.timeval
store i32 %0, i32* %3
store i8** %1, i8*** %4
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 4
br i1 %12, label %13, label %26
13: ; preds = %2
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i8**, i8*** %4
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([387 x i8], [387 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %23)
%25 = call i32 @exit(i32 2)
unreachable
26: ; preds = %2
%27 = load i8**, i8*** %4
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = load i32, i32* @O_WRONLY
%31 = call i32 @open(i8* %29, i32 %30)
store i32 %31, i32* %5
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %26
%37 = load i8**, i8*** %4
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %6
%41 = load i8**, i8*** %4
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
store i32 %44, i32* %7
store %struct.input_event* %8, %struct.input_event** %9
%45 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%46 = getelementptr inbounds %struct.input_event, %struct.input_event* %8, i32 0, i32 3
%47 = bitcast %struct.timeval* %46 to i8*
%48 = bitcast %struct.timeval* %10 to i8*
%49 = load i32, i32* @EV_REL
%50 = getelementptr inbounds %struct.input_event, %struct.input_event* %8, i32 0, i32 2
store i32 %49, i32* %50
%51 = load i32, i32* %7
%52 = getelementptr inbounds %struct.input_event, %struct.input_event* %8, i32 0, i32 0
store i32 %51, i32* %52
%53 = load i32, i32* %6
%54 = getelementptr inbounds %struct.input_event, %struct.input_event* %8, i32 0, i32 1
store i32 %53, i32* %54
%55 = getelementptr inbounds %struct.input_event, %struct.input_event* %8, i32 0, i32 0
%56 = load i32, i32* %55
%57 = getelementptr inbounds %struct.input_event, %struct.input_event* %8, i32 0, i32 1
%58 = load i32, i32* %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0), i32 %56, i32 %58)
%60 = load i32, i32* %5
%61 = load %struct.input_event*, %struct.input_event** %9
%62 = call i32 @write(i32 %60, %struct.input_event* %61, i32 16)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%64 = load i32, i32* %5
%65 = call i32 @close(i32 %64)
ret i32 0
}

LLVM IR (-O2):
%struct.input_event = type { i32, i32, i32, %struct.timeval }
%struct.timeval = type { i32 }
@.str = [29 x i8] c"Usage: %s fifo axis amount\0A\0A\00"
@.str.1 = [387 x i8] c"Populates an input_event struct and writes it to the file\0Afifo (which will generally be a named pipe), with type set\0Ato EV_REL, code set to axis (0,1,2,3,4,5 = x,y,z,pitch,yaw,roll)\0Aand amount set to the specified (integer) amount.\0A\0AExample: %s my-named-pipe 0 100\0A writes a relative input_event with x=100\0A\0AExample: %s my-named-pipe 3 -10\0A writes a relative input_event with pitch=-10\0A\00"
@O_WRONLY = global i32 0
@.str.2 = [31 x i8] c"opening the file you specified\00"
@EV_REL = global i32 0
@.str.3 = [63 x i8] c"Writing an input_event with type=EV_REL, value=%d and code=%d\0A\00"
@str = [6 x i8] c"Done.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.input_event
%4 = icmp eq i32 %0, 4
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([387 x i8], [387 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %8)
%10 = tail call i32 @exit(i32 2)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_WRONLY
%15 = tail call i32 @open(i8* %13, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %11
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32 @atoi(i8* %22)
%24 = getelementptr inbounds i8*, i8** %1, i64 3
%25 = load i8*, i8** %24
%26 = tail call i32 @atoi(i8* %25)
%27 = bitcast %struct.input_event* %3 to i8*
%28 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 3, i32 0
%29 = bitcast i32* %28 to %struct.timeval*
%30 = call i32 @gettimeofday(%struct.timeval* %29, i32* null)
%31 = load i32, i32* @EV_REL
%32 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 2
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 0
store i32 %26, i32* %33
%34 = getelementptr inbounds %struct.input_event, %struct.input_event* %3, i64 0, i32 1
store i32 %23, i32* %34
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 %23)
%36 = call i32 @write(i32 %15, %struct.input_event* %3, i32 16)
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%38 = tail call i32 @close(i32 %15)
ret i32 0
}