#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_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint8_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  void *sin_port;
  TYPE_1__ sin_addr;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
struct js_event {
  int type;
  size_t number;
  int value;
};
typedef int int16_t;
typedef int /*<<< orphan*/ caddr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ JSIOCGAXES;
int /*<<< orphan*/ JSIOCGBUTTONS;
int /*<<< orphan*/ JSIOCGNAME(int);
#define JS_EVENT_AXIS 129
#define JS_EVENT_BUTTON 128
int JS_EVENT_INIT;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ inet_pton(void *, char *, TYPE_1__ *);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, struct js_event *, int);
scalar_t__ sendto(int, int **, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int joy_fd, *axis = NULL, num_of_axis = 0, num_of_buttons = 0, x;
  char *button = NULL, name_of_joystick[80];
  struct js_event js;
  if ((joy_fd = open("/dev/input/js0", O_RDONLY)) == -1) {
    printf("Couldn't open joystick\n");
    return -1;
  }
  ioctl(joy_fd, JSIOCGAXES, &num_of_axis);
  ioctl(joy_fd, JSIOCGBUTTONS, &num_of_buttons);
  ioctl(joy_fd, JSIOCGNAME(80), &name_of_joystick);
  axis = (int *)calloc(num_of_axis, sizeof(int));
  button = (char *)calloc(num_of_buttons, sizeof(char));
  printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n", name_of_joystick,
         num_of_axis, num_of_buttons);
  int sock;
  struct sockaddr_in saddr, caddr;
  uint8_t i;
  int16_t buf[4];
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock < 0) {
    perror("ERROR:");
    exit(-1);
  }
  caddr.sin_family = AF_INET;
  caddr.sin_addr.s_addr = htonl(INADDR_ANY);
  caddr.sin_port = htons(0);
  saddr.sin_family = AF_INET;
  inet_pton(AF_INET, "10.2.110.201", &(saddr.sin_addr));
  saddr.sin_port = htons(25000);
  if (bind(sock, (struct sockaddr *)&caddr, sizeof(caddr)) < 0) {
    perror("ERROR:");
    exit(-1);
  }
  while (1) {
    read(joy_fd, &js, sizeof(struct js_event));
    switch (js.type & ~JS_EVENT_INIT) {
    case JS_EVENT_AXIS:
      axis[js.number] = js.value;
      break;
    case JS_EVENT_BUTTON:
      button[js.number] = js.value;
      break;
    }
    memset(buf, 0, sizeof(buf));
    buf[0] = axis[0];
    buf[1] = axis[1];
    buf[2] = axis[3];
    buf[3] = axis[4];
    if (sendto(sock, &buf, sizeof(buf), 0, (struct sockaddr *)&saddr,
               sizeof saddr) < 0) {
      perror("ERROR:");
      exit(-1);
    }
    printf("%d %d %d %d\n", buf[0], buf[1], buf[2], buf[3]);
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
lea    0xdc9(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1264 <main+0x74>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x110,%rsp
pop    %rbp
ret
mov    -0x14(%rbp),%edi
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
lea    -0x24(%rbp),%rdx
mov    $0x0,%al
call   1070 <ioctl@plt>
mov    -0x14(%rbp),%edi
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1070 <ioctl@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x104(%rbp)
mov    $0x50,%edi
call   1100 <JSIOCGNAME@plt>
mov    -0x104(%rbp),%edi
mov    %eax,%esi
lea    -0x90(%rbp),%rdx
mov    $0x0,%al
call   1070 <ioctl@plt>
mov    -0x24(%rbp),%edi
mov    $0x4,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x38(%rbp)
lea    -0x90(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xd36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%rdi
mov    0x2cc7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0xac(%rbp)
cmpl   $0x0,-0xac(%rbp)
jge    133b <main+0x14b>
lea    0xd28(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xd0(%rbp)
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0xd8(%rbp)
xor    %edi,%edi
call   1030 <htons@plt>
mov    %rax,-0xe0(%rbp)
mov    0x2c73(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xb8(%rbp)
mov    0x2c62(%rip),%rax
mov    (%rax),%rdi
lea    -0xc8(%rbp),%rdx
add    $0x8,%rdx
lea    0xcc0(%rip),%rsi
call   10b0 <inet_pton@plt>
mov    $0x61a8,%edi
call   1030 <htons@plt>
mov    %rax,-0xc8(%rbp)
mov    -0xac(%rbp),%edi
lea    -0xe0(%rbp),%rsi
mov    $0x18,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    13e8 <main+0x1f8>
lea    0xc7b(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
jmp    13ed <main+0x1fd>
mov    -0x14(%rbp),%edi
lea    -0xa8(%rbp),%rsi
mov    $0x18,%edx
call   1090 <read@plt>
mov    -0xa8(%rbp),%eax
mov    0x2ba2(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %ecx,%eax
mov    %eax,-0x108(%rbp)
sub    $0x80,%eax
je     1459 <main+0x269>
jmp    142a <main+0x23a>
mov    -0x108(%rbp),%eax
sub    $0x81,%eax
jne    146f <main+0x27f>
jmp    1440 <main+0x250>
mov    -0x98(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    -0xa0(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    146f <main+0x27f>
mov    -0x98(%rbp),%eax
mov    %al,%dl
mov    -0x38(%rbp),%rax
mov    -0xa0(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
lea    -0x100(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x100(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0xfc(%rbp)
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0xf8(%rbp)
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0xf4(%rbp)
mov    -0xac(%rbp),%edi
lea    -0x100(%rbp),%rsi
lea    -0xc8(%rbp),%r8
mov    $0x10,%edx
xor    %ecx,%ecx
mov    $0x18,%r9d
call   1080 <sendto@plt>
cmp    $0x0,%rax
jge    14fb <main+0x30b>
lea    0xb68(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x100(%rbp),%esi
mov    -0xfc(%rbp),%edx
mov    -0xf8(%rbp),%ecx
mov    -0xf4(%rbp),%r8d
lea    0xb4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13ed <main+0x1fd>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
lea    0xdcf(%rip),%rdi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
jne    125e <main+0x5e>
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
mov    0x2d59(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1080 <ioctl@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1080 <ioctl@plt>
mov    $0x50,%edi
call   1110 <JSIOCGNAME@plt>
lea    0x70(%rsp),%rbp
mov    %ebx,%edi
mov    %eax,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <ioctl@plt>
mov    0xc(%rsp),%edi
mov    $0x4,%esi
call   10b0 <calloc@plt>
mov    %rax,%r14
mov    0x8(%rsp),%edi
mov    $0x1,%esi
call   10b0 <calloc@plt>
mov    %rax,0x20(%rsp)
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
lea    0xd31(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2cf9(%rip),%rbp
mov    0x0(%rbp),%rdi
mov    0x2cd6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
test   %eax,%eax
js     1371 <main+0x171>
mov    %eax,%r13d
mov    0x0(%rbp),%rax
mov    %rax,0x50(%rsp)
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0x48(%rsp)
xor    %edi,%edi
call   1040 <htons@plt>
mov    %rax,0x40(%rsp)
mov    0x0(%rbp),%rdi
mov    %rdi,0x68(%rsp)
lea    0x60(%rsp),%rdx
lea    0xcfd(%rip),%rsi
call   10c0 <inet_pton@plt>
mov    $0x61a8,%edi
call   1040 <htons@plt>
mov    %rax,0x58(%rsp)
lea    0x40(%rsp),%rsi
mov    %r13d,%edi
mov    $0x18,%edx
call   10d0 <bind@plt>
test   %rax,%rax
jns    1387 <main+0x187>
lea    0xcc4(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%edi
call   1100 <exit@plt>
lea    0x10(%rsp),%rbp
lea    0x58(%rsp),%r15
lea    0xcb8(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
lea    0x28(%rsp),%rsi
mov    $0x18,%edx
call   10a0 <read@plt>
mov    0x2bf8(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x28(%rsp),%eax
cmp    $0x80,%eax
je     13dd <main+0x1dd>
cmp    $0x81,%eax
jne    13ef <main+0x1ef>
mov    0x38(%rsp),%eax
mov    0x30(%rsp),%rcx
mov    %eax,(%r14,%rcx,4)
jmp    13ef <main+0x1ef>
movzbl 0x38(%rsp),%eax
mov    0x30(%rsp),%rcx
mov    0x20(%rsp),%rdx
mov    %al,(%rdx,%rcx,1)
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
movsd  (%r14),%xmm0
movsd  0xc(%r14),%xmm1
movlhps %xmm1,%xmm0
movaps %xmm0,0x10(%rsp)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0x10,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x18,%r9d
call   1090 <sendto@plt>
test   %rax,%rax
js     1371 <main+0x171>
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
mov    0x18(%rsp),%ecx
mov    0x1c(%rsp),%r8d
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    13a0 <main+0x1a0>

LLVM IR (-O0):
%struct.js_event = type { i32, i64, i32 }
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"/dev/input/js0\00"
@O_RDONLY = global i32 0
@.str.1 = [24 x i8] c"Couldn't open joystick\0A\00"
@JSIOCGAXES = global i32 0
@JSIOCGBUTTONS = global i32 0
@.str.2 = [45 x i8] c"Joystick detected: %s\0A\09%d axis\0A\09%d buttons\0A\0A\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@.str.3 = [7 x i8] c"ERROR:\00"
@INADDR_ANY = global i32 0
@.str.4 = [13 x i8] c"10.2.110.201\00"
@JS_EVENT_INIT = global i32 0
@.str.5 = [13 x i8] c"%d %d %d %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca [80 x i8]
%13 = alloca %struct.js_event
%14 = alloca i32
%15 = alloca %struct.sockaddr_in
%16 = alloca %struct.sockaddr_in
%17 = alloca i32
%18 = alloca [4 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %7
store i32 0, i32* %8
store i32 0, i32* %9
store i8* null, i8** %11
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 %20, i32* %6
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
ret i32 -1
24: ; preds = %2
%25 = load i32, i32* %6
%26 = load i32, i32* @JSIOCGAXES
%27 = call i32 (i32, i32, ...) @ioctl(i32 %25, i32 %26, i32* %8)
%28 = load i32, i32* %6
%29 = load i32, i32* @JSIOCGBUTTONS
%30 = call i32 (i32, i32, ...) @ioctl(i32 %28, i32 %29, i32* %9)
%31 = load i32, i32* %6
%32 = call i32 @JSIOCGNAME(i32 80)
%33 = call i32 (i32, i32, ...) @ioctl(i32 %31, i32 %32, [80 x i8]* %12)
%34 = load i32, i32* %8
%35 = call i64 @calloc(i32 %34, i32 4)
%36 = inttoptr i64 %35 to i32*
store i32* %36, i32** %7
%37 = load i32, i32* %9
%38 = call i64 @calloc(i32 %37, i32 1)
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %11
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%41 = load i32, i32* %8
%42 = load i32, i32* %9
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %40, i32 %41, i32 %42)
%44 = load i8*, i8** @AF_INET
%45 = load i32, i32* @SOCK_DGRAM
%46 = call i32 @socket(i8* %44, i32 %45, i32 0)
store i32 %46, i32* %14
%47 = load i32, i32* %14
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %24
%50 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%51 = call i32 @exit(i32 -1)
unreachable
52: ; preds = %24
%53 = load i8*, i8** @AF_INET
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 2
store i8* %53, i8** %54
%55 = load i32, i32* @INADDR_ANY
%56 = call i32 @htonl(i32 %55)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 1
%58 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %57, i32 0, i32 0
store i32 %56, i32* %58
%59 = call i8* @htons(i32 0)
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 0
store i8* %59, i8** %60
%61 = load i8*, i8** @AF_INET
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 2
store i8* %61, i8** %62
%63 = load i8*, i8** @AF_INET
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 1
%65 = call i32 @inet_pton(i8* %63, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), %struct.TYPE_2__* %64)
%66 = call i8* @htons(i32 25000)
%67 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 0
store i8* %66, i8** %67
%68 = load i32, i32* %14
%69 = bitcast %struct.sockaddr_in* %16 to %struct.sockaddr*
%70 = call i64 @bind(i32 %68, %struct.sockaddr* %69, i32 24)
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %52
%73 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%74 = call i32 @exit(i32 -1)
unreachable
75: ; preds = %52
br label %76
76: ; preds = %75, %126
%77 = load i32, i32* %6
%78 = call i32 @read(i32 %77, %struct.js_event* %13, i32 24)
%79 = getelementptr inbounds %struct.js_event, %struct.js_event* %13, i32 0, i32 0
%80 = load i32, i32* %79
%81 = load i32, i32* @JS_EVENT_INIT
%82 = xor i32 %81, -1
%83 = and i32 %80, %82
switch i32 %83, label %99 [
i32 129, label %84
i32 128, label %91
]
84: ; preds = %76
%85 = getelementptr inbounds %struct.js_event, %struct.js_event* %13, i32 0, i32 2
%86 = load i32, i32* %85
%87 = load i32*, i32** %7
%88 = getelementptr inbounds %struct.js_event, %struct.js_event* %13, i32 0, i32 1
%89 = load i64, i64* %88
%90 = getelementptr inbounds i32, i32* %87, i64 %89
store i32 %86, i32* %90
br label %99
91: ; preds = %76
%92 = getelementptr inbounds %struct.js_event, %struct.js_event* %13, i32 0, i32 2
%93 = load i32, i32* %92
%94 = trunc i32 %93 to i8
%95 = load i8*, i8** %11
%96 = getelementptr inbounds %struct.js_event, %struct.js_event* %13, i32 0, i32 1
%97 = load i64, i64* %96
%98 = getelementptr inbounds i8, i8* %95, i64 %97
store i8 %94, i8* %98
br label %99
99: ; preds = %76, %91, %84
%100 = getelementptr inbounds [4 x i32], [4 x i32]* %18, i64 0, i64 0
%101 = call i32 @memset(i32* %100, i32 0, i32 16)
%102 = load i32*, i32** %7
%103 = getelementptr inbounds i32, i32* %102, i64 0
%104 = load i32, i32* %103
%105 = getelementptr inbounds [4 x i32], [4 x i32]* %18, i64 0, i64 0
store i32 %104, i32* %105
%106 = load i32*, i32** %7
%107 = getelementptr inbounds i32, i32* %106, i64 1
%108 = load i32, i32* %107
%109 = getelementptr inbounds [4 x i32], [4 x i32]* %18, i64 0, i64 1
store i32 %108, i32* %109
%110 = load i32*, i32** %7
%111 = getelementptr inbounds i32, i32* %110, i64 3
%112 = load i32, i32* %111
%113 = getelementptr inbounds [4 x i32], [4 x i32]* %18, i64 0, i64 2
store i32 %112, i32* %113
%114 = load i32*, i32** %7
%115 = getelementptr inbounds i32, i32* %114, i64 4
%116 = load i32, i32* %115
%117 = getelementptr inbounds [4 x i32], [4 x i32]* %18, i64 0, i64 3
store i32 %116, i32* %117
%118 = load i32, i32* %14
%119 = bitcast [4 x i32]* %18 to i32**
%120 = bitcast %struct.sockaddr_in* %15 to %struct.sockaddr*
%121 = call i64 @sendto(i32 %118, i32** %119, i32 16, i32 0, %struct.sockaddr* %120, i32 24)
%122 = icmp slt i64 %121, 0
br i1 %122, label %123, label %126
123: ; preds = %99
%124 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%125 = call i32 @exit(i32 -1)
unreachable
126: ; preds = %99
%127 = getelementptr inbounds [4 x i32], [4 x i32]* %18, i64 0, i64 0
%128 = load i32, i32* %127
%129 = getelementptr inbounds [4 x i32], [4 x i32]* %18, i64 0, i64 1
%130 = load i32, i32* %129
%131 = getelementptr inbounds [4 x i32], [4 x i32]* %18, i64 0, i64 2
%132 = load i32, i32* %131
%133 = getelementptr inbounds [4 x i32], [4 x i32]* %18, i64 0, i64 3
%134 = load i32, i32* %133
%135 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %128, i32 %130, i32 %132, i32 %134)
br label %76
}

LLVM IR (-O2):
%struct.js_event = type { i32, i64, i32 }
%struct.sockaddr_in = type { i8*, %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"/dev/input/js0\00"
@O_RDONLY = global i32 0
@JSIOCGAXES = global i32 0
@JSIOCGBUTTONS = global i32 0
@.str.2 = [45 x i8] c"Joystick detected: %s\0A\09%d axis\0A\09%d buttons\0A\0A\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@.str.3 = [7 x i8] c"ERROR:\00"
@INADDR_ANY = global i32 0
@.str.4 = [13 x i8] c"10.2.110.201\00"
@JS_EVENT_INIT = global i32 0
@.str.5 = [13 x i8] c"%d %d %d %d\0A\00"
@str = [23 x i8] c"Couldn't open joystick\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [80 x i8]
%6 = alloca %struct.js_event
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = alloca <4 x i32>
%10 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%11 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%13 = bitcast %struct.js_event* %6 to i8*
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
ret i32 -1
19: ; preds = %2
%20 = load i32, i32* @JSIOCGAXES
%21 = call i32 (i32, i32, ...) @ioctl(i32 %15, i32 %20, i32* %3)
%22 = load i32, i32* @JSIOCGBUTTONS
%23 = call i32 (i32, i32, ...) @ioctl(i32 %15, i32 %22, i32* %4)
%24 = call i32 @JSIOCGNAME(i32 80)
%25 = call i32 (i32, i32, ...) @ioctl(i32 %15, i32 %24, [80 x i8]* %5)
%26 = load i32, i32* %3
%27 = call i64 @calloc(i32 %26, i32 4)
%28 = inttoptr i64 %27 to i32*
%29 = load i32, i32* %4
%30 = call i64 @calloc(i32 %29, i32 1)
%31 = inttoptr i64 %30 to i8*
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %12, i32 %32, i32 %33)
%35 = bitcast %struct.sockaddr_in* %7 to i8*
%36 = bitcast %struct.sockaddr_in* %8 to i8*
%37 = bitcast <4 x i32>* %9 to i8*
%38 = load i8*, i8** @AF_INET
%39 = load i32, i32* @SOCK_DGRAM
%40 = call i32 @socket(i8* %38, i32 %39, i32 0)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %19
%43 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 @exit(i32 -1)
unreachable
45: ; preds = %19
%46 = load i8*, i8** @AF_INET
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 2
store i8* %46, i8** %47
%48 = load i32, i32* @INADDR_ANY
%49 = call i32 @htonl(i32 %48)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 1, i32 0
store i32 %49, i32* %50
%51 = call i8* @htons(i32 0)
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 0
store i8* %51, i8** %52
%53 = load i8*, i8** @AF_INET
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
store i8* %53, i8** %54
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1
%56 = call i32 @inet_pton(i8* %53, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), %struct.TYPE_2__* %55)
%57 = call i8* @htons(i32 25000)
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
store i8* %57, i8** %58
%59 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%60 = call i64 @bind(i32 %40, %struct.sockaddr* %59, i32 24)
%61 = icmp slt i64 %60, 0
br i1 %61, label %75, label %62
62: ; preds = %45
%63 = getelementptr inbounds %struct.js_event, %struct.js_event* %6, i64 0, i32 0
%64 = getelementptr inbounds %struct.js_event, %struct.js_event* %6, i64 0, i32 2
%65 = getelementptr inbounds %struct.js_event, %struct.js_event* %6, i64 0, i32 1
%66 = getelementptr inbounds <4 x i32>, <4 x i32>* %9, i64 0, i64 0
%67 = getelementptr inbounds <4 x i32>, <4 x i32>* %9, i64 0, i64 1
%68 = getelementptr inbounds i32, i32* %28, i64 3
%69 = getelementptr inbounds <4 x i32>, <4 x i32>* %9, i64 0, i64 2
%70 = getelementptr inbounds <4 x i32>, <4 x i32>* %9, i64 0, i64 3
%71 = bitcast <4 x i32>* %9 to i32**
%72 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%73 = inttoptr i64 %27 to <2 x i32>*
%74 = bitcast i32* %68 to <2 x i32>*
br label %78
75: ; preds = %45
%76 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%77 = call i32 @exit(i32 -1)
unreachable
78: ; preds = %62, %103
%79 = call i32 @read(i32 %15, %struct.js_event* %6, i32 24)
%80 = load i32, i32* %63
%81 = load i32, i32* @JS_EVENT_INIT
%82 = xor i32 %81, -1
%83 = and i32 %80, %82
switch i32 %83, label %93 [
i32 129, label %84
i32 128, label %88
]
84: ; preds = %78
%85 = load i32, i32* %64
%86 = load i64, i64* %65
%87 = getelementptr inbounds i32, i32* %28, i64 %86
store i32 %85, i32* %87
br label %93
88: ; preds = %78
%89 = load i32, i32* %64
%90 = trunc i32 %89 to i8
%91 = load i64, i64* %65
%92 = getelementptr inbounds i8, i8* %31, i64 %91
store i8 %90, i8* %92
br label %93
93: ; preds = %78, %88, %84
%94 = call i32 @memset(i32* %66, i32 0, i32 16)
%95 = load <2 x i32>, <2 x i32>* %73
%96 = load <2 x i32>, <2 x i32>* %74
%97 = shufflevector <2 x i32> %95, <2 x i32> %96, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
store <4 x i32> %97, <4 x i32>* %9
%98 = call i64 @sendto(i32 %40, i32** %71, i32 16, i32 0, %struct.sockaddr* %72, i32 24)
%99 = icmp slt i64 %98, 0
br i1 %99, label %100, label %103
100: ; preds = %93
%101 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%102 = call i32 @exit(i32 -1)
unreachable
103: ; preds = %93
%104 = load i32, i32* %66
%105 = load i32, i32* %67
%106 = load i32, i32* %69
%107 = load i32, i32* %70
%108 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %104, i32 %105, i32 %106, i32 %107)
br label %78
}