#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  char *pressed = malloc(100 * sizeof(char));
  int mode = 0;
  do {
    pressed = "";
    int fd = open(argv[1], O_RDWR);
    if (fd == -1) {
      perror("open");
      return 1;
    }
    char *buffer = malloc(20);
    int len = read(fd, buffer, 20);
    if (len < 0) {
      perror("Read: ");
      exit(-1);
    }
    int i = 0;
    char *type[14];
    type[0] = "0x00\t";
    type[1] = "size of report";
    type[2] = "\nUp, Down, Left, Right, Start, Back, Left Stick, Right Stick";
    type[3] = "LB, RB, XBOX, A, B, X, Y";
    type[4] = "\nLT";
    type[5] = "RT";
    type[6] = "\nleft stick x - l\t";
    type[7] = "\t     - r\t";
    type[8] = "left stick y - b\t";
    type[9] = "\t     - t\t";
    type[10] = "\nright stick x - l\t";
    type[11] = "\t      - r\t";
    type[12] = "right stick y - b\t";
    type[13] = "\t      - t\t";
    while (i < 14) {
      if (i == 2 && pressed == "") {
        switch (buffer[i]) {
        case 0:
          pressed = "";
          break;
        case 1:
          pressed = "D-Pad UP";
          break;
        case 2:
          pressed = "D-Pad DOWN";
          break;
        case 4:
          pressed = "D-Pad LEFT";
          break;
        case 8:
          pressed = "D-Pad RIGHT";
          break;
        case 16:
          pressed = "Start";
          break;
        case 32:
          pressed = "Back";
          break;
        case 64:
          pressed = "Left Stick";
          break;
        default:
          pressed = "Right Stick";
          break;
        }
      }
      if (i == 3 && pressed == "") {
        switch (buffer[i]) {
        case 0:
          pressed = "";
          break;
        case 1:
          pressed = "LB";
          break;
        case 2:
          pressed = "RB";
          break;
        case 4:
          pressed = "XBOX-Button";
          break;
        case 16:
          pressed = "A";
          break;
        case 32:
          pressed = "B";
          break;
        case 64:
          pressed = "X";
          break;
        default:
          pressed = "Y";
          break;
        }
      }
      if (i == 4 && pressed == "" && buffer[i] > 0 && buffer[i] < 120) {
        pressed = "LT";
      }
      if (i == 5 && pressed == "" && buffer[i] > 0 && buffer[i] < 120) {
        pressed = "RT";
      }
      if (mode == 0)
        printf("%s\t:\t%u\n", type[i], buffer[i]);
      i++;
    }
    if (mode == 0)
      printf("\n-------------------------\n");
    printf("Pressed: %s\n", pressed);
    close(fd);
    free(buffer);
  } while (1);
  free(pressed);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0x1064(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11f4 <main+0x74>
lea    0x1025(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15d5 <main+0x455>
mov    $0x14,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x14,%edx
call   1060 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1236 <main+0xb6>
lea    0xfe6(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x30(%rbp)
lea    0xfd0(%rip),%rax
mov    %rax,-0xa0(%rbp)
lea    0xfc8(%rip),%rax
mov    %rax,-0x98(%rbp)
lea    0xfc9(%rip),%rax
mov    %rax,-0x90(%rbp)
lea    0xff8(%rip),%rax
mov    %rax,-0x88(%rbp)
lea    0x1003(%rip),%rax
mov    %rax,-0x80(%rbp)
lea    0xffc(%rip),%rax
mov    %rax,-0x78(%rbp)
lea    0xff4(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    0xffc(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    0xffc(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0x1003(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0x1003(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0x100c(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0x100d(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0x1015(%rip),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0xe,-0x30(%rbp)
jge    157b <main+0x3fb>
cmpl   $0x2,-0x30(%rbp)
jne    13cd <main+0x24d>
lea    0xf1b(%rip),%rax
cmp    %rax,-0x18(%rbp)
jne    13cd <main+0x24d>
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,%ecx
mov    %rcx,-0xa8(%rbp)
sub    $0x40,%eax
ja     13bd <main+0x23d>
mov    -0xa8(%rbp),%rax
lea    0xccc(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xed5(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    13c8 <main+0x248>
lea    0xfac(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    13c8 <main+0x248>
lea    0xfa5(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    13c8 <main+0x248>
lea    0xfa0(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    13c8 <main+0x248>
lea    0xf9b(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    13c8 <main+0x248>
lea    0xf97(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    13c8 <main+0x248>
lea    0xf8d(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    13c8 <main+0x248>
lea    0xf82(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    13c8 <main+0x248>
lea    0xe96(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    13cd <main+0x24d>
cmpl   $0x3,-0x30(%rbp)
jne    149d <main+0x31d>
lea    0xe3b(%rip),%rax
cmp    %rax,-0x18(%rbp)
jne    149d <main+0x31d>
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,%ecx
mov    %rcx,-0xb0(%rbp)
sub    $0x40,%eax
ja     148d <main+0x30d>
mov    -0xb0(%rbp),%rax
lea    0xcf0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xdf5(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1498 <main+0x318>
lea    0xf0d(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1498 <main+0x318>
lea    0xf00(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1498 <main+0x318>
lea    0xef3(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1498 <main+0x318>
lea    0xeef(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1498 <main+0x318>
lea    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1498 <main+0x318>
lea    0xed1(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1498 <main+0x318>
lea    0xde9(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    149d <main+0x31d>
cmpl   $0x4,-0x30(%rbp)
jne    14ed <main+0x36d>
lea    0xd6b(%rip),%rax
cmp    %rax,-0x18(%rbp)
jne    14ed <main+0x36d>
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jle    14ed <main+0x36d>
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x78,%eax
jge    14ed <main+0x36d>
lea    0xd97(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x5,-0x30(%rbp)
jne    153d <main+0x3bd>
lea    0xd1b(%rip),%rax
cmp    %rax,-0x18(%rbp)
jne    153d <main+0x3bd>
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jle    153d <main+0x3bd>
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x78,%eax
jge    153d <main+0x3bd>
lea    0xd4a(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    156d <main+0x3ed>
movslq -0x30(%rbp),%rax
mov    -0xa0(%rbp,%rax,8),%rsi
ff
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12e3 <main+0x163>
cmpl   $0x0,-0x1c(%rbp)
jne    1593 <main+0x413>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%al
test   $0x1,%al
jne    11ae <main+0x2e>
jmp    15c5 <main+0x445>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,0x8(%rsp)
mov    0x8(%rsi),%rdi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
jne    11e0 <main+0x50>
lea    0x1044(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r15d
lea    0x102f(%rip),%r14
lea    0xf13(%rip),%r12
lea    0x115f(%rip),%rbx
jmp    1251 <main+0xc1>
nopw   0x0(%rax,%rax,1)
lea    0x1166(%rip),%rdi
call   1040 <puts@plt>
lea    0x114d(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%edi
call   1060 <close@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rdi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     11bd <main+0x2d>
mov    $0x14,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
mov    %r15d,%edi
mov    %rax,%rsi
mov    $0x14,%edx
call   1070 <read@plt>
test   %eax,%eax
js     14b5 <main+0x325>
mov    %r15d,0x4(%rsp)
lea    0xf92(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xf8c(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xf8f(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xfc0(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xfcd(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xfc5(%rip),%rax
mov    %rax,0x38(%rsp)
lea    0xfbc(%rip),%rax
mov    %rax,0x40(%rsp)
lea    0xfc3(%rip),%rax
mov    %rax,0x48(%rsp)
lea    0xfc2(%rip),%rax
mov    %rax,0x50(%rsp)
lea    0xfc8(%rip),%rax
mov    %rax,0x58(%rsp)
lea    0xfc7(%rip),%rax
mov    %rax,0x60(%rsp)
lea    0xfcf(%rip),%rax
mov    %rax,0x68(%rsp)
lea    0xfcf(%rip),%rax
mov    %rax,0x70(%rsp)
lea    0xfd6(%rip),%rax
mov    %rax,0x78(%rsp)
xor    %r13d,%r13d
mov    %r14,%r15
jmp    1373 <main+0x1e3>
movzbl 0x4(%rbp),%eax
add    $0xff,%al
cmp    $0x77,%al
mov    %r14,%r15
lea    0xf43(%rip),%rax
cmovb  %rax,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp,%r13,8),%rsi
movsbl 0x0(%rbp,%r13,1),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r13
cmp    $0xe,%r13
je     1200 <main+0x70>
cmp    $0x2,%r13
jne    13a0 <main+0x210>
cmp    %r14,%r15
jne    13a0 <main+0x210>
movsbl 0x2(%rbp),%eax
cmp    $0x40,%eax
ja     1425 <main+0x295>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
mov    %r14,%r15
jmp    *%rax
lea    0xf62(%rip),%r15
jmp    1350 <main+0x1c0>
cmp    $0x3,%r13
jne    13e0 <main+0x250>
cmp    %r14,%r15
jne    13e0 <main+0x250>
movsbl 0x3(%rbp),%eax
cmp    $0x40,%eax
ja     1479 <main+0x2e9>
lea    0xc41(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
mov    %r14,%r15
jmp    *%rax
lea    0xf6f(%rip),%r15
jmp    1350 <main+0x1c0>
nopw   0x0(%rax,%rax,1)
cmp    $0x4,%r13
jne    13ef <main+0x25f>
cmp    %r14,%r15
je     132b <main+0x19b>
cmp    $0x5,%r13
jne    1350 <main+0x1c0>
cmp    %r14,%r15
jne    1350 <main+0x1c0>
movzbl 0x5(%rbp),%eax
add    $0xff,%al
cmp    $0x77,%al
mov    %r14,%r15
lea    0xe6f(%rip),%rax
jmp    133d <main+0x1ad>
lea    0xee9(%rip),%r15
jmp    1350 <main+0x1c0>
lea    0xe2e(%rip),%r15
jmp    1350 <main+0x1c0>
lea    0xedc(%rip),%r15
jmp    1350 <main+0x1c0>
lea    0xedb(%rip),%r15
jmp    1350 <main+0x1c0>
lea    0xedb(%rip),%r15
jmp    1350 <main+0x1c0>
lea    0xed5(%rip),%r15
jmp    1350 <main+0x1c0>
lea    0xece(%rip),%r15
jmp    1350 <main+0x1c0>
lea    0xed0(%rip),%r15
jmp    1350 <main+0x1c0>
lea    0xdfd(%rip),%r15
jmp    1350 <main+0x1c0>
lea    0xebb(%rip),%r15
jmp    1350 <main+0x1c0>
lea    0xebb(%rip),%r15
jmp    1350 <main+0x1c0>
lea    0xe9e(%rip),%r15
jmp    1350 <main+0x1c0>
lea    0xea5(%rip),%r15
jmp    1350 <main+0x1c0>
lea    0xd51(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [7 x i8] c"Read: \00"
@.str.3 = [6 x i8] c"0x00\09\00"
@.str.4 = [15 x i8] c"size of report\00"
@.str.5 = [61 x i8] c"\0AUp, Down, Left, Right, Start, Back, Left Stick, Right Stick\00"
@.str.6 = [25 x i8] c"LB, RB, XBOX, A, B, X, Y\00"
@.str.7 = [4 x i8] c"\0ALT\00"
@.str.8 = [3 x i8] c"RT\00"
@.str.9 = [19 x i8] c"\0Aleft stick x - l\09\00"
@.str.10 = [11 x i8] c"\09 - r\09\00"
@.str.11 = [18 x i8] c"left stick y - b\09\00"
@.str.12 = [11 x i8] c"\09 - t\09\00"
@.str.13 = [20 x i8] c"\0Aright stick x - l\09\00"
@.str.14 = [12 x i8] c"\09 - r\09\00"
@.str.15 = [19 x i8] c"right stick y - b\09\00"
@.str.16 = [12 x i8] c"\09 - t\09\00"
@.str.17 = [9 x i8] c"D-Pad UP\00"
@.str.18 = [11 x i8] c"D-Pad DOWN\00"
@.str.19 = [11 x i8] c"D-Pad LEFT\00"
@.str.20 = [12 x i8] c"D-Pad RIGHT\00"
@.str.21 = [6 x i8] c"Start\00"
@.str.22 = [5 x i8] c"Back\00"
@.str.23 = [11 x i8] c"Left Stick\00"
@.str.24 = [12 x i8] c"Right Stick\00"
@.str.25 = [3 x i8] c"LB\00"
@.str.26 = [3 x i8] c"RB\00"
@.str.27 = [12 x i8] c"XBOX-Button\00"
@.str.28 = [2 x i8] c"A\00"
@.str.29 = [2 x i8] c"B\00"
@.str.30 = [2 x i8] c"X\00"
@.str.31 = [2 x i8] c"Y\00"
@.str.32 = [3 x i8] c"LT\00"
@.str.33 = [9 x i8] c"%s\09:\09%u\0A\00"
@.str.34 = [28 x i8] c"\0A-------------------------\0A\00"
@.str.35 = [13 x i8] c"Pressed: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca [14 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i8* @malloc(i32 100)
store i8* %13, i8** %6
store i32 0, i32* %7
br label %14
14: ; preds = %173, %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDWR
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %177
24: ; preds = %14
%25 = call i8* @malloc(i32 20)
store i8* %25, i8** %9
%26 = load i32, i32* %8
%27 = load i8*, i8** %9
%28 = call i32 @read(i32 %26, i8* %27, i32 20)
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %24
%32 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %24
store i32 0, i32* %11
%35 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %35
%36 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8** %36
%37 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 2
store i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.5, i64 0, i64 0), i8** %37
%38 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 3
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8** %38
%39 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8** %39
%40 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8** %40
%41 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 6
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8** %41
%42 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 7
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i8** %42
%43 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 8
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i8** %43
%44 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 9
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i8** %44
%45 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 10
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0), i8** %45
%46 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 11
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0), i8** %46
%47 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 12
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.15, i64 0, i64 0), i8** %47
%48 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 13
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.16, i64 0, i64 0), i8** %48
br label %49
49: ; preds = %158, %34
%50 = load i32, i32* %11
%51 = icmp slt i32 %50, 14
br i1 %51, label %52, label %161
52: ; preds = %49
%53 = load i32, i32* %11
%54 = icmp eq i32 %53, 2
br i1 %54, label %55, label %75
55: ; preds = %52
%56 = load i8*, i8** %6
%57 = icmp eq i8* %56, getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
br i1 %57, label %58, label %75
58: ; preds = %55
%59 = load i8*, i8** %9
%60 = load i32, i32* %11
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
switch i32 %64, label %73 [
i32 0, label %65
i32 1, label %66
i32 2, label %67
i32 4, label %68
i32 8, label %69
i32 16, label %70
i32 32, label %71
i32 64, label %72
]
65: ; preds = %58
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
br label %74
66: ; preds = %58
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.17, i64 0, i64 0), i8** %6
br label %74
67: ; preds = %58
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.18, i64 0, i64 0), i8** %6
br label %74
68: ; preds = %58
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.19, i64 0, i64 0), i8** %6
br label %74
69: ; preds = %58
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.20, i64 0, i64 0), i8** %6
br label %74
70: ; preds = %58
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.21, i64 0, i64 0), i8** %6
br label %74
71: ; preds = %58
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.22, i64 0, i64 0), i8** %6
br label %74
72: ; preds = %58
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.23, i64 0, i64 0), i8** %6
br label %74
73: ; preds = %58
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.24, i64 0, i64 0), i8** %6
br label %74
74: ; preds = %73, %72, %71, %70, %69, %68, %67, %66, %65
br label %75
75: ; preds = %74, %55, %52
%76 = load i32, i32* %11
%77 = icmp eq i32 %76, 3
br i1 %77, label %78, label %97
78: ; preds = %75
%79 = load i8*, i8** %6
%80 = icmp eq i8* %79, getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
br i1 %80, label %81, label %97
81: ; preds = %78
%82 = load i8*, i8** %9
%83 = load i32, i32* %11
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %82, i64 %84
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
switch i32 %87, label %95 [
i32 0, label %88
i32 1, label %89
i32 2, label %90
i32 4, label %91
i32 16, label %92
i32 32, label %93
i32 64, label %94
]
88: ; preds = %81
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
br label %96
89: ; preds = %81
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.25, i64 0, i64 0), i8** %6
br label %96
90: ; preds = %81
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.26, i64 0, i64 0), i8** %6
br label %96
91: ; preds = %81
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.27, i64 0, i64 0), i8** %6
br label %96
92: ; preds = %81
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.28, i64 0, i64 0), i8** %6
br label %96
93: ; preds = %81
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.29, i64 0, i64 0), i8** %6
br label %96
94: ; preds = %81
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.30, i64 0, i64 0), i8** %6
br label %96
95: ; preds = %81
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.31, i64 0, i64 0), i8** %6
br label %96
96: ; preds = %95, %94, %93, %92, %91, %90, %89, %88
br label %97
97: ; preds = %96, %78, %75
%98 = load i32, i32* %11
%99 = icmp eq i32 %98, 4
br i1 %99, label %100, label %120
100: ; preds = %97
%101 = load i8*, i8** %6
%102 = icmp eq i8* %101, getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
br i1 %102, label %103, label %120
103: ; preds = %100
%104 = load i8*, i8** %9
%105 = load i32, i32* %11
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i8, i8* %104, i64 %106
%108 = load i8, i8* %107
%109 = sext i8 %108 to i32
%110 = icmp sgt i32 %109, 0
br i1 %110, label %111, label %120
111: ; preds = %103
%112 = load i8*, i8** %9
%113 = load i32, i32* %11
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds i8, i8* %112, i64 %114
%116 = load i8, i8* %115
%117 = sext i8 %116 to i32
%118 = icmp slt i32 %117, 120
br i1 %118, label %119, label %120
119: ; preds = %111
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.32, i64 0, i64 0), i8** %6
br label %120
120: ; preds = %119, %111, %103, %100, %97
%121 = load i32, i32* %11
%122 = icmp eq i32 %121, 5
br i1 %122, label %123, label %143
123: ; preds = %120
%124 = load i8*, i8** %6
%125 = icmp eq i8* %124, getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
br i1 %125, label %126, label %143
126: ; preds = %123
%127 = load i8*, i8** %9
%128 = load i32, i32* %11
%129 = sext i32 %128 to i64
%130 = getelementptr inbounds i8, i8* %127, i64 %129
%131 = load i8, i8* %130
%132 = sext i8 %131 to i32
%133 = icmp sgt i32 %132, 0
br i1 %133, label %134, label %143
134: ; preds = %126
%135 = load i8*, i8** %9
%136 = load i32, i32* %11
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds i8, i8* %135, i64 %137
%139 = load i8, i8* %138
%140 = sext i8 %139 to i32
%141 = icmp slt i32 %140, 120
br i1 %141, label %142, label %143
142: ; preds = %134
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8** %6
br label %143
143: ; preds = %142, %134, %126, %123, %120
%144 = load i32, i32* %7
%145 = icmp eq i32 %144, 0
br i1 %145, label %146, label %158
146: ; preds = %143
%147 = load i32, i32* %11
%148 = sext i32 %147 to i64
%149 = getelementptr inbounds [14 x i8*], [14 x i8*]* %12, i64 0, i64 %148
%150 = load i8*, i8** %149
%151 = load i8*, i8** %9
%152 = load i32, i32* %11
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds i8, i8* %151, i64 %153
%155 = load i8, i8* %154
%156 = sext i8 %155 to i32
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.33, i64 0, i64 0), i8* %150, i32 %156)
br label %158
158: ; preds = %146, %143
%159 = load i32, i32* %11
%160 = add nsw i32 %159, 1
store i32 %160, i32* %11
br label %49
161: ; preds = %49
%162 = load i32, i32* %7
%163 = icmp eq i32 %162, 0
br i1 %163, label %164, label %166
164: ; preds = %161
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.34, i64 0, i64 0))
br label %166
166: ; preds = %164, %161
%167 = load i8*, i8** %6
%168 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.35, i64 0, i64 0), i8* %167)
%169 = load i32, i32* %8
%170 = call i32 @close(i32 %169)
%171 = load i8*, i8** %9
%172 = call i32 @free(i8* %171)
br label %173
173: ; preds = %166
br i1 true, label %14, label %174
174: ; preds = %173
%175 = load i8*, i8** %6
%176 = call i32 @free(i8* %175)
store i32 0, i32* %3
br label %177
177: ; preds = %174, %22
%178 = load i32, i32* %3
ret i32 %178
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [7 x i8] c"Read: \00"
@.str.3 = [6 x i8] c"0x00\09\00"
@.str.4 = [15 x i8] c"size of report\00"
@.str.5 = [61 x i8] c"\0AUp, Down, Left, Right, Start, Back, Left Stick, Right Stick\00"
@.str.6 = [25 x i8] c"LB, RB, XBOX, A, B, X, Y\00"
@.str.7 = [4 x i8] c"\0ALT\00"
@.str.8 = [3 x i8] c"RT\00"
@.str.9 = [19 x i8] c"\0Aleft stick x - l\09\00"
@.str.10 = [11 x i8] c"\09 - r\09\00"
@.str.11 = [18 x i8] c"left stick y - b\09\00"
@.str.12 = [11 x i8] c"\09 - t\09\00"
@.str.13 = [20 x i8] c"\0Aright stick x - l\09\00"
@.str.14 = [12 x i8] c"\09 - r\09\00"
@.str.15 = [19 x i8] c"right stick y - b\09\00"
@.str.16 = [12 x i8] c"\09 - t\09\00"
@.str.17 = [9 x i8] c"D-Pad UP\00"
@.str.18 = [11 x i8] c"D-Pad DOWN\00"
@.str.19 = [11 x i8] c"D-Pad LEFT\00"
@.str.20 = [12 x i8] c"D-Pad RIGHT\00"
@.str.21 = [6 x i8] c"Start\00"
@.str.22 = [5 x i8] c"Back\00"
@.str.23 = [11 x i8] c"Left Stick\00"
@.str.24 = [12 x i8] c"Right Stick\00"
@.str.25 = [3 x i8] c"LB\00"
@.str.26 = [3 x i8] c"RB\00"
@.str.27 = [12 x i8] c"XBOX-Button\00"
@.str.28 = [2 x i8] c"A\00"
@.str.29 = [2 x i8] c"B\00"
@.str.30 = [2 x i8] c"X\00"
@.str.31 = [2 x i8] c"Y\00"
@.str.32 = [3 x i8] c"LT\00"
@.str.33 = [9 x i8] c"%s\09:\09%u\0A\00"
@.str.35 = [13 x i8] c"Pressed: %s\0A\00"
@str = [27 x i8] c"\0A-------------------------\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [14 x i8*]
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = bitcast [14 x i8*]* %3 to i8*
%6 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 0
%7 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 1
%8 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 2
%9 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 3
%10 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 4
%11 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 5
%12 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 6
%13 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 7
%14 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 8
%15 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 9
%16 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 10
%17 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 11
%18 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 12
%19 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 13
%20 = load i8*, i8** %4
%21 = load i32, i32* @O_RDWR
%22 = tail call i32 @open(i8* %20, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %102, label %24
24: ; preds = %2, %93
%25 = phi i32 [ %100, %93 ], [ %22, %2 ]
%26 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
%27 = tail call i32 @read(i32 %25, i8* %26, i32 20)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%31 = tail call i32 @exit(i32 -1)
unreachable
32: ; preds = %24
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.5, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8** %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8** %11
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8** %12
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i8** %13
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i8** %14
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i8** %15
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0), i8** %16
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0), i8** %17
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.15, i64 0, i64 0), i8** %18
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.16, i64 0, i64 0), i8** %19
%33 = getelementptr inbounds i8, i8* %26, i64 5
%34 = getelementptr inbounds i8, i8* %26, i64 4
%35 = getelementptr inbounds i8, i8* %26, i64 3
%36 = getelementptr inbounds i8, i8* %26, i64 2
br label %37
37: ; preds = %32, %83
%38 = phi i64 [ 0, %32 ], [ %91, %83 ]
%39 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %32 ], [ %84, %83 ]
%40 = icmp eq i64 %38, 2
%41 = icmp eq i8* %39, getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
%42 = select i1 %40, i1 %41, i1 false
br i1 %42, label %43, label %54
43: ; preds = %37
%44 = load i8, i8* %36
%45 = sext i8 %44 to i32
switch i32 %45, label %53 [
i32 0, label %83
i32 1, label %46
i32 2, label %47
i32 4, label %48
i32 8, label %49
i32 16, label %50
i32 32, label %51
i32 64, label %52
]
46: ; preds = %43
br label %83
47: ; preds = %43
br label %83
48: ; preds = %43
br label %83
49: ; preds = %43
br label %83
50: ; preds = %43
br label %83
51: ; preds = %43
br label %83
52: ; preds = %43
br label %83
53: ; preds = %43
br label %83
54: ; preds = %37
%55 = icmp eq i64 %38, 3
%56 = select i1 %55, i1 %41, i1 false
br i1 %56, label %57, label %67
57: ; preds = %54
%58 = load i8, i8* %35
%59 = sext i8 %58 to i32
switch i32 %59, label %66 [
i32 0, label %83
i32 1, label %60
i32 2, label %61
i32 4, label %62
i32 16, label %63
i32 32, label %64
i32 64, label %65
]
60: ; preds = %57
br label %83
61: ; preds = %57
br label %83
62: ; preds = %57
br label %83
63: ; preds = %57
br label %83
64: ; preds = %57
br label %83
65: ; preds = %57
br label %83
66: ; preds = %57
br label %83
67: ; preds = %54
%68 = icmp eq i64 %38, 4
%69 = select i1 %68, i1 %41, i1 false
br i1 %69, label %70, label %75
70: ; preds = %67
%71 = load i8, i8* %34
%72 = add i8 %71, -1
%73 = icmp ult i8 %72, 119
%74 = select i1 %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.32, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
br label %83
75: ; preds = %67
%76 = icmp eq i64 %38, 5
%77 = select i1 %76, i1 %41, i1 false
br i1 %77, label %78, label %83
78: ; preds = %75
%79 = load i8, i8* %33
%80 = add i8 %79, -1
%81 = icmp ult i8 %80, 119
%82 = select i1 %81, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
br label %83
83: ; preds = %53, %52, %51, %50, %49, %48, %47, %46, %43, %66, %65, %64, %63, %62, %61, %60, %57, %70, %78, %75
%84 = phi i8* [ %39, %75 ], [ %82, %78 ], [ %74, %70 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %57 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.25, i64 0, i64 0), %60 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.26, i64 0, i64 0), %61 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.27, i64 0, i64 0), %62 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.28, i64 0, i64 0), %63 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.29, i64 0, i64 0), %64 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.30, i64 0, i64 0), %65 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.31, i64 0, i64 0), %66 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %43 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.17, i64 0, i64 0), %46 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.18, i64 0, i64 0), %47 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.19, i64 0, i64 0), %48 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.20, i64 0, i64 0), %49 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.21, i64 0, i64 0), %50 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.22, i64 0, i64 0), %51 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.23, i64 0, i64 0), %52 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.24, i64 0, i64 0), %53 ]
%85 = getelementptr inbounds [14 x i8*], [14 x i8*]* %3, i64 0, i64 %38
%86 = load i8*, i8** %85
%87 = getelementptr inbounds i8, i8* %26, i64 %38
%88 = load i8, i8* %87
%89 = sext i8 %88 to i32
%90 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.33, i64 0, i64 0), i8* %86, i32 %89)
%91 = add nuw nsw i64 %38, 1
%92 = icmp eq i64 %91, 14
br i1 %92, label %93, label %37
93: ; preds = %83
%94 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%95 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.35, i64 0, i64 0), i8* %84)
%96 = tail call i32 @close(i32 %25)
%97 = tail call i32 @free(i8* %26)
%98 = load i8*, i8** %4
%99 = load i32, i32* @O_RDWR
%100 = tail call i32 @open(i8* %98, i32 %99)
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %24
102: ; preds = %93, %2
%103 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
ret i32 1
}