#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: usbreset device-filename\n");
    return 1;
  }
  filename = argv[1];
  fd = open(filename, O_WRONLY);
  if (fd < 0) {
    perror("Error opening output file");
    return 1;
  }
  printf("USBRESET ON: Reseteando  %s\n", filename);
  rc = ioctl(fd, USBDEVFS_RESET, 0);
  if (rc < 0) {
    perror("Error en IO");
    return 1;
  }
  printf("Reset OK\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     11a1 <main+0x41>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124b <main+0xeb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11e4 <main+0x84>
lea    0xe4e(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    124b <main+0xeb>
mov    -0x18(%rbp),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    122e <main+0xce>
lea    0xe3b(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    124b <main+0xeb>
lea    0xe2f(%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   %r14
push   %rbx
cmp    $0x2,%edi
jne    11d3 <main+0x63>
mov    0x8(%rsi),%rbx
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     11f6 <main+0x86>
mov    %eax,%ebp
lea    0xea0(%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>
test   %eax,%eax
js     11ff <main+0x8f>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    11ee <main+0x7e>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe24(%rip),%rdi
jmp    1206 <main+0x96>
lea    0xe52(%rip),%rdi
call   1090 <perror@plt>
jmp    11e8 <main+0x78>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Usage: usbreset device-filename\0A\00"
@O_WRONLY = global i32 0
@.str.1 = [26 x i8] c"Error opening output file\00"
@.str.2 = [29 x i8] c"USBRESET ON: Reseteando %s\0A\00"
@USBDEVFS_RESET = global i32 0
@.str.3 = [12 x i8] c"Error en IO\00"
@.str.4 = [10 x i8] c"Reset OK\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 %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %39
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = load i32, i32* @O_WRONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %39
25: ; preds = %14
%26 = load i8*, i8** %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load i32, i32* %7
%29 = load i32, i32* @USBDEVFS_RESET
%30 = call i32 @ioctl(i32 %28, i32 %29, i32 0)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %25
%34 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %39
35: ; preds = %25
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32, i32* %7
%38 = call i32 @close(i32 %37)
store i32 0, i32* %3
br label %39
39: ; preds = %35, %33, %23, %11
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Usage: usbreset device-filename\0A\00"
@O_WRONLY = global i32 0
@.str.1 = [26 x i8] c"Error opening output file\00"
@.str.2 = [29 x i8] c"USBRESET ON: Reseteando %s\0A\00"
@USBDEVFS_RESET = global i32 0
@.str.3 = [12 x i8] c"Error en IO\00"
@str = [9 x i8] c"Reset OK\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %25
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_WRONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %25
15: ; preds = %7
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%17 = load i32, i32* @USBDEVFS_RESET
%18 = tail call i32 @ioctl(i32 %11, i32 %17, i32 0)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %25
22: ; preds = %15
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 @close(i32 %11)
br label %25
25: ; preds = %22, %20, %13, %4
%26 = phi i32 [ 1, %4 ], [ 1, %13 ], [ 1, %20 ], [ 0, %22 ]
ret i32 %26
}