#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  FILE *fp;
  FILE *fp2;
  int status;
  char path[1024];
  char path2[1024];
  fp = popen("ls -al ", "r");
  while (fgets(path, 1024, fp) != NULL) {
    printf("%s", path);
  }
  fp2 = popen("awk '{print $1}'", "r");
  while (fgets(path2, 1024, fp2) != NULL) {
    printf("%s", path2);
  }
  status = pclose(fp);
  status = pclose(fp2);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11b7 <main+0x67>
lea    -0x430(%rbp),%rsi
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
jmp    1180 <main+0x30>
lea    0xe4f(%rip),%rdi
lea    0xe43(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x830(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1205 <main+0xb5>
lea    -0x830(%rbp),%rsi
lea    0xe0f(%rip),%rdi
call   1030 <printf@plt>
jmp    11ce <main+0x7e>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <pclose@plt>
mov    %eax,-0x24(%rbp)
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
lea    0xe9b(%rip),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,%r14
lea    0x400(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11c0 <main+0x70>
lea    0xe75(%rip),%r15
lea    0x400(%rsp),%rbx
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11a0 <main+0x50>
lea    0xe46(%rip),%rdi
lea    0xe3a(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,%r12
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1220 <main+0xd0>
lea    0xe18(%rip),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1200 <main+0xb0>
mov    %r14,%rdi
call   1040 <pclose@plt>
mov    %r12,%rdi
call   1040 <pclose@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"ls -al \00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [17 x i8] c"awk '{print $1}'\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 [1024 x i8]
%10 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32* @popen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
br label %12
12: ; preds = %17, %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%14 = load i32*, i32** %6
%15 = call i32* @fgets(i8* %13, i32 1024, i32* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %12
20: ; preds = %12
%21 = call i32* @popen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %7
br label %22
22: ; preds = %27, %20
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%24 = load i32*, i32** %7
%25 = call i32* @fgets(i8* %23, i32 1024, i32* %24)
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %22
30: ; preds = %22
%31 = load i32*, i32** %6
%32 = call i32 @pclose(i32* %31)
store i32 %32, i32* %8
%33 = load i32*, i32** %7
%34 = call i32 @pclose(i32* %33)
store i32 %34, i32* %8
%35 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"ls -al \00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [17 x i8] c"awk '{print $1}'\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @popen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32* @fgets(i8* %5, i32 1024, i32* %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %2, %10
%11 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%12 = call i32* @fgets(i8* %5, i32 1024, i32* %7)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %10
14: ; preds = %10, %2
%15 = call i32* @popen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32* @fgets(i8* %6, i32 1024, i32* %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %22, label %18
18: ; preds = %14, %18
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%20 = call i32* @fgets(i8* %6, i32 1024, i32* %15)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %18
22: ; preds = %18, %14
%23 = call i32 @pclose(i32* %7)
%24 = call i32 @pclose(i32* %15)
%25 = call i32 @exit(i32 0)
unreachable
}