#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*/ FILE;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  char *cmd = "lsusb";
  char buf[BUFSIZ];
  FILE *ptr;
  cmd = argv[1];
  if ((ptr = popen(cmd, "r")) != NULL) {
    while (fgets(buf, BUFSIZ, ptr) != NULL) {
      (void)printf("%s", buf);
    }
    (void)pclose(ptr);
  }
  return 0;
}


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)
lea    0xea3(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11fa <main+0xba>
jmp    11bc <main+0x7c>
mov    -0x38(%rbp),%rdi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
mov    -0x30(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11f1 <main+0xb1>
mov    -0x38(%rbp),%rsi
lea    0xe21(%rip),%rdi
call   1030 <printf@plt>
jmp    11bc <main+0x7c>
mov    -0x30(%rbp),%rdi
call   1040 <pclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e8e(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x8(%rsi),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     11c7 <main+0x87>
mov    %rax,%r14
mov    (%r12),%esi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11bf <main+0x7f>
lea    0xe68(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    (%r12),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11a0 <main+0x60>
mov    %r14,%rdi
call   1040 <pclose@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"lsusb\00"
@BUFSIZ = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %6
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = call i32* @popen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %9
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %31
20: ; preds = %2
br label %21
21: ; preds = %26, %20
%22 = load i32, i32* @BUFSIZ
%23 = load i32*, i32** %9
%24 = call i32* @fgets(i8* %13, i32 %22, i32* %23)
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %21
28: ; preds = %21
%29 = load i32*, i32** %9
%30 = call i32 @pclose(i32* %29)
br label %31
31: ; preds = %28, %2
store i32 0, i32* %3
%32 = load i8*, i8** %7
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @popen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %21, label %10
10: ; preds = %2
%11 = load i32, i32* @BUFSIZ
%12 = call i32* @fgets(i8* %5, i32 %11, i32* %8)
%13 = icmp eq i32* %12, null
br i1 %13, label %19, label %14
14: ; preds = %10, %14
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%16 = load i32, i32* @BUFSIZ
%17 = call i32* @fgets(i8* %5, i32 %16, i32* %8)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %14
19: ; preds = %14, %10
%20 = call i32 @pclose(i32* %8)
br label %21
21: ; preds = %19, %2
ret i32 0
}