#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 errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  const char *filename;
  int fd;
  filename = argv[1];
  fd = open(filename, O_WRONLY);
  errno = 0;
  if (fd < 0) {
    fprintf(stderr, "failed with error code : %d\n", errno);
    return 0;
  }
  ioctl(fd, USBDEVFS_RESET, 0);
  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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e52(%rip),%rax
movl   $0x0,(%rax)
cmpl   $0x0,-0x1c(%rbp)
jge    11b8 <main+0x78>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11da <main+0x9a>
mov    -0x1c(%rbp),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x8(%rsi),%rdi
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebx
mov    0x2e74(%rip),%rax
movl   $0x0,(%rax)
test   %ebx,%ebx
js     1181 <main+0x41>
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    %ebx,%edi
call   1040 <close@plt>
jmp    1198 <main+0x58>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
xor    %edx,%edx
call   1050 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"failed with error code : %d\0A\00"
@USBDEVFS_RESET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = load i32, i32* @O_WRONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %7
store i32 0, i32* @errno
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 0, i32* %3
br label %26
20: ; preds = %2
%21 = load i32, i32* %7
%22 = load i32, i32* @USBDEVFS_RESET
%23 = call i32 @ioctl(i32 %21, i32 %22, i32 0)
%24 = load i32, i32* %7
%25 = call i32 @close(i32 %24)
store i32 0, i32* %3
br label %26
26: ; preds = %20, %16
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"failed with error code : %d\0A\00"
@USBDEVFS_RESET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_WRONLY
%6 = tail call i32 @open(i8* %4, i32 %5)
store i32 0, i32* @errno
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 0)
br label %15
11: ; preds = %2
%12 = load i32, i32* @USBDEVFS_RESET
%13 = tail call i32 @ioctl(i32 %6, i32 %12, i32 0)
%14 = tail call i32 @close(i32 %6)
br label %15
15: ; preds = %11, %8
ret i32 0
}