#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int main(int argc, char **argv) {
  unsigned char buf[128];
  int fd, nr, i, val, run;
  run = 0;
  if (argc < 2) {
    printf("Usage: %s /dev/hidrawX\n", argv[0]);
    return 1;
  }
  if ((fd = open(argv[1], O_RDONLY)) < 0) {
    perror("open(argv[1])");
    return 1;
  }
  while ((nr = read(fd, buf, sizeof(buf)))) {
    if (nr < 0) {
      perror("read(stdin)");
      return 1;
    }
    for (i = 0; i <= nr; i++) {
      val = buf[i];
      printf("%02X ", val);
      if (i == nr) {
        printf("\n \n");
      } else if (!i && !run) {
        run = 1;
      } else if (i % 15 == 0 && run) {
        printf("\n");
        run = 0;
      } else if ((i + 1) % 16 == 0) {
        printf("\n");
      }
    }
  }
  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)
movl   $0x0,-0xa4(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118e <main+0x4e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    134b <main+0x20b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x94(%rbp)
cmp    $0x0,%eax
jge    11cb <main+0x8b>
lea    0xe5e(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    134b <main+0x20b>
jmp    11d0 <main+0x90>
mov    -0x94(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1040 <read@plt>
mov    %eax,-0x98(%rbp)
cmp    $0x0,%eax
je     1344 <main+0x204>
cmpl   $0x0,-0x98(%rbp)
jge    121b <main+0xdb>
lea    0xe1c(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    134b <main+0x20b>
movl   $0x0,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
cmp    -0x98(%rbp),%eax
jg     133f <main+0x1ff>
movslq -0x9c(%rbp),%rax
movzbl -0x90(%rbp,%rax,1),%eax
ff
mov    %eax,-0xa0(%rbp)
mov    -0xa0(%rbp),%esi
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x9c(%rbp),%eax
cmp    -0x98(%rbp),%eax
jne    1285 <main+0x145>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1326 <main+0x1e6>
cmpl   $0x0,-0x9c(%rbp)
jne    12ae <main+0x16e>
cmpl   $0x0,-0xa4(%rbp)
jne    12ae <main+0x16e>
movl   $0x1,-0xa4(%rbp)
jmp    1321 <main+0x1e1>
mov    -0x9c(%rbp),%eax
mov    $0xf,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12ef <main+0x1af>
cmpl   $0x0,-0xa4(%rbp)
je     12ef <main+0x1af>
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xa4(%rbp)
jmp    131c <main+0x1dc>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1317 <main+0x1d7>
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    131c <main+0x1dc>
jmp    1321 <main+0x1e1>
jmp    1326 <main+0x1e6>
jmp    132b <main+0x1eb>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    1225 <main+0xe5>
jmp    11d0 <main+0x90>
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    $0x98,%rsp
cmp    $0x1,%edi
jg     1191 <main+0x31>
mov    (%rsi),%rsi
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    1296 <main+0x136>
mov    0x8(%rsi),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     12a8 <main+0x148>
mov    %eax,%r14d
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x80,%edx
call   1060 <read@plt>
test   %eax,%eax
je     1294 <main+0x134>
mov    %eax,%ebp
lea    0xe62(%rip),%rbx
xor    %r13d,%r13d
mov    %r14d,0xc(%rsp)
jmp    11fd <main+0x9d>
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x80,%edx
call   1060 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1294 <main+0x134>
test   %ebp,%ebp
js     12b9 <main+0x159>
mov    %ebp,%r12d
add    $0x1,%ebp
xor    %r14d,%r14d
jmp    1228 <main+0xc8>
lea    0xe21(%rip),%rdi
call   1040 <puts@plt>
mov    %r15d,%r13d
add    $0x1,%r14
cmp    %r14,%rbp
je     11e0 <main+0x80>
mov    %r13d,%r15d
movzbl 0x10(%rsp,%r14,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %r14,%r12
je     1210 <main+0xb0>
test   %r14,%r14
jne    1250 <main+0xf0>
mov    $0x1,%r13d
test   %r15d,%r15d
je     121f <main+0xbf>
mov    %r14d,%eax
mov    $0x88888889,%ecx
imul   %rcx,%rax
shr    $0x23,%rax
mov    %eax,%ecx
shl    $0x4,%ecx
sub    %ecx,%eax
add    %r14d,%eax
jne    1280 <main+0x120>
test   %r15d,%r15d
je     1280 <main+0x120>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %r13d,%r13d
jmp    121f <main+0xbf>
lea    0x1(%r14),%eax
test   $0xf,%al
jne    121c <main+0xbc>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    121c <main+0xbc>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd69(%rip),%rdi
call   1080 <perror@plt>
jmp    1187 <main+0x27>
lea    0xd66(%rip),%rdi
call   1080 <perror@plt>
jmp    1187 <main+0x27>

LLVM IR (-O0):
@.str = [24 x i8] c"Usage: %s /dev/hidrawX\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [14 x i8] c"open(argv[1])\00"
@.str.2 = [12 x i8] c"read(stdin)\00"
@.str.3 = [6 x i8] c"%02X \00"
@.str.4 = [4 x i8] c"\0A \0A\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [128 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %89
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %7
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %89
28: ; preds = %19
br label %29
29: ; preds = %87, %28
%30 = load i32, i32* %7
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%32 = call i32 @read(i32 %30, i8* %31, i32 128)
store i32 %32, i32* %8
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %88
34: ; preds = %29
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %89
39: ; preds = %34
store i32 0, i32* %9
br label %40
40: ; preds = %84, %39
%41 = load i32, i32* %9
%42 = load i32, i32* %8
%43 = icmp sle i32 %41, %42
br i1 %43, label %44, label %87
44: ; preds = %40
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
store i32 %49, i32* %10
%50 = load i32, i32* %10
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %50)
%52 = load i32, i32* %9
%53 = load i32, i32* %8
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %57
55: ; preds = %44
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %83
57: ; preds = %44
%58 = load i32, i32* %9
%59 = icmp ne i32 %58, 0
br i1 %59, label %64, label %60
60: ; preds = %57
%61 = load i32, i32* %11
%62 = icmp ne i32 %61, 0
br i1 %62, label %64, label %63
63: ; preds = %60
store i32 1, i32* %11
br label %82
64: ; preds = %60, %57
%65 = load i32, i32* %9
%66 = srem i32 %65, 15
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %64
%69 = load i32, i32* %11
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %11
br label %81
73: ; preds = %68, %64
%74 = load i32, i32* %9
%75 = add nsw i32 %74, 1
%76 = srem i32 %75, 16
%77 = icmp eq i32 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %73
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %80
80: ; preds = %78, %73
br label %81
81: ; preds = %80, %71
br label %82
82: ; preds = %81, %63
br label %83
83: ; preds = %82, %55
br label %84
84: ; preds = %83
%85 = load i32, i32* %9
%86 = add nsw i32 %85, 1
store i32 %86, i32* %9
br label %40
87: ; preds = %40
br label %29
88: ; preds = %29
store i32 0, i32* %3
br label %89
89: ; preds = %88, %37, %26, %14
%90 = load i32, i32* %3
ret i32 %90
}

LLVM IR (-O2):
@.str = [24 x i8] c"Usage: %s /dev/hidrawX\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [14 x i8] c"open(argv[1])\00"
@.str.2 = [12 x i8] c"read(stdin)\00"
@.str.3 = [6 x i8] c"%02X \00"
@str = [3 x i8] c"\0A \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %65
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = call i32 @read(i32 %13, i8* %4, i32 128)
%17 = icmp eq i32 %16, 0
br i1 %17, label %65, label %23
18: ; preds = %9
%19 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %65
20: ; preds = %61
%21 = call i32 @read(i32 %13, i8* %4, i32 128)
%22 = icmp eq i32 %21, 0
br i1 %22, label %65, label %23
23: ; preds = %15, %20
%24 = phi i32 [ %21, %20 ], [ %16, %15 ]
%25 = phi i32 [ %62, %20 ], [ 0, %15 ]
%26 = icmp slt i32 %24, 0
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = zext i32 %24 to i64
%29 = add nuw i32 %24, 1
%30 = zext i32 %29 to i64
br label %33
31: ; preds = %23
%32 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %65
33: ; preds = %27, %61
%34 = phi i64 [ 0, %27 ], [ %63, %61 ]
%35 = phi i32 [ %25, %27 ], [ %62, %61 ]
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %34
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = icmp eq i64 %34, %28
br i1 %40, label %41, label %43
41: ; preds = %33
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %61
43: ; preds = %33
%44 = icmp ne i64 %34, 0
%45 = icmp ne i32 %35, 0
%46 = select i1 %44, i1 true, i1 %45
br i1 %46, label %47, label %61
47: ; preds = %43
%48 = trunc i64 %34 to i32
%49 = urem i32 %48, 15
%50 = icmp eq i32 %49, 0
%51 = select i1 %50, i1 %45, i1 false
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = tail call i32 @putchar(i32 10)
br label %61
54: ; preds = %47
%55 = trunc i64 %34 to i32
%56 = add i32 %55, 1
%57 = and i32 %56, 15
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = tail call i32 @putchar(i32 10)
br label %61
61: ; preds = %43, %41, %52, %59, %54
%62 = phi i32 [ %35, %41 ], [ 0, %52 ], [ %35, %59 ], [ %35, %54 ], [ 1, %43 ]
%63 = add nuw nsw i64 %34, 1
%64 = icmp eq i64 %63, %30
br i1 %64, label %20, label %33
65: ; preds = %20, %15, %31, %18, %6
%66 = phi i32 [ 1, %6 ], [ 1, %18 ], [ 1, %31 ], [ 0, %15 ], [ 0, %20 ]
ret i32 %66
}