#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 hidraw_devinfo {
  int vendor;
  int product;
  scalar_t__ bustype;
};
typedef int /*<<< orphan*/ magic_sequence;
typedef int __s16;

/* Variables and functions */
scalar_t__ BUS_USB;
int /*<<< orphan*/ HIDIOCGRAWINFO;
int O_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ close(int);
int help();
int ioctl(int, int /*<<< orphan*/, struct hidraw_devinfo *);
scalar_t__ noreceiver(int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int write(int, char *, int);
int main(int argc, char **argv) {
  int fd;
  int res;
  int seqdev = 0;
  int arg = 1;
  int try_seq = 0;
  int check = 0;
  char *device;
  char hidraw[14] = "/dev/hidraw";
  hidraw[12] = '\0';
  hidraw[13] = '\0';
  struct hidraw_devinfo info;
  char magic_sequence[] = {0x10, 0xFF, 0x80, 0xB2, 0x01, 0x00, 0x00};
  int len_magic = sizeof(magic_sequence);
  printf("%d > %d\n", argc, arg);
  if (argc > arg) {
    if (!strcmp(argv[arg], "-h"))
      return help();
    else if (!strcmp(argv[arg], "-n")) {
      check = 1;
      arg++;
    }
  }
  printf("%d == %d\n", argc, arg);
  if (argc == arg)
    try_seq = 1;
  while (1) {
    if (try_seq) {
      if (seqdev > 99) {
        printf("Devices above /dev/hidraw99 not supported");
        break;
      } else if (seqdev < 10)
        hidraw[11] = seqdev + 48;
      else {
        hidraw[11] = seqdev / 10 + 48;
        hidraw[12] = seqdev % 10 + 48;
      }
      device = hidraw;
      ++seqdev;
    } else {
      if (arg >= argc)
        break;
      device = argv[arg++];
    }
    fd = open(device, O_RDWR | O_NONBLOCK);
    if (fd < 0) {
      printf("Unable to open device %s", device);
      if (try_seq) {
        printf(", stopping here\n");
        break;
      }
      printf("\n");
    } else {
      res = ioctl(fd, HIDIOCGRAWINFO, &info);
      printf("%sing device %04x:%04x on %s: ", (check ? "Check" : "Try"),
             info.vendor, info.product, device);
      if (res < 0)
        printf("no info from device\n");
      else if (info.bustype != BUS_USB)
        printf("not a USB device\n");
      else if (info.vendor != (__s16)0x046d)
        printf("not a Logitech device\n");
      else if (noreceiver(info.product))
        printf("not a known Logitech receiver\n");
      else {
        printf("a Logitech receiver\n");
        if (!check) {
          res = write(fd, magic_sequence, len_magic);
          if (res < 0)
            printf("Could not initialize the receiver\n");
          else if (res != len_magic)
            printf("Initialization of receiver not completed, only %d of %d "
                   "bytes written\n",
                   res, len_magic);
          else {
            printf("\nReceiver initialized, now waiting to pair a new device: "
                   "switch it (off and) on to pair it\n");
            break;
          }
        }
      }
      close(fd);
    }
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    0xe47(%rip),%rax
mov    %rax,-0x3e(%rbp)
mov    0xe45(%rip),%eax
mov    %eax,-0x36(%rbp)
mov    0xe3f(%rip),%ax
mov    %ax,-0x32(%rbp)
movb   $0x0,-0x32(%rbp)
movb   $0x0,-0x31(%rbp)
mov    0xe2f(%rip),%eax
mov    %eax,-0x57(%rbp)
mov    0xe29(%rip),%ax
mov    %ax,-0x53(%rbp)
mov    0xe21(%rip),%al
mov    %al,-0x51(%rbp)
movl   $0x7,-0x5c(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    1288 <main+0x108>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdee(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    124d <main+0xcd>
mov    $0x0,%al
call   10a0 <help@plt>
mov    %eax,-0x4(%rbp)
jmp    154a <main+0x3ca>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdc1(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    127e <main+0xfe>
movl   $0x1,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1283 <main+0x103>
jmp    1288 <main+0x108>
mov    -0x8(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    12af <main+0x12f>
movl   $0x1,-0x24(%rbp)
jmp    12b4 <main+0x134>
cmpl   $0x0,-0x24(%rbp)
je     1332 <main+0x1b2>
cmpl   $0x63,-0x1c(%rbp)
jle    12db <main+0x15b>
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1542 <main+0x3c2>
cmpl   $0xa,-0x1c(%rbp)
jge    12f3 <main+0x173>
mov    -0x1c(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x33(%rbp)
jmp    1317 <main+0x197>
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%eax
mov    %al,-0x33(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%al
mov    %al,-0x32(%rbp)
jmp    131c <main+0x19c>
lea    -0x3e(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    135d <main+0x1dd>
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     1343 <main+0x1c3>
jmp    1542 <main+0x3c2>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2c70(%rip),%rax
mov    (%rax),%esi
mov    0x2c5f(%rip),%rax
or     (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    13c7 <main+0x247>
mov    -0x30(%rbp),%rsi
lea    0xcc8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x24(%rbp)
je     13b4 <main+0x234>
lea    0xcc9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1542 <main+0x3c2>
lea    0xc71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    153d <main+0x3bd>
mov    -0x14(%rbp),%edi
mov    0x2c1f(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%ecx
lea    0xcbe(%rip),%rsi
lea    0xcb1(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
mov    -0x50(%rbp),%edx
mov    -0x4c(%rbp),%ecx
mov    -0x30(%rbp),%r8
lea    0xc7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
jge    142c <main+0x2ac>
lea    0xc8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1535 <main+0x3b5>
mov    -0x48(%rbp),%rax
mov    0x2bb1(%rip),%rcx
cmp    (%rcx),%rax
je     1453 <main+0x2d3>
lea    0xc79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1530 <main+0x3b0>
cmpl   $0x46d,-0x50(%rbp)
je     1473 <main+0x2f3>
lea    0xc6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    152b <main+0x3ab>
mov    -0x4c(%rbp),%edi
call   1080 <noreceiver@plt>
cmp    $0x0,%rax
je     1498 <main+0x318>
lea    0xc5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1526 <main+0x3a6>
lea    0xc69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x28(%rbp)
jne    1521 <main+0x3a1>
mov    -0x14(%rbp),%edi
lea    -0x57(%rbp),%rsi
mov    -0x5c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    14df <main+0x35f>
lea    0xc4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    151c <main+0x39c>
mov    -0x18(%rbp),%eax
cmp    -0x5c(%rbp),%eax
je     1504 <main+0x384>
mov    -0x18(%rbp),%esi
mov    -0x5c(%rbp),%edx
lea    0xc48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1517 <main+0x397>
lea    0xc7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1542 <main+0x3c2>
jmp    151c <main+0x39c>
jmp    1521 <main+0x3a1>
jmp    1526 <main+0x3a6>
jmp    152b <main+0x3ab>
jmp    1530 <main+0x3b0>
jmp    1535 <main+0x3b5>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
jmp    12b4 <main+0x134>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movabs $0x6469682f7665642f,%rax
68 69 64
mov    %rax,0x10(%rsp)
movl   $0x776172,0x18(%rsp)
movw   $0x0,0x1c(%rsp)
movl   $0x1b2,0x23(%rsp)
movl   $0xb280ff10,0x20(%rsp)
b2
lea    0xe2d(%rip),%rdi
mov    $0x1,%ebx
mov    %ebp,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x1,%ebp
jle    1273 <main+0xd3>
mov    0x8(%r14),%rbx
lea    0xe13(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     14b5 <main+0x315>
mov    %r14,0x28(%rsp)
lea    0xdfa(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
mov    %eax,%r14d
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
add    $0x1,%ebx
lea    0xde1(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,0xc(%rsp)
cmp    %ebp,%ebx
sete   %r15b
test   %r14d,%r14d
jne    1298 <main+0xf8>
movl   $0x0,0x8(%rsp)
lea    0xe24(%rip),%rax
mov    %rax,0x30(%rsp)
jmp    12aa <main+0x10a>
mov    %r14,0x28(%rsp)
lea    0xda5(%rip),%rdi
mov    %ebp,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,0xc(%rsp)
cmp    $0x1,%ebp
sete   %r15b
lea    0xdf7(%rip),%rax
mov    %rax,0x30(%rsp)
mov    $0x1,%al
mov    %eax,0x8(%rsp)
xor    %ebp,%ebp
test   %r15b,%r15b
jne    12f9 <main+0x159>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    0xc(%rsp),%ebx
jge    149c <main+0x2fc>
movslq %ebx,%rax
add    $0x1,%ebx
mov    0x28(%rsp),%rcx
mov    (%rcx,%rax,8),%r12
jmp    1339 <main+0x199>
nopl   0x0(%rax,%rax,1)
lea    0xed0(%rip),%rdi
call   1040 <puts@plt>
mov    %r13d,%edi
call   1080 <close@plt>
test   %r15b,%r15b
je     12c0 <main+0x120>
cmp    $0x64,%ebp
jge    1480 <main+0x2e0>
cmp    $0x9,%ebp
jg     1310 <main+0x170>
lea    0x30(%rbp),%eax
mov    %al,0x1b(%rsp)
jmp    1331 <main+0x191>
movzbl %bpl,%eax
imul   $0xcd,%eax,%ecx
shr    $0xb,%ecx
lea    0x30(%rcx),%edx
mov    %dl,0x1b(%rsp)
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %cl,%al
or     $0x30,%al
mov    %al,0x1c(%rsp)
add    $0x1,%ebp
lea    0x10(%rsp),%r12
mov    0x2c90(%rip),%rax
mov    (%rax),%esi
mov    0x2c8f(%rip),%rax
or     (%rax),%esi
mov    %r12,%rdi
call   10b0 <open@plt>
mov    %eax,%r13d
test   %eax,%eax
js     13d0 <main+0x230>
mov    0x2c8f(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
lea    0x38(%rsp),%rdx
call   1070 <ioctl@plt>
mov    %eax,%r14d
mov    0x38(%rsp),%edx
mov    0x3c(%rsp),%ecx
lea    0xcef(%rip),%rdi
mov    0x30(%rsp),%rsi
mov    %r12,%r8
xor    %eax,%eax
call   1060 <printf@plt>
test   %r14d,%r14d
js     12e0 <main+0x140>
mov    0x40(%rsp),%rax
mov    0x2c42(%rip),%rcx
cmp    (%rcx),%rax
jne    1410 <main+0x270>
cmpl   $0x46d,0x38(%rsp)
jne    141c <main+0x27c>
mov    0x3c(%rsp),%edi
call   10a0 <noreceiver@plt>
test   %rax,%rax
je     1428 <main+0x288>
lea    0xda8(%rip),%rdi
jmp    12e7 <main+0x147>
nop
lea    0xc81(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r15b,%r15b
jne    1490 <main+0x2f0>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r15b,%r15b
je     12c0 <main+0x120>
jmp    12f9 <main+0x159>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xd8f(%rip),%rdi
jmp    12e7 <main+0x147>
lea    0xd6d(%rip),%rdi
jmp    12e7 <main+0x147>
lea    0xcb2(%rip),%rdi
call   1040 <puts@plt>
cmpb   $0x0,0x8(%rsp)
je     12ec <main+0x14c>
mov    %r13d,%edi
lea    0x20(%rsp),%rsi
mov    $0x7,%edx
call   1050 <write@plt>
test   %eax,%eax
js     1474 <main+0x2d4>
cmp    $0x7,%eax
je     14ca <main+0x32a>
lea    0xc39(%rip),%rdi
mov    %eax,%esi
mov    $0x7,%edx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12ec <main+0x14c>
lea    0xcd5(%rip),%rdi
jmp    12e7 <main+0x147>
lea    0xba7(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    149c <main+0x2fc>
lea    0xd34(%rip),%rdi
call   1040 <puts@plt>
mov    %r13d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10c0 <help@plt>
lea    0xc24(%rip),%rdi
jmp    1497 <main+0x2f7>

LLVM IR (-O0):
%struct.hidraw_devinfo = type { i32, i32, i64 }
@__const.main.hidraw = [14 x i8] c"/dev/hidraw\00\00\00"
@__const.main.magic_sequence = [7 x i8] c"\10\FF\80\B2\01\00\00"
@.str = [9 x i8] c"%d > %d\0A\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [3 x i8] c"-n\00"
@.str.3 = [10 x i8] c"%d == %d\0A\00"
@.str.4 = [42 x i8] c"Devices above /dev/hidraw99 not supported\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.5 = [25 x i8] c"Unable to open device %s\00"
@.str.6 = [17 x i8] c", stopping here\0A\00"
@.str.7 = [2 x i8] c"\0A\00"
@HIDIOCGRAWINFO = global i32 0
@.str.8 = [31 x i8] c"%sing device %04x:%04x on %s: \00"
@.str.9 = [6 x i8] c"Check\00"
@.str.10 = [4 x i8] c"Try\00"
@.str.11 = [21 x i8] c"no info from device\0A\00"
@BUS_USB = global i64 0
@.str.12 = [18 x i8] c"not a USB device\0A\00"
@.str.13 = [23 x i8] c"not a Logitech device\0A\00"
@.str.14 = [31 x i8] c"not a known Logitech receiver\0A\00"
@.str.15 = [21 x i8] c"a Logitech receiver\0A\00"
@.str.16 = [35 x i8] c"Could not initialize the receiver\0A\00"
@.str.17 = [71 x i8] c"Initialization of receiver not completed, only %d of %d bytes written\0A\00"
@.str.18 = [92 x i8] c"\0AReceiver initialized, now waiting to pair a new device: switch it (off and) on to pair it\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 i32
%12 = alloca i8*
%13 = alloca [14 x i8]
%14 = alloca %struct.hidraw_devinfo
%15 = alloca [7 x i8]
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 1, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
%17 = bitcast [14 x i8]* %13 to i8*
%18 = getelementptr inbounds [14 x i8], [14 x i8]* %13, i64 0, i64 12
store i8 0, i8* %18
%19 = getelementptr inbounds [14 x i8], [14 x i8]* %13, i64 0, i64 13
store i8 0, i8* %19
%20 = bitcast [7 x i8]* %15 to i8*
store i32 7, i32* %16
%21 = load i32, i32* %4
%22 = load i32, i32* %9
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22)
%24 = load i32, i32* %4
%25 = load i32, i32* %9
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %50
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @strcmp(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%34 = icmp ne i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %27
%36 = call i32 (...) @help()
store i32 %36, i32* %3
br label %194
37: ; preds = %27
%38 = load i8**, i8*** %5
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 @strcmp(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%44 = icmp ne i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %37
store i32 1, i32* %11
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %48
48: ; preds = %45, %37
br label %49
49: ; preds = %48
br label %50
50: ; preds = %49, %2
%51 = load i32, i32* %4
%52 = load i32, i32* %9
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %51, i32 %52)
%54 = load i32, i32* %4
%55 = load i32, i32* %9
%56 = icmp eq i32 %54, %55
br i1 %56, label %57, label %58
57: ; preds = %50
store i32 1, i32* %10
br label %58
58: ; preds = %57, %50
br label %59
59: ; preds = %58, %190
%60 = load i32, i32* %10
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %91
62: ; preds = %59
%63 = load i32, i32* %8
%64 = icmp sgt i32 %63, 99
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
br label %191
67: ; preds = %62
%68 = load i32, i32* %8
%69 = icmp slt i32 %68, 10
br i1 %69, label %70, label %75
70: ; preds = %67
%71 = load i32, i32* %8
%72 = add nsw i32 %71, 48
%73 = trunc i32 %72 to i8
%74 = getelementptr inbounds [14 x i8], [14 x i8]* %13, i64 0, i64 11
store i8 %73, i8* %74
br label %86
75: ; preds = %67
%76 = load i32, i32* %8
%77 = sdiv i32 %76, 10
%78 = add nsw i32 %77, 48
%79 = trunc i32 %78 to i8
%80 = getelementptr inbounds [14 x i8], [14 x i8]* %13, i64 0, i64 11
store i8 %79, i8* %80
%81 = load i32, i32* %8
%82 = srem i32 %81, 10
%83 = add nsw i32 %82, 48
%84 = trunc i32 %83 to i8
%85 = getelementptr inbounds [14 x i8], [14 x i8]* %13, i64 0, i64 12
store i8 %84, i8* %85
br label %86
86: ; preds = %75, %70
br label %87
87: ; preds = %86
%88 = getelementptr inbounds [14 x i8], [14 x i8]* %13, i64 0, i64 0
store i8* %88, i8** %12
%89 = load i32, i32* %8
%90 = add nsw i32 %89, 1
store i32 %90, i32* %8
br label %103
91: ; preds = %59
%92 = load i32, i32* %9
%93 = load i32, i32* %4
%94 = icmp sge i32 %92, %93
br i1 %94, label %95, label %96
95: ; preds = %91
br label %191
96: ; preds = %91
%97 = load i8**, i8*** %5
%98 = load i32, i32* %9
%99 = add nsw i32 %98, 1
store i32 %99, i32* %9
%100 = sext i32 %98 to i64
%101 = getelementptr inbounds i8*, i8** %97, i64 %100
%102 = load i8*, i8** %101
store i8* %102, i8** %12
br label %103
103: ; preds = %96, %87
%104 = load i8*, i8** %12
%105 = load i32, i32* @O_RDWR
%106 = load i32, i32* @O_NONBLOCK
%107 = or i32 %105, %106
%108 = call i32 @open(i8* %104, i32 %107)
store i32 %108, i32* %6
%109 = load i32, i32* %6
%110 = icmp slt i32 %109, 0
br i1 %110, label %111, label %120
111: ; preds = %103
%112 = load i8*, i8** %12
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %112)
%114 = load i32, i32* %10
%115 = icmp ne i32 %114, 0
br i1 %115, label %116, label %118
116: ; preds = %111
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
br label %191
118: ; preds = %111
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %190
120: ; preds = %103
%121 = load i32, i32* %6
%122 = load i32, i32* @HIDIOCGRAWINFO
%123 = call i32 @ioctl(i32 %121, i32 %122, %struct.hidraw_devinfo* %14)
store i32 %123, i32* %7
%124 = load i32, i32* %11
%125 = icmp ne i32 %124, 0
%126 = zext i1 %125 to i64
%127 = select i1 %125, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0)
%128 = getelementptr inbounds %struct.hidraw_devinfo, %struct.hidraw_devinfo* %14, i32 0, i32 0
%129 = load i32, i32* %128
%130 = getelementptr inbounds %struct.hidraw_devinfo, %struct.hidraw_devinfo* %14, i32 0, i32 1
%131 = load i32, i32* %130
%132 = load i8*, i8** %12
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %127, i32 %129, i32 %131, i8* %132)
%134 = load i32, i32* %7
%135 = icmp slt i32 %134, 0
br i1 %135, label %136, label %138
136: ; preds = %120
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0))
br label %187
138: ; preds = %120
%139 = getelementptr inbounds %struct.hidraw_devinfo, %struct.hidraw_devinfo* %14, i32 0, i32 2
%140 = load i64, i64* %139
%141 = load i64, i64* @BUS_USB
%142 = icmp ne i64 %140, %141
br i1 %142, label %143, label %145
143: ; preds = %138
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0))
br label %186
145: ; preds = %138
%146 = getelementptr inbounds %struct.hidraw_devinfo, %struct.hidraw_devinfo* %14, i32 0, i32 0
%147 = load i32, i32* %146
%148 = icmp ne i32 %147, 1133
br i1 %148, label %149, label %151
149: ; preds = %145
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0))
br label %185
151: ; preds = %145
%152 = getelementptr inbounds %struct.hidraw_devinfo, %struct.hidraw_devinfo* %14, i32 0, i32 1
%153 = load i32, i32* %152
%154 = call i64 @noreceiver(i32 %153)
%155 = icmp ne i64 %154, 0
br i1 %155, label %156, label %158
156: ; preds = %151
%157 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0))
br label %184
158: ; preds = %151
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.15, i64 0, i64 0))
%160 = load i32, i32* %11
%161 = icmp ne i32 %160, 0
br i1 %161, label %183, label %162
162: ; preds = %158
%163 = load i32, i32* %6
%164 = getelementptr inbounds [7 x i8], [7 x i8]* %15, i64 0, i64 0
%165 = load i32, i32* %16
%166 = call i32 @write(i32 %163, i8* %164, i32 %165)
store i32 %166, i32* %7
%167 = load i32, i32* %7
%168 = icmp slt i32 %167, 0
br i1 %168, label %169, label %171
169: ; preds = %162
%170 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.16, i64 0, i64 0))
br label %182
171: ; preds = %162
%172 = load i32, i32* %7
%173 = load i32, i32* %16
%174 = icmp ne i32 %172, %173
br i1 %174, label %175, label %179
175: ; preds = %171
%176 = load i32, i32* %7
%177 = load i32, i32* %16
%178 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.17, i64 0, i64 0), i32 %176, i32 %177)
br label %181
179: ; preds = %171
%180 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.18, i64 0, i64 0))
br label %191
181: ; preds = %175
br label %182
182: ; preds = %181, %169
br label %183
183: ; preds = %182, %158
br label %184
184: ; preds = %183, %156
br label %185
185: ; preds = %184, %149
br label %186
186: ; preds = %185, %143
br label %187
187: ; preds = %186, %136
%188 = load i32, i32* %6
%189 = call i32 @close(i32 %188)
br label %190
190: ; preds = %187, %118
br label %59
191: ; preds = %179, %116, %95, %65
%192 = load i32, i32* %6
%193 = call i32 @close(i32 %192)
br label %194
194: ; preds = %191, %35
%195 = load i32, i32* %3
ret i32 %195
}

LLVM IR (-O2):
%struct.hidraw_devinfo = type { i32, i32, i64 }
@__const.main.hidraw = [14 x i8] c"/dev/hidraw\00\00\00"
@__const.main.magic_sequence = [7 x i8] c"\10\FF\80\B2\01\00\00"
@.str = [9 x i8] c"%d > %d\0A\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [3 x i8] c"-n\00"
@.str.3 = [10 x i8] c"%d == %d\0A\00"
@.str.4 = [42 x i8] c"Devices above /dev/hidraw99 not supported\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.5 = [25 x i8] c"Unable to open device %s\00"
@HIDIOCGRAWINFO = global i32 0
@.str.8 = [31 x i8] c"%sing device %04x:%04x on %s: \00"
@.str.9 = [6 x i8] c"Check\00"
@.str.10 = [4 x i8] c"Try\00"
@BUS_USB = global i64 0
@.str.17 = [71 x i8] c"Initialization of receiver not completed, only %d of %d bytes written\0A\00"
@str = [20 x i8] c"a Logitech receiver\00"
@str.19 = [91 x i8] c"\0AReceiver initialized, now waiting to pair a new device: switch it (off and) on to pair it\00"
@str.20 = [34 x i8] c"Could not initialize the receiver\00"
@str.21 = [30 x i8] c"not a known Logitech receiver\00"
@str.22 = [22 x i8] c"not a Logitech device\00"
@str.23 = [17 x i8] c"not a USB device\00"
@str.24 = [20 x i8] c"no info from device\00"
@str.25 = [16 x i8] c", stopping here\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [14 x i8]
%4 = alloca %struct.hidraw_devinfo
%5 = alloca [7 x 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 12
store i8 0, i8* %7
%8 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 13
store i8 0, i8* %8
%9 = bitcast %struct.hidraw_devinfo* %4 to i8*
%10 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %0, i32 1)
%12 = icmp sgt i32 %0, 1
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %0, i32 1)
%15 = icmp eq i32 %0, 1
%16 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 11
br label %31
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i32 (...) @help()
br label %131
24: ; preds = %17
%25 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i32 2, i32 1
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %0, i32 %27)
%29 = icmp eq i32 %27, %0
%30 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 11
br i1 %26, label %35, label %31
31: ; preds = %13, %24
%32 = phi i8* [ %16, %13 ], [ %30, %24 ]
%33 = phi i1 [ %15, %13 ], [ %29, %24 ]
%34 = phi i32 [ 1, %13 ], [ %27, %24 ]
br label %35
35: ; preds = %24, %31
%36 = phi i8* [ %32, %31 ], [ %30, %24 ]
%37 = phi i1 [ %33, %31 ], [ %29, %24 ]
%38 = phi i1 [ true, %31 ], [ false, %24 ]
%39 = phi i32 [ %34, %31 ], [ %27, %24 ]
%40 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), %31 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), %24 ]
%41 = getelementptr inbounds %struct.hidraw_devinfo, %struct.hidraw_devinfo* %4, i64 0, i32 0
%42 = getelementptr inbounds %struct.hidraw_devinfo, %struct.hidraw_devinfo* %4, i64 0, i32 1
%43 = getelementptr inbounds %struct.hidraw_devinfo, %struct.hidraw_devinfo* %4, i64 0, i32 2
br label %44
44: ; preds = %127, %35
%45 = phi i32 [ undef, %35 ], [ %78, %127 ]
%46 = phi i32 [ 0, %35 ], [ %72, %127 ]
%47 = phi i32 [ %39, %35 ], [ %73, %127 ]
br i1 %37, label %48, label %64
48: ; preds = %44
%49 = icmp sgt i32 %46, 99
br i1 %49, label %50, label %52
50: ; preds = %48
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
br label %128
52: ; preds = %48
%53 = icmp slt i32 %46, 10
%54 = trunc i32 %46 to i8
br i1 %53, label %55, label %57
55: ; preds = %52
%56 = add i8 %54, 48
store i8 %56, i8* %36
br label %62
57: ; preds = %52
%58 = udiv i8 %54, 10
%59 = add nuw nsw i8 %58, 48
store i8 %59, i8* %36
%60 = urem i8 %54, 10
%61 = or i8 %60, 48
store i8 %61, i8* %7
br label %62
62: ; preds = %55, %57
%63 = add nsw i32 %46, 1
br label %71
64: ; preds = %44
%65 = icmp slt i32 %47, %0
br i1 %65, label %66, label %128
66: ; preds = %64
%67 = add nsw i32 %47, 1
%68 = sext i32 %47 to i64
%69 = getelementptr inbounds i8*, i8** %1, i64 %68
%70 = load i8*, i8** %69
br label %71
71: ; preds = %66, %62
%72 = phi i32 [ %63, %62 ], [ %46, %66 ]
%73 = phi i32 [ %47, %62 ], [ %67, %66 ]
%74 = phi i8* [ %6, %62 ], [ %70, %66 ]
%75 = load i32, i32* @O_RDWR
%76 = load i32, i32* @O_NONBLOCK
%77 = or i32 %76, %75
%78 = call i32 @open(i8* %74, i32 %77)
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %86
80: ; preds = %71
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %74)
br i1 %37, label %82, label %84
82: ; preds = %80
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.25, i64 0, i64 0))
br label %128
84: ; preds = %80
%85 = call i32 @putchar(i32 10)
br label %127
86: ; preds = %71
%87 = load i32, i32* @HIDIOCGRAWINFO
%88 = call i32 @ioctl(i32 %78, i32 %87, %struct.hidraw_devinfo* %4)
%89 = load i32, i32* %41
%90 = load i32, i32* %42
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %40, i32 %89, i32 %90, i8* %74)
%92 = icmp slt i32 %88, 0
br i1 %92, label %93, label %95
93: ; preds = %86
%94 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.24, i64 0, i64 0))
br label %125
95: ; preds = %86
%96 = load i64, i64* %43
%97 = load i64, i64* @BUS_USB
%98 = icmp eq i64 %96, %97
br i1 %98, label %101, label %99
99: ; preds = %95
%100 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.23, i64 0, i64 0))
br label %125
101: ; preds = %95
%102 = load i32, i32* %41
%103 = icmp eq i32 %102, 1133
br i1 %103, label %106, label %104
104: ; preds = %101
%105 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.22, i64 0, i64 0))
br label %125
106: ; preds = %101
%107 = load i32, i32* %42
%108 = call i64 @noreceiver(i32 %107)
%109 = icmp eq i64 %108, 0
br i1 %109, label %112, label %110
110: ; preds = %106
%111 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.21, i64 0, i64 0))
br label %125
112: ; preds = %106
%113 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br i1 %38, label %114, label %125
114: ; preds = %112
%115 = call i32 @write(i32 %78, i8* %10, i32 7)
%116 = icmp slt i32 %115, 0
br i1 %116, label %117, label %119
117: ; preds = %114
%118 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.20, i64 0, i64 0))
br label %125
119: ; preds = %114
%120 = icmp eq i32 %115, 7
br i1 %120, label %123, label %121
121: ; preds = %119
%122 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @.str.17, i64 0, i64 0), i32 %115, i32 7)
br label %125
123: ; preds = %119
%124 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @str.19, i64 0, i64 0))
br label %128
125: ; preds = %99, %110, %117, %121, %112, %104, %93
%126 = call i32 @close(i32 %78)
br label %127
127: ; preds = %125, %84
br label %44
128: ; preds = %64, %123, %82, %50
%129 = phi i32 [ %45, %50 ], [ %78, %82 ], [ %78, %123 ], [ %45, %64 ]
%130 = call i32 @close(i32 %129)
br label %131
131: ; preds = %128, %22
%132 = phi i32 [ 0, %128 ], [ %23, %22 ]
ret i32 %132
}