#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, "\nUsage: %s <device filename>\n\n", argv[0]);
    fprintf(stderr, "Find your device with:\n\n$ lsusb\n...\n");
    fprintf(stderr, "Bus 001 Device 002: ID 0403:6001 Future Technology "
                    "Devices ...\n...\n\n");
    fprintf(stderr, "The device filename is: /dev/bus/usb/<Bus>/<Device>\n");
    fprintf(stderr, "here: /dev/bus/usb/001/002\n");
    return 1;
  }
  filename = argv[1];
  printf("Reset %s ...\n", filename);
  fd = open(filename, O_WRONLY);
  if (fd < 0) {
    perror("Error opening device");
    return 2;
  }
  rc = ioctl(fd, USBDEVFS_RESET, 0);
  if (rc < 0) {
    perror("Error in ioctl");
    return 3;
  }
  printf("Reset successful\n");
  close(fd);
  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     1206 <main+0xa6>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xead(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xecb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b0 <main+0x150>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    125b <main+0xfb>
lea    0xe9e(%rip),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    12b0 <main+0x150>
mov    -0x1c(%rbp),%edi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1293 <main+0x133>
lea    0xe7b(%rip),%rdi
call   1080 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    12b0 <main+0x150>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11d9 <main+0x69>
mov    0x8(%rsi),%rbx
lea    0xf57(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1241 <main+0xd1>
mov    %eax,%ebp
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <ioctl@plt>
test   %eax,%eax
js     1254 <main+0xe4>
lea    0xf41(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    1238 <main+0xc8>
mov    0x2df8(%rip),%rbx
mov    (%rbx),%edi
mov    (%rsi),%rdx
lea    0xe14(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe23(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe38(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe6d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe92(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xea0(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2,%ebx
jmp    1238 <main+0xc8>
lea    0xea2(%rip),%rdi
call   1090 <perror@plt>
mov    $0x3,%ebx
jmp    1238 <main+0xc8>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"\0AUsage: %s <device filename>\0A\0A\00"
@.str.1 = [37 x i8] c"Find your device with:\0A\0A$ lsusb\0A...\0A\00"
@.str.2 = [69 x i8] c"Bus 001 Device 002: ID 0403:6001 Future Technology Devices ...\0A...\0A\0A\00"
@.str.3 = [53 x i8] c"The device filename is: /dev/bus/usb/<Bus>/<Device>\0A\00"
@.str.4 = [28 x i8] c"here: /dev/bus/usb/001/002\0A\00"
@.str.5 = [14 x i8] c"Reset %s ...\0A\00"
@O_WRONLY = global i32 0
@.str.6 = [21 x i8] c"Error opening device\00"
@USBDEVFS_RESET = global i32 0
@.str.7 = [15 x i8] c"Error in ioctl\00"
@.str.8 = [18 x i8] c"Reset successful\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 %25
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %50
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %6
%32 = load i32, i32* @O_WRONLY
%33 = call i32 @open(i8* %31, i32 %32)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %25
%37 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
store i32 2, i32* %3
br label %50
38: ; preds = %25
%39 = load i32, i32* %7
%40 = load i32, i32* @USBDEVFS_RESET
%41 = call i32 @ioctl(i32 %39, i32 %40, i32 0)
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
store i32 3, i32* %3
br label %50
46: ; preds = %38
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
%48 = load i32, i32* %7
%49 = call i32 @close(i32 %48)
store i32 0, i32* %3
br label %50
50: ; preds = %46, %44, %36, %11
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"\0AUsage: %s <device filename>\0A\0A\00"
@.str.1 = [37 x i8] c"Find your device with:\0A\0A$ lsusb\0A...\0A\00"
@.str.2 = [69 x i8] c"Bus 001 Device 002: ID 0403:6001 Future Technology Devices ...\0A...\0A\0A\00"
@.str.3 = [53 x i8] c"The device filename is: /dev/bus/usb/<Bus>/<Device>\0A\00"
@.str.4 = [28 x i8] c"here: /dev/bus/usb/001/002\0A\00"
@.str.5 = [14 x i8] c"Reset %s ...\0A\00"
@O_WRONLY = global i32 0
@.str.6 = [21 x i8] c"Error opening device\00"
@USBDEVFS_RESET = global i32 0
@.str.7 = [15 x i8] c"Error in ioctl\00"
@str = [17 x i8] c"Reset successful\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %16, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %34
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @O_WRONLY
%21 = tail call i32 @open(i8* %18, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %34
25: ; preds = %16
%26 = load i32, i32* @USBDEVFS_RESET
%27 = tail call i32 @ioctl(i32 %21, i32 %26, i32 0)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
br label %34
31: ; preds = %25
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%33 = tail call i32 @close(i32 %21)
br label %34
34: ; preds = %31, %29, %23, %4
%35 = phi i32 [ 1, %4 ], [ 2, %23 ], [ 3, %29 ], [ 0, %31 ]
ret i32 %35
}