#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 */
struct usbdevfs_ioctl {
  int ifno;
  int /*<<< orphan*/ *data;
  int /*<<< orphan*/ ioctl_code;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ USBDEVFS_DISCONNECT;
int /*<<< orphan*/ USBDEVFS_IOCTL;
int ioctl(int, int /*<<< orphan*/, struct usbdevfs_ioctl *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  struct usbdevfs_ioctl command;
  int ret;
  int fd;
  int i;
  if (argc > 1) {
    fd = open(argv[1], O_RDWR);
    if (fd < 1) {
      perror("unable to open file");
      return 1;
    }
    for (i = 0; i < 255; i++) {
      command.ifno = i;
      command.ioctl_code = USBDEVFS_DISCONNECT;
      command.data = NULL;
      ret = ioctl(fd, USBDEVFS_IOCTL, &command);
      if (ret != -1)
        printf("un claimed interface %d %d\n", i, ret);
    }
  } else {
    printf("usage: %s /dev/bus/usb/BUS/DEVICE\n", argv[0]);
    printf("Release all interfaces of this usb device for usage in "
           "virtualisation\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1217 <main+0xd7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x1,-0x30(%rbp)
jge    119b <main+0x5b>
lea    0xe76(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    123a <main+0xfa>
movl   $0x0,-0x34(%rbp)
cmpl   $0xff,-0x34(%rbp)
jge    1212 <main+0xd2>
mov    -0x34(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x30(%rbp),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
je     11ff <main+0xbf>
mov    -0x34(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1204 <main+0xc4>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a2 <main+0x62>
jmp    123a <main+0xfa>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     11e2 <main+0x92>
mov    0x8(%rsi),%rdi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
jle    1216 <main+0xc6>
mov    %eax,%ebx
mov    0x2e52(%rip),%r12
mov    0x2e53(%rip),%r13
mov    %rsp,%r14
lea    0xe7d(%rip),%r15
xor    %ebp,%ebp
jmp    11ab <main+0x5b>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0xff,%ebp
je     1203 <main+0xb3>
mov    %ebp,(%rsp)
mov    (%r12),%eax
mov    %eax,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x0(%r13),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11a0 <main+0x50>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a0 <main+0x50>
mov    (%rsi),%rsi
lea    0xe44(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
jmp    1205 <main+0xb5>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde3(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%ebx
jmp    1205 <main+0xb5>

LLVM IR (-O0):
%struct.usbdevfs_ioctl = type { i32, i32*, i32 }
@O_RDWR = global i32 0
@.str = [20 x i8] c"unable to open file\00"
@USBDEVFS_DISCONNECT = global i32 0
@USBDEVFS_IOCTL = global i32 0
@.str.1 = [28 x i8] c"un claimed interface %d %d\0A\00"
@.str.2 = [35 x i8] c"usage: %s /dev/bus/usb/BUS/DEVICE\0A\00"
@.str.3 = [71 x i8] c"Release all interfaces of this usb device for usage in virtualisation\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.usbdevfs_ioctl
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %46
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %52
22: ; preds = %12
store i32 0, i32* %9
br label %23
23: ; preds = %42, %22
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 255
br i1 %25, label %26, label %45
26: ; preds = %23
%27 = load i32, i32* %9
%28 = getelementptr inbounds %struct.usbdevfs_ioctl, %struct.usbdevfs_ioctl* %6, i32 0, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* @USBDEVFS_DISCONNECT
%30 = getelementptr inbounds %struct.usbdevfs_ioctl, %struct.usbdevfs_ioctl* %6, i32 0, i32 2
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.usbdevfs_ioctl, %struct.usbdevfs_ioctl* %6, i32 0, i32 1
store i32* null, i32** %31
%32 = load i32, i32* %8
%33 = load i32, i32* @USBDEVFS_IOCTL
%34 = call i32 @ioctl(i32 %32, i32 %33, %struct.usbdevfs_ioctl* %6)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp ne i32 %35, -1
br i1 %36, label %37, label %41
37: ; preds = %26
%38 = load i32, i32* %9
%39 = load i32, i32* %7
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %39)
br label %41
41: ; preds = %37, %26
br label %42
42: ; preds = %41
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
store i32 %44, i32* %9
br label %23
45: ; preds = %23
br label %52
46: ; preds = %2
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 0
%49 = load i8*, i8** %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0))
br label %52
52: ; preds = %20, %46, %45
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
%struct.usbdevfs_ioctl = type { i32, i32*, i32 }
@O_RDWR = global i32 0
@.str = [20 x i8] c"unable to open file\00"
@USBDEVFS_DISCONNECT = global i32 0
@USBDEVFS_IOCTL = global i32 0
@.str.1 = [28 x i8] c"un claimed interface %d %d\0A\00"
@.str.2 = [35 x i8] c"usage: %s /dev/bus/usb/BUS/DEVICE\0A\00"
@str = [70 x i8] c"Release all interfaces of this usb device for usage in virtualisation\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.usbdevfs_ioctl
%4 = bitcast %struct.usbdevfs_ioctl* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %29
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDWR
%10 = tail call i32 @open(i8* %8, i32 %9)
%11 = icmp slt i32 %10, 1
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = getelementptr inbounds %struct.usbdevfs_ioctl, %struct.usbdevfs_ioctl* %3, i64 0, i32 0
%14 = getelementptr inbounds %struct.usbdevfs_ioctl, %struct.usbdevfs_ioctl* %3, i64 0, i32 2
%15 = getelementptr inbounds %struct.usbdevfs_ioctl, %struct.usbdevfs_ioctl* %3, i64 0, i32 1
br label %18
16: ; preds = %6
%17 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %33
18: ; preds = %12, %26
%19 = phi i32 [ 0, %12 ], [ %27, %26 ]
store i32 %19, i32* %13
%20 = load i32, i32* @USBDEVFS_DISCONNECT
store i32 %20, i32* %14
store i32* null, i32** %15
%21 = load i32, i32* @USBDEVFS_IOCTL
%22 = call i32 @ioctl(i32 %10, i32 %21, %struct.usbdevfs_ioctl* %3)
%23 = icmp eq i32 %22, -1
br i1 %23, label %26, label %24
24: ; preds = %18
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %22)
br label %26
26: ; preds = %18, %24
%27 = add nuw nsw i32 %19, 1
%28 = icmp eq i32 %27, 255
br i1 %28, label %33, label %18
29: ; preds = %2
%30 = load i8*, i8** %1
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %26, %29, %16
%34 = phi i32 [ 1, %16 ], [ 0, %29 ], [ 0, %26 ]
ret i32 %34
}