#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 ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("error: missing filename argument\n");
    return 1;
  }
  int fd, ok;
  const char *filename;
  filename = argv[1];
  fd = open(filename, O_WRONLY);
  if (fd < 0) {
    printf("error: opening %s failed (error number: %d)\n", filename, errno);
    return errno;
  }
  ok = ioctl(fd, USBDEVFS_RESET, 0);
  if (ok < 0) {
    printf("error: %s reset failed (error number: %d)\n", filename, errno);
    close(fd);
    return errno;
  }
  printf("ok: %s reset successful (return code:  %d)\n", filename, ok);
  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)
jge    117a <main+0x3a>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1249 <main+0x109>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d1 <main+0x91>
mov    -0x20(%rbp),%rsi
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1249 <main+0x109>
mov    -0x14(%rbp),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1225 <main+0xe5>
mov    -0x20(%rbp),%rsi
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1249 <main+0x109>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%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    $0x1,%edi
jg     116f <main+0x1f>
lea    0xf24(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    11fd <main+0xad>
mov    0x8(%rsi),%r14
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11be <main+0x6e>
mov    %eax,%ebp
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <ioctl@plt>
test   %eax,%eax
js     11da <main+0x8a>
lea    0xeaf(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    11fd <main+0xad>
mov    0x2e13(%rip),%rbx
mov    (%rbx),%edx
lea    0xe32(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11fb <main+0xab>
mov    0x2df7(%rip),%rbx
mov    (%rbx),%edx
lea    0xe43(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    (%rbx),%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"error: missing filename argument\0A\00"
@O_WRONLY = global i32 0
@.str.1 = [45 x i8] c"error: opening %s failed (error number: %d)\0A\00"
@errno = global i32 0
@USBDEVFS_RESET = global i32 0
@.str.2 = [43 x i8] c"error: %s reset failed (error number: %d)\0A\00"
@.str.3 = [44 x i8] c"ok: %s reset successful (return code: %d)\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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %46
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = load i32, i32* @O_WRONLY
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %13
%23 = load i8*, i8** %8
%24 = load i32, i32* @errno
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %23, i32 %24)
%26 = load i32, i32* @errno
store i32 %26, i32* %3
br label %46
27: ; preds = %13
%28 = load i32, i32* %6
%29 = load i32, i32* @USBDEVFS_RESET
%30 = call i32 @ioctl(i32 %28, i32 %29, i32 0)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %27
%34 = load i8*, i8** %8
%35 = load i32, i32* @errno
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %34, i32 %35)
%37 = load i32, i32* %6
%38 = call i32 @close(i32 %37)
%39 = load i32, i32* @errno
store i32 %39, i32* %3
br label %46
40: ; preds = %27
%41 = load i8*, i8** %8
%42 = load i32, i32* %7
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %41, i32 %42)
%44 = load i32, i32* %6
%45 = call i32 @close(i32 %44)
store i32 0, i32* %3
br label %46
46: ; preds = %40, %33, %22, %11
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@.str.1 = [45 x i8] c"error: opening %s failed (error number: %d)\0A\00"
@errno = global i32 0
@USBDEVFS_RESET = global i32 0
@.str.2 = [43 x i8] c"error: %s reset failed (error number: %d)\0A\00"
@.str.3 = [44 x i8] c"ok: %s reset successful (return code: %d)\0A\00"
@str = [33 x i8] c"error: missing filename argument\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %28
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_WRONLY
%10 = tail call i32 @open(i8* %8, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = load i32, i32* @errno
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32 %13)
%15 = load i32, i32* @errno
br label %28
16: ; preds = %6
%17 = load i32, i32* @USBDEVFS_RESET
%18 = tail call i32 @ioctl(i32 %10, i32 %17, i32 0)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32, i32* @errno
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i8* %8, i32 %21)
%23 = tail call i32 @close(i32 %10)
%24 = load i32, i32* @errno
br label %28
25: ; preds = %16
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %8, i32 %18)
%27 = tail call i32 @close(i32 %10)
br label %28
28: ; preds = %12, %20, %25, %4
%29 = phi i32 [ 1, %4 ], [ %15, %12 ], [ %24, %20 ], [ 0, %25 ]
ret i32 %29
}