#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 /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int main() {
  FILE *filp = 0;
  char command[100] = "ls /";
  filp = popen(command, "r");
  if (filp) {
    pclose(filp);
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
movb   $0x6c,-0x80(%rbp)
movb   $0x73,-0x7f(%rbp)
movb   $0x20,-0x7e(%rbp)
movb   $0x2f,-0x7d(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119e <main+0x6e>
mov    -0x10(%rbp),%rdi
call   1030 <pclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <main+0x75>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x68,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x60(%rsp)
movl   $0x2f20736c,(%rsp)
lea    0xea6(%rip),%rsi
mov    %rsp,%rdi
call   1040 <popen@plt>
test   %rax,%rax
je     1176 <main+0x56>
mov    %rax,%rdi
call   1030 <pclose@plt>
xor    %eax,%eax
add    $0x68,%rsp
ret
mov    $0xffffffff,%eax
add    $0x68,%rsp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [100 x i8]
store i32 0, i32* %1
store i32* null, i32** %2
%4 = bitcast [100 x i8]* %3 to i8*
%5 = bitcast i8* %4 to [100 x i8]*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i32 0, i32 0
store i8 108, i8* %6
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i32 0, i32 1
store i8 115, i8* %7
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i32 0, i32 2
store i8 32, i8* %8
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i32 0, i32 3
store i8 47, i8* %9
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%11 = call i32* @popen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = load i32*, i32** %2
%16 = call i32 @pclose(i32* %15)
store i32 0, i32* %1
br label %18
17: ; preds = %0
store i32 -1, i32* %1
br label %18
18: ; preds = %17, %14
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
store i8 108, i8* %2
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
store i8 115, i8* %3
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
store i8 32, i8* %4
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 3
store i8 47, i8* %5
%6 = call i32* @popen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = tail call i32 @pclose(i32* %6)
br label %10
10: ; preds = %0, %8
%11 = phi i32 [ 0, %8 ], [ -1, %0 ]
ret i32 %11
}