#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_WRONLY;
int /*<<< orphan*/ USBDEVFS_RESET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  const char *filename;
  int fd;
  int rc;
  if (argc != 2) {
    fprintf(stderr, "usage: nusbreset [device file]\n");
    fprintf(stderr, "example: ./nusbreset /dev/bus/usb/001/003\n");
    return 1;
  }
  filename = argv[1];
  fd = open(filename, O_WRONLY);
  if (fd < 0) {
    perror("nusbreset error: can't open device file, exiting.");
    return 1;
  }
  printf("nusbreset: resetting USB device %s\n", filename);
  rc = ioctl(fd, USBDEVFS_RESET, 0);
  if (rc < 0) {
    close(fd);
    perror("nusbreset error: ioctl failure, exiting.");
    return 1;
  }
  close(fd);
  printf("nusbreset: success\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b6 <main+0x56>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x108>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11f9 <main+0x99>
lea    0xe63(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x108>
mov    -0x18(%rbp),%rsi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    124b <main+0xeb>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
lea    0xe67(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x108>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11d5 <main+0x65>
mov    0x8(%rsi),%rbx
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1206 <main+0x96>
mov    %eax,%ebp
lea    0xee2(%rip),%rdi
xor    %r14d,%r14d
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <ioctl@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1060 <close@plt>
test   %ebx,%ebx
js     120f <main+0x9f>
lea    0xefc(%rip),%rdi
call   1030 <puts@plt>
jmp    11fe <main+0x8e>
mov    0x2dfc(%rip),%rbx
mov    (%rbx),%edi
lea    0xe1b(%rip),%rsi
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe2d(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe3e(%rip),%rdi
jmp    1216 <main+0xa6>
lea    0xe8b(%rip),%rdi
call   1090 <perror@plt>
jmp    11f8 <main+0x88>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"usage: nusbreset [device file]\0A\00"
@.str.1 = [43 x i8] c"example: ./nusbreset /dev/bus/usb/001/003\0A\00"
@O_WRONLY = global i32 0
@.str.2 = [50 x i8] c"nusbreset error: can't open device file, exiting.\00"
@.str.3 = [36 x i8] c"nusbreset: resetting USB device %s\0A\00"
@USBDEVFS_RESET = global i32 0
@.str.4 = [41 x i8] c"nusbreset error: ioctl failure, exiting.\00"
@.str.5 = [20 x i8] c"nusbreset: success\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %43
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = load i32, i32* @O_WRONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %16
%26 = call i32 @perror(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %43
27: ; preds = %16
%28 = load i8*, i8** %6
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = load i32, i32* %7
%31 = load i32, i32* @USBDEVFS_RESET
%32 = call i32 @ioctl(i32 %30, i32 %31, i32 0)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %27
%36 = load i32, i32* %7
%37 = call i32 @close(i32 %36)
%38 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %43
39: ; preds = %27
%40 = load i32, i32* %7
%41 = call i32 @close(i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %43
43: ; preds = %39, %35, %25, %11
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"usage: nusbreset [device file]\0A\00"
@.str.1 = [43 x i8] c"example: ./nusbreset /dev/bus/usb/001/003\0A\00"
@O_WRONLY = global i32 0
@.str.2 = [50 x i8] c"nusbreset error: can't open device file, exiting.\00"
@.str.3 = [36 x i8] c"nusbreset: resetting USB device %s\0A\00"
@USBDEVFS_RESET = global i32 0
@.str.4 = [41 x i8] c"nusbreset error: ioctl failure, exiting.\00"
@str = [19 x i8] c"nusbreset: success\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %27
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_WRONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 @perror(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
br label %27
17: ; preds = %9
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%19 = load i32, i32* @USBDEVFS_RESET
%20 = tail call i32 @ioctl(i32 %13, i32 %19, i32 0)
%21 = icmp slt i32 %20, 0
%22 = tail call i32 @close(i32 %13)
br i1 %21, label %23, label %25
23: ; preds = %17
%24 = tail call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
br label %27
25: ; preds = %17
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %27
27: ; preds = %25, %23, %15, %4
%28 = phi i32 [ 1, %4 ], [ 1, %15 ], [ 1, %23 ], [ 0, %25 ]
ret i32 %28
}