#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 js_event {
  int type;
  size_t number;
  int value;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ JSIOCGAXES;
int /*<<< orphan*/ JSIOCGBUTTONS;
int /*<<< orphan*/ JSIOCGNAME(int);
int /*<<< orphan*/ JSIOCGVERSION;
#define JS_EVENT_AXIS 129
#define JS_EVENT_BUTTON 128
int /*<<< orphan*/ O_RDONLY;
int *calloc(unsigned char, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int read(int, struct js_event *, int);
int /*<<< orphan*/ serialport_flush(int);
int serialport_init(char *, int);
int serialport_write(int, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  const int buf_max = 256;
  int timeout = 5000;
  int sp = -1;
  FILE *df = fopen("dump", "wb");
  int rc;
  int baudrate = 19200;
  char serialport[buf_max];
  char buf[buf_max];
  int fd;
  unsigned char axes = 2;
  unsigned char buttons = 2;
  int version = 0x000800;
  char name[128] = "Unknown";
  if (argc != 3 || !strcmp("--help", argv[1])) {
    puts("Usage: jscommander <jsdevice> <serialdevice>");
    exit(1);
  }
  if ((fd = open(argv[1], O_RDONLY)) < 0) {
    perror("jscommander: Unable to open joystick device");
    exit(1);
  }
  strcpy(serialport, argv[2]);
  if ((sp = serialport_init(serialport, baudrate)) < 0) {
    perror("jscommander: Unable to open serial device");
    exit(1);
  }
  serialport_flush(sp);
  ioctl(fd, JSIOCGVERSION, &version);
  ioctl(fd, JSIOCGAXES, &axes);
  ioctl(fd, JSIOCGBUTTONS, &buttons);
  ioctl(fd, JSIOCGNAME(128), name);
  printf(
      "Joystick (%s) has %d axes and %d buttons. Driver version is %d.%d.%d.\n",
      name, axes, buttons, version >> 16, (version >> 8) & 0xff,
      version & 0xff);
  printf("Running... (SIGINT to exit)\n");
  int *axis;
  int *button;
  int i;
  struct js_event js;
  axis = calloc(axes, sizeof(int));
  button = calloc(buttons, sizeof(char));
  while (1) {
    if (read(fd, &js, sizeof(struct js_event)) != sizeof(struct js_event)) {
      perror("jscommander: Error reading joystick device");
      exit(1);
    }
    switch (js.type) {
    case JS_EVENT_BUTTON:
      button[js.number] = js.value;
      break;
    case JS_EVENT_AXIS:
      axis[js.number] = js.value;
      break;
    }
    if (axes) {
      sprintf(buf, "%dx%dy", axis[0] / 364 + 90, axis[1] / 364 + 90);
      fprintf(df, "%s\n", buf);
      rc = serialport_write(sp, buf);
      if (rc == -1)
        perror("jscommander: Error writing to serial device");
    }
    fflush(df);
    fflush(stdout);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x320,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x100,-0x14(%rbp)
movl   $0x1388,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
lea    0xd9b(%rip),%rdi
lea    0xd99(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x4b00,-0x30(%rbp)
mov    %rsp,%rax
mov    %rax,-0x38(%rbp)
movb   $0x2,-0x3d(%rbp)
movb   $0x2,-0x3e(%rbp)
movl   $0x800,-0x44(%rbp)
lea    -0xd0(%rbp),%rdi
lea    0xec0(%rip),%rsi
mov    $0x80,%edx
call   10d0 <memcpy@plt>
cmpl   $0x3,-0x8(%rbp)
jne    12d1 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd45(%rip),%rdi
call   10b0 <strcmp@plt>
cmp    $0x0,%eax
jne    12e7 <main+0xb7>
lea    0xd37(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2cea(%rip),%rax
mov    (%rax),%esi
call   1100 <open@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jge    131f <main+0xef>
lea    0xd2c(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x200(%rbp),%rdi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%esi
lea    -0x200(%rbp),%rdi
call   1050 <serialport_init@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1364 <main+0x134>
lea    0xd13(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1030 <serialport_flush@plt>
mov    -0x3c(%rbp),%edi
mov    0x2c72(%rip),%rax
mov    (%rax),%esi
lea    -0x44(%rbp),%rdx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    -0x3c(%rbp),%edi
mov    0x2c43(%rip),%rax
mov    (%rax),%esi
lea    -0x3d(%rbp),%rdx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    -0x3c(%rbp),%edi
mov    0x2c24(%rip),%rax
mov    (%rax),%esi
lea    -0x3e(%rbp),%rdx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x304(%rbp)
mov    $0x80,%edi
call   1150 <JSIOCGNAME@plt>
mov    -0x304(%rbp),%edi
mov    %eax,%esi
lea    -0xd0(%rbp),%rdx
mov    $0x0,%al
call   1080 <ioctl@plt>
lea    -0xd0(%rbp),%rsi
movzbl -0x3d(%rbp),%edx
movzbl -0x3e(%rbp),%ecx
mov    -0x44(%rbp),%r8d
sar    $0x10,%r8d
mov    -0x44(%rbp),%r9d
sar    $0x8,%r9d
and    $0xff,%r9d
mov    -0x44(%rbp),%eax
and    $0xff,%eax
lea    0xc83(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xcb9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x4,%esi
movzbl -0x3d(%rbp),%edi
call   10a0 <calloc@plt>
mov    %rax,-0xd8(%rbp)
mov    $0x1,%esi
movzbl -0x3e(%rbp),%edi
call   10a0 <calloc@plt>
mov    %rax,-0xe0(%rbp)
jmp    1456 <main+0x226>
mov    -0x3c(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0x18,%edx
call   1090 <read@plt>
cltq
cmp    $0x18,%rax
je     148c <main+0x25c>
lea    0xc79(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    -0x100(%rbp),%eax
mov    %eax,-0x308(%rbp)
sub    $0x80,%eax
je     14be <main+0x28e>
jmp    14a8 <main+0x278>
mov    -0x308(%rbp),%eax
sub    $0x81,%eax
je     14da <main+0x2aa>
jmp    14f1 <main+0x2c1>
mov    -0xf0(%rbp),%edx
mov    -0xe0(%rbp),%rax
mov    -0xf8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    14f1 <main+0x2c1>
mov    -0xf0(%rbp),%edx
mov    -0xd8(%rbp),%rax
mov    -0xf8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
cmpb   $0x0,-0x3d(%rbp)
je     1589 <main+0x359>
mov    -0xd8(%rbp),%rax
mov    (%rax),%eax
mov    $0x16c,%ecx
cltd
idiv   %ecx
add    $0x5a,%eax
mov    %eax,-0x30c(%rbp)
mov    -0xd8(%rbp),%rax
mov    0x4(%rax),%eax
mov    $0x16c,%ecx
cltd
idiv   %ecx
mov    -0x30c(%rbp),%edx
mov    %eax,%ecx
add    $0x5a,%ecx
lea    -0x300(%rbp),%rdi
lea    0xbe1(%rip),%rsi
call   1130 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xbd8(%rip),%rsi
lea    -0x300(%rbp),%rdx
call   10c0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x300(%rbp),%rsi
call   10f0 <serialport_write@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1584 <main+0x354>
lea    0xbad(%rip),%rdi
call   1120 <perror@plt>
jmp    1589 <main+0x359>
mov    -0x28(%rbp),%rdi
call   10e0 <fflush@plt>
mov    0x2a27(%rip),%rax
mov    (%rax),%rdi
call   10e0 <fflush@plt>
jmp    1451 <main+0x221>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2b8,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xdc3(%rip),%rdi
lea    0xdc1(%rip),%rsi
call   1100 <fopen@plt>
movb   $0x2,0xe(%rsp)
movb   $0x2,0xf(%rsp)
movl   $0x800,0x10(%rsp)
movaps 0xf6e(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xf4f(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xf30(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xf11(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xef5(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xebd(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xea1(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
cmp    $0x3,%ebp
jne    12e3 <main+0xc3>
mov    %rax,%r12
mov    0x8(%rbx),%rbp
lea    0xd31(%rip),%rdi
mov    %rbp,%rsi
call   10b0 <strcmp@plt>
test   %eax,%eax
jne    12f9 <main+0xd9>
lea    0xd25(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10f0 <open@plt>
test   %eax,%eax
jns    131a <main+0xfa>
lea    0xd27(%rip),%rdi
jmp    1538 <main+0x318>
mov    %eax,%r15d
mov    0x10(%rbx),%rsi
lea    0x1b0(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x4b00,%esi
call   1050 <serialport_init@plt>
test   %eax,%eax
jns    134e <main+0x12e>
lea    0xd1f(%rip),%rdi
jmp    1538 <main+0x318>
mov    %eax,0x14(%rsp)
mov    %eax,%edi
call   1030 <serialport_flush@plt>
mov    0x2c88(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r15d,%edi
xor    %eax,%eax
call   1080 <ioctl@plt>
mov    0x2c58(%rip),%rax
mov    (%rax),%esi
lea    0xe(%rsp),%rdx
mov    %r15d,%edi
xor    %eax,%eax
call   1080 <ioctl@plt>
mov    0x2c38(%rip),%rax
mov    (%rax),%esi
lea    0xf(%rsp),%rdx
mov    %r15d,%edi
xor    %eax,%eax
call   1080 <ioctl@plt>
mov    $0x80,%edi
call   1140 <JSIOCGNAME@plt>
lea    0x30(%rsp),%rbx
mov    %r15d,%edi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <ioctl@plt>
movzbl 0xe(%rsp),%edx
movzbl 0xf(%rsp),%ecx
mov    0x10(%rsp),%eax
movzbl %ah,%ebp
movzbl %al,%esi
sar    $0x10,%eax
mov    %esi,(%rsp)
lea    0xcb2(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%r8d
mov    %ebp,%r9d
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd44(%rip),%rdi
call   1060 <puts@plt>
movzbl 0xe(%rsp),%edi
mov    $0x4,%esi
call   10a0 <calloc@plt>
mov    %rax,%rbp
movzbl 0xf(%rsp),%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,%rbx
lea    0x18(%rsp),%rsi
mov    %r15d,%edi
mov    $0x18,%edx
call   1090 <read@plt>
cmp    $0x18,%eax
jne    1531 <main+0x311>
lea    0x18(%rsp),%r13
lea    0xb0(%rsp),%r14
jmp    1480 <main+0x260>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   10d0 <fflush@plt>
mov    0x2b61(%rip),%rax
mov    (%rax),%rdi
call   10d0 <fflush@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0x18,%edx
call   1090 <read@plt>
cmp    $0x18,%eax
jne    1531 <main+0x311>
mov    0x18(%rsp),%ecx
mov    %rbx,%rax
cmp    $0x80,%ecx
je     149a <main+0x27a>
cmp    $0x81,%ecx
jne    14a6 <main+0x286>
mov    %rbp,%rax
mov    0x28(%rsp),%ecx
mov    0x20(%rsp),%rdx
mov    %ecx,(%rax,%rdx,4)
cmpb   $0x0,0xe(%rsp)
je     1450 <main+0x230>
movslq 0x0(%rbp),%rax
imul   $0xffffffffb40b40b5,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%eax
sar    $0x8,%eax
shr    $0x1f,%ecx
lea    (%rax,%rcx,1),%edx
add    $0x5a,%edx
movslq 0x4(%rbp),%rax
imul   $0xffffffffb40b40b5,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%eax
sar    $0x8,%eax
shr    $0x1f,%ecx
add    %eax,%ecx
add    $0x5a,%ecx
mov    %r14,%rdi
lea    0xc10(%rip),%rsi
call   1120 <sprintf@plt>
mov    %r12,%rdi
lea    0xc08(%rip),%rsi
mov    %r14,%rdx
call   10c0 <fprintf@plt>
mov    0x14(%rsp),%edi
mov    %r14,%rsi
call   10e0 <serialport_write@plt>
cmp    $0xffffffff,%eax
jne    1450 <main+0x230>
lea    0xbe8(%rip),%rdi
call   1110 <perror@plt>
jmp    1450 <main+0x230>
lea    0xba1(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.js_event = type { i32, i64, i32 }
@.str = [5 x i8] c"dump\00"
@.str.1 = [3 x i8] c"wb\00"
@__const.main.name = [128 x i8] c"Unknown\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.2 = [7 x i8] c"--help\00"
@.str.3 = [45 x i8] c"Usage: jscommander <jsdevice> <serialdevice>\00"
@O_RDONLY = global i32 0
@.str.4 = [44 x i8] c"jscommander: Unable to open joystick device\00"
@.str.5 = [42 x i8] c"jscommander: Unable to open serial device\00"
@JSIOCGVERSION = global i32 0
@JSIOCGAXES = global i32 0
@JSIOCGBUTTONS = global i32 0
@.str.6 = [71 x i8] c"Joystick (%s) has %d axes and %d buttons. Driver version is %d.%d.%d.\0A\00"
@.str.7 = [29 x i8] c"Running... (SIGINT to exit)\0A\00"
@.str.8 = [43 x i8] c"jscommander: Error reading joystick device\00"
@.str.9 = [7 x i8] c"%dx%dy\00"
@.str.10 = [4 x i8] c"%s\0A\00"
@.str.11 = [44 x i8] c"jscommander: Error writing to serial device\00"
@stdout = global i32* null
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 i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8
%15 = alloca i8
%16 = alloca i32
%17 = alloca [128 x i8]
%18 = alloca i32*
%19 = alloca i32*
%20 = alloca i32
%21 = alloca %struct.js_event
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 256, i32* %6
store i32 5000, i32* %7
store i32 -1, i32* %8
%22 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %9
store i32 19200, i32* %11
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %12
%24 = alloca i8, i64 256
%25 = alloca i8, i64 256
store i8 2, i8* %14
store i8 2, i8* %15
store i32 2048, i32* %16
%26 = bitcast [128 x i8]* %17 to i8*
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 3
br i1 %28, label %35, label %29
29: ; preds = %2
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %29, %2
%36 = call i32 @puts(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %29
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = load i32, i32* @O_RDONLY
%43 = call i32 @open(i8* %41, i32 %42)
store i32 %43, i32* %13
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %38
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = call i32 @strcpy(i8* %24, i8* %51)
%53 = load i32, i32* %11
%54 = call i32 @serialport_init(i8* %24, i32 %53)
store i32 %54, i32* %8
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %48
%57 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %48
%60 = load i32, i32* %8
%61 = call i32 @serialport_flush(i32 %60)
%62 = load i32, i32* %13
%63 = load i32, i32* @JSIOCGVERSION
%64 = call i32 (i32, i32, ...) @ioctl(i32 %62, i32 %63, i32* %16)
%65 = load i32, i32* %13
%66 = load i32, i32* @JSIOCGAXES
%67 = call i32 (i32, i32, ...) @ioctl(i32 %65, i32 %66, i8* %14)
%68 = load i32, i32* %13
%69 = load i32, i32* @JSIOCGBUTTONS
%70 = call i32 (i32, i32, ...) @ioctl(i32 %68, i32 %69, i8* %15)
%71 = load i32, i32* %13
%72 = call i32 @JSIOCGNAME(i32 128)
%73 = getelementptr inbounds [128 x i8], [128 x i8]* %17, i64 0, i64 0
%74 = call i32 (i32, i32, ...) @ioctl(i32 %71, i32 %72, i8* %73)
%75 = getelementptr inbounds [128 x i8], [128 x i8]* %17, i64 0, i64 0
%76 = load i8, i8* %14
%77 = zext i8 %76 to i32
%78 = load i8, i8* %15
%79 = zext i8 %78 to i32
%80 = load i32, i32* %16
%81 = ashr i32 %80, 16
%82 = load i32, i32* %16
%83 = ashr i32 %82, 8
%84 = and i32 %83, 255
%85 = load i32, i32* %16
%86 = and i32 %85, 255
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.6, i64 0, i64 0), i8* %75, i32 %77, i32 %79, i32 %81, i32 %84, i32 %86)
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%89 = load i8, i8* %14
%90 = call i32* @calloc(i8 zeroext %89, i32 4)
store i32* %90, i32** %18
%91 = load i8, i8* %15
%92 = call i32* @calloc(i8 zeroext %91, i32 1)
store i32* %92, i32** %19
br label %93
93: ; preds = %143, %59
br label %94
94: ; preds = %93
%95 = load i32, i32* %13
%96 = call i32 @read(i32 %95, %struct.js_event* %21, i32 24)
%97 = sext i32 %96 to i64
%98 = icmp ne i64 %97, 24
br i1 %98, label %99, label %102
99: ; preds = %94
%100 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %94
%103 = getelementptr inbounds %struct.js_event, %struct.js_event* %21, i32 0, i32 0
%104 = load i32, i32* %103
switch i32 %104, label %119 [
i32 128, label %105
i32 129, label %112
]
105: ; preds = %102
%106 = getelementptr inbounds %struct.js_event, %struct.js_event* %21, i32 0, i32 2
%107 = load i32, i32* %106
%108 = load i32*, i32** %19
%109 = getelementptr inbounds %struct.js_event, %struct.js_event* %21, i32 0, i32 1
%110 = load i64, i64* %109
%111 = getelementptr inbounds i32, i32* %108, i64 %110
store i32 %107, i32* %111
br label %119
112: ; preds = %102
%113 = getelementptr inbounds %struct.js_event, %struct.js_event* %21, i32 0, i32 2
%114 = load i32, i32* %113
%115 = load i32*, i32** %18
%116 = getelementptr inbounds %struct.js_event, %struct.js_event* %21, i32 0, i32 1
%117 = load i64, i64* %116
%118 = getelementptr inbounds i32, i32* %115, i64 %117
store i32 %114, i32* %118
br label %119
119: ; preds = %102, %112, %105
%120 = load i8, i8* %14
%121 = icmp ne i8 %120, 0
br i1 %121, label %122, label %143
122: ; preds = %119
%123 = load i32*, i32** %18
%124 = getelementptr inbounds i32, i32* %123, i64 0
%125 = load i32, i32* %124
%126 = sdiv i32 %125, 364
%127 = add nsw i32 %126, 90
%128 = load i32*, i32** %18
%129 = getelementptr inbounds i32, i32* %128, i64 1
%130 = load i32, i32* %129
%131 = sdiv i32 %130, 364
%132 = add nsw i32 %131, 90
%133 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %127, i32 %132)
%134 = load i32*, i32** %9
%135 = call i32 @fprintf(i32* %134, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %25)
%136 = load i32, i32* %8
%137 = call i32 @serialport_write(i32 %136, i8* %25)
store i32 %137, i32* %10
%138 = load i32, i32* %10
%139 = icmp eq i32 %138, -1
br i1 %139, label %140, label %142
140: ; preds = %122
%141 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.11, i64 0, i64 0))
br label %142
142: ; preds = %140, %122
br label %143
143: ; preds = %142, %119
%144 = load i32*, i32** %9
%145 = call i32 @fflush(i32* %144)
%146 = load i32*, i32** @stdout
%147 = call i32 @fflush(i32* %146)
br label %93
}

LLVM IR (-O2):
%struct.js_event = type { i32, i64, i32 }
@.str = [5 x i8] c"dump\00"
@.str.1 = [3 x i8] c"wb\00"
@__const.main.name = [128 x i8] c"Unknown\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.2 = [7 x i8] c"--help\00"
@.str.3 = [45 x i8] c"Usage: jscommander <jsdevice> <serialdevice>\00"
@O_RDONLY = global i32 0
@.str.4 = [44 x i8] c"jscommander: Unable to open joystick device\00"
@.str.5 = [42 x i8] c"jscommander: Unable to open serial device\00"
@JSIOCGVERSION = global i32 0
@JSIOCGAXES = global i32 0
@JSIOCGBUTTONS = global i32 0
@.str.6 = [71 x i8] c"Joystick (%s) has %d axes and %d buttons. Driver version is %d.%d.%d.\0A\00"
@.str.8 = [43 x i8] c"jscommander: Error reading joystick device\00"
@.str.9 = [7 x i8] c"%dx%dy\00"
@.str.10 = [4 x i8] c"%s\0A\00"
@.str.11 = [44 x i8] c"jscommander: Error writing to serial device\00"
@stdout = global i32* null
@str = [28 x i8] c"Running... (SIGINT to exit)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32
%6 = alloca [128 x i8]
%7 = alloca %struct.js_event
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = alloca [256 x i8]
%10 = alloca [256 x i8]
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
store i8 2, i8* %3
store i8 2, i8* %4
%13 = bitcast i32* %5 to i8*
store i32 2048, i32* %5
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%15 = icmp eq i32 %0, 3
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @strcmp(i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* dereferenceable(1) %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16, %2
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %16
%25 = load i32, i32* @O_RDONLY
%26 = tail call i32 @open(i8* %18, i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = tail call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %24
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @strcpy(i8* %12, i8* %33)
%35 = call i32 @serialport_init(i8* %12, i32 19200)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %31
%41 = call i32 @serialport_flush(i32 %35)
%42 = load i32, i32* @JSIOCGVERSION
%43 = call i32 (i32, i32, ...) @ioctl(i32 %26, i32 %42, i32* %5)
%44 = load i32, i32* @JSIOCGAXES
%45 = call i32 (i32, i32, ...) @ioctl(i32 %26, i32 %44, i8* %3)
%46 = load i32, i32* @JSIOCGBUTTONS
%47 = call i32 (i32, i32, ...) @ioctl(i32 %26, i32 %46, i8* %4)
%48 = call i32 @JSIOCGNAME(i32 128)
%49 = call i32 (i32, i32, ...) @ioctl(i32 %26, i32 %48, i8* %14)
%50 = load i8, i8* %3
%51 = zext i8 %50 to i32
%52 = load i8, i8* %4
%53 = zext i8 %52 to i32
%54 = load i32, i32* %5
%55 = ashr i32 %54, 16
%56 = lshr i32 %54, 8
%57 = and i32 %56, 255
%58 = and i32 %54, 255
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @.str.6, i64 0, i64 0), i8* %14, i32 %51, i32 %53, i32 %55, i32 %57, i32 %58)
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%61 = bitcast %struct.js_event* %7 to i8*
%62 = load i8, i8* %3
%63 = call i32* @calloc(i8 zeroext %62, i32 4)
%64 = load i8, i8* %4
%65 = call i32* @calloc(i8 zeroext %64, i32 1)
%66 = call i32 @read(i32 %26, %struct.js_event* %7, i32 24)
%67 = icmp eq i32 %66, 24
br i1 %67, label %68, label %73
68: ; preds = %40
%69 = getelementptr inbounds %struct.js_event, %struct.js_event* %7, i64 0, i32 0
%70 = getelementptr inbounds %struct.js_event, %struct.js_event* %7, i64 0, i32 2
%71 = getelementptr inbounds %struct.js_event, %struct.js_event* %7, i64 0, i32 1
%72 = getelementptr inbounds i32, i32* %63, i64 1
br label %76
73: ; preds = %100, %40
%74 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %68, %100
%77 = load i32, i32* %69
switch i32 %77, label %84 [
i32 128, label %79
i32 129, label %78
]
78: ; preds = %76
br label %79
79: ; preds = %76, %78
%80 = phi i32* [ %63, %78 ], [ %65, %76 ]
%81 = load i32, i32* %70
%82 = load i64, i64* %71
%83 = getelementptr inbounds i32, i32* %80, i64 %82
store i32 %81, i32* %83
br label %84
84: ; preds = %79, %76
%85 = load i8, i8* %3
%86 = icmp eq i8 %85, 0
br i1 %86, label %100, label %87
87: ; preds = %84
%88 = load i32, i32* %63
%89 = sdiv i32 %88, 364
%90 = add nsw i32 %89, 90
%91 = load i32, i32* %72
%92 = sdiv i32 %91, 364
%93 = add nsw i32 %92, 90
%94 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %90, i32 %93)
%95 = call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %11)
%96 = call i32 @serialport_write(i32 %35, i8* %11)
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %100
98: ; preds = %87
%99 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.11, i64 0, i64 0))
br label %100
100: ; preds = %87, %98, %84
%101 = call i32 @fflush(i32* %8)
%102 = load i32*, i32** @stdout
%103 = call i32 @fflush(i32* %102)
%104 = call i32 @read(i32 %26, %struct.js_event* %7, i32 24)
%105 = icmp eq i32 %104, 24
br i1 %105, label %76, label %73
}