#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 */
typedef int /*<<< orphan*/ path;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ USBDEVFS_RESET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char **argv) {
  int fd;
  int rc;
  FILE *fp;
  char path[1035];
  char filename[21];
  char buff[3];
  fp = popen("lsusb | grep \"WLAN\"", "r");
  if (fp == NULL) {
    printf("Failed to run command\n");
    exit(1);
  }
  while (fgets(path, sizeof(path) - 1, fp) != NULL) {
    printf("%s", path);
  }
  pclose(fp);
  strcpy(filename, "/dev/bus/usb/");
  strncpy(buff, path + 4, 3);
  strcat(filename, buff);
  strcat(filename, "/");
  strncpy(buff, path + 15, 3);
  strcat(filename, buff);
  filename[21] = '\0';
  fd = open(filename, O_WRONLY);
  if (fd < 0) {
    perror("Error opening output file");
    return 1;
  }
  printf("Resetting USB device %s\n", filename);
  rc = ioctl(fd, USBDEVFS_RESET, 0);
  if (rc < 0) {
    perror("Error in ioctl");
    return 1;
  }
  printf("Reset successful\n");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe20(%rip),%rdi
lea    0xe2d(%rip),%rsi
call   10b0 <popen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1213 <main+0x53>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    1218 <main+0x58>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x40a,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     1251 <main+0x91>
lea    -0x430(%rbp),%rsi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1218 <main+0x58>
mov    -0x20(%rbp),%rdi
call   1060 <pclose@plt>
lea    -0x450(%rbp),%rdi
lea    0xdc8(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x453(%rbp),%rdi
lea    -0x430(%rbp),%rsi
add    $0x4,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    -0x450(%rbp),%rdi
lea    -0x453(%rbp),%rsi
call   10d0 <strcat@plt>
lea    -0x450(%rbp),%rdi
lea    0xd92(%rip),%rsi
call   10d0 <strcat@plt>
lea    -0x453(%rbp),%rdi
lea    -0x430(%rbp),%rsi
add    $0xf,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    -0x450(%rbp),%rdi
lea    -0x453(%rbp),%rsi
call   10d0 <strcat@plt>
movb   $0x0,-0x43b(%rbp)
lea    -0x450(%rbp),%rdi
mov    0x2cdd(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    131f <main+0x15f>
lea    0xd30(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1389 <main+0x1c9>
lea    -0x450(%rbp),%rsi
lea    0xd2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2caa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    136c <main+0x1ac>
lea    0xd16(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1389 <main+0x1c9>
lea    0xd0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x440,%rsp
lea    0xe1e(%rip),%rdi
lea    0xe2b(%rip),%rsi
call   10c0 <popen@plt>
test   %rax,%rax
je     1330 <main+0x160>
mov    %rax,%rbx
lea    0x30(%rsp),%rdi
mov    $0x40a,%esi
mov    %rax,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     1242 <main+0x72>
lea    0xdfe(%rip),%r14
lea    0x30(%rsp),%rbp
nopl   (%rax)
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    $0x40a,%esi
mov    %rbx,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
jne    1220 <main+0x50>
mov    %rbx,%rdi
call   1070 <pclose@plt>
lea    0xdc8(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
lea    0x34(%rsp),%rsi
lea    0xd(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10e0 <strcat@plt>
lea    0xd9e(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <strcat@plt>
lea    0x3f(%rsp),%rsi
mov    %rbp,%rdi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10e0 <strcat@plt>
movb   $0x0,0x25(%rsp)
mov    0x2d18(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10b0 <open@plt>
test   %eax,%eax
js     1314 <main+0x144>
mov    %eax,%ebp
lea    0xd72(%rip),%rdi
xor    %ebx,%ebx
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d04(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1080 <ioctl@plt>
test   %eax,%eax
js     131d <main+0x14d>
lea    0xd6f(%rip),%rdi
call   1050 <puts@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    %ebx,%eax
add    $0x440,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd0c(%rip),%rdi
jmp    1324 <main+0x154>
lea    0xd36(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%ebx
jmp    1306 <main+0x136>
lea    0xd43(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"lsusb | grep \22WLAN\22\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"Failed to run command\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [14 x i8] c"/dev/bus/usb/\00"
@.str.5 = [2 x i8] c"/\00"
@O_WRONLY = global i32 0
@.str.6 = [26 x i8] c"Error opening output file\00"
@.str.7 = [25 x i8] c"Resetting USB device %s\0A\00"
@USBDEVFS_RESET = global i32 0
@.str.8 = [15 x i8] c"Error in ioctl\00"
@.str.9 = [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 i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca [1035 x i8]
%10 = alloca [21 x i8]
%11 = alloca [3 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32* @popen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
br label %19
19: ; preds = %24, %18
%20 = getelementptr inbounds [1035 x i8], [1035 x i8]* %9, i64 0, i64 0
%21 = load i32*, i32** %8
%22 = call i32* @fgets(i8* %20, i32 1034, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = getelementptr inbounds [1035 x i8], [1035 x i8]* %9, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %19
27: ; preds = %19
%28 = load i32*, i32** %8
%29 = call i32 @pclose(i32* %28)
%30 = getelementptr inbounds [21 x i8], [21 x i8]* %10, i64 0, i64 0
%31 = call i32 @strcpy(i8* %30, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%33 = getelementptr inbounds [1035 x i8], [1035 x i8]* %9, i64 0, i64 0
%34 = getelementptr inbounds i8, i8* %33, i64 4
%35 = call i32 @strncpy(i8* %32, i8* %34, i32 3)
%36 = getelementptr inbounds [21 x i8], [21 x i8]* %10, i64 0, i64 0
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%38 = call i32 @strcat(i8* %36, i8* %37)
%39 = getelementptr inbounds [21 x i8], [21 x i8]* %10, i64 0, i64 0
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%41 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%42 = getelementptr inbounds [1035 x i8], [1035 x i8]* %9, i64 0, i64 0
%43 = getelementptr inbounds i8, i8* %42, i64 15
%44 = call i32 @strncpy(i8* %41, i8* %43, i32 3)
%45 = getelementptr inbounds [21 x i8], [21 x i8]* %10, i64 0, i64 0
%46 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%47 = call i32 @strcat(i8* %45, i8* %46)
%48 = getelementptr inbounds [21 x i8], [21 x i8]* %10, i64 0, i64 21
store i8 0, i8* %48
%49 = getelementptr inbounds [21 x i8], [21 x i8]* %10, i64 0, i64 0
%50 = load i32, i32* @O_WRONLY
%51 = call i32 @open(i8* %49, i32 %50)
store i32 %51, i32* %6
%52 = load i32, i32* %6
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %27
%55 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %70
56: ; preds = %27
%57 = getelementptr inbounds [21 x i8], [21 x i8]* %10, i64 0, i64 0
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %57)
%59 = load i32, i32* %6
%60 = load i32, i32* @USBDEVFS_RESET
%61 = call i32 @ioctl(i32 %59, i32 %60, i32 0)
store i32 %61, i32* %7
%62 = load i32, i32* %7
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %56
%65 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %70
66: ; preds = %56
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%68 = load i32, i32* %6
%69 = call i32 @close(i32 %68)
store i32 0, i32* %3
br label %70
70: ; preds = %66, %64, %54
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@.str = [20 x i8] c"lsusb | grep \22WLAN\22\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [14 x i8] c"/dev/bus/usb/\00"
@.str.5 = [2 x i8] c"/\00"
@O_WRONLY = global i32 0
@.str.6 = [26 x i8] c"Error opening output file\00"
@.str.7 = [25 x i8] c"Resetting USB device %s\0A\00"
@USBDEVFS_RESET = global i32 0
@.str.8 = [15 x i8] c"Error in ioctl\00"
@str = [17 x i8] c"Reset successful\00"
@str.10 = [22 x i8] c"Failed to run command\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1035 x i8]
%4 = alloca [21 x i8]
%5 = alloca [3 x i8]
%6 = getelementptr inbounds [1035 x i8], [1035 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [21 x i8], [21 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%9 = tail call i32* @popen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = call i32* @fgets(i8* %6, i32 1034, i32* %9)
%13 = icmp eq i32* %12, null
br i1 %13, label %21, label %17
14: ; preds = %2
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.10, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %11, %17
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%19 = call i32* @fgets(i8* %6, i32 1034, i32* %9)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %17
21: ; preds = %17, %11
%22 = call i32 @pclose(i32* %9)
%23 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%24 = getelementptr inbounds [1035 x i8], [1035 x i8]* %3, i64 0, i64 4
%25 = call i32 @strncpy(i8* %8, i8* %24, i32 3)
%26 = call i32 @strcat(i8* %7, i8* %8)
%27 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%28 = getelementptr inbounds [1035 x i8], [1035 x i8]* %3, i64 0, i64 15
%29 = call i32 @strncpy(i8* %8, i8* %28, i32 3)
%30 = call i32 @strcat(i8* %7, i8* %8)
%31 = getelementptr inbounds [21 x i8], [21 x i8]* %4, i64 0, i64 21
store i8 0, i8* %31
%32 = load i32, i32* @O_WRONLY
%33 = call i32 @open(i8* %7, i32 %32)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %21
%36 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %47
37: ; preds = %21
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %7)
%39 = load i32, i32* @USBDEVFS_RESET
%40 = call i32 @ioctl(i32 %33, i32 %39, i32 0)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %47
44: ; preds = %37
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%46 = call i32 @close(i32 %33)
br label %47
47: ; preds = %44, %42, %35
%48 = phi i32 [ 1, %35 ], [ 1, %42 ], [ 0, %44 ]
ret i32 %48
}