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

/* Variables and functions */
int /*<<< orphan*/ BUFSIZ;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fread(char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  FILE *read_fp;
  char buffer[BUFSIZ + 1];
  int chars_read;
  memset(buffer, '\0', sizeof(buffer));
  read_fp = popen("cat popen*.c | wc -l", "r");
  if (read_fp != NULL) {
    chars_read = fread(buffer, sizeof(char), BUFSIZ, read_fp);
    while (chars_read > 0) {
      buffer[chars_read - 1] = '\0';
      printf("Reading:-\n %s\n", buffer);
      chars_read = fread(buffer, sizeof(char), BUFSIZ, read_fp);
    }
    pclose(read_fp);
    exit(EXIT_SUCCESS);
  }
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe52(%rip),%rdi
lea    0xe60(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1247 <main+0xe7>
mov    -0x30(%rbp),%rdi
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    1230 <main+0xd0>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,(%rsi,%rax,1)
lea    0xe0f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
jmp    11e7 <main+0x87>
mov    -0x10(%rbp),%rdi
call   1050 <pclose@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e6e(%rip),%r12
mov    (%r12),%edx
add    $0x1,%edx
mov    %rsp,%rbx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe65(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1070 <popen@plt>
test   %rax,%rax
jne    11ba <main+0x5a>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    %rax,%r14
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    120a <main+0xaa>
lea    0xe3b(%rip),%r15
nopl   0x0(%rax)
add    $0xffffffff,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jg     11e0 <main+0x80>
mov    %r14,%rdi
call   1050 <pclose@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [21 x i8] c"cat popen*.c | wc -l\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"Reading:-\0A %s\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @BUFSIZ
%7 = add nsw i32 %6, 1
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %3
%10 = alloca i8, i64 %8
store i64 %8, i64* %4
%11 = trunc i64 %8 to i32
%12 = call i32 @memset(i8* %10, i8 signext 0, i32 %11)
%13 = call i32* @popen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %2
%14 = load i32*, i32** %2
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %37
16: ; preds = %0
%17 = load i32, i32* @BUFSIZ
%18 = load i32*, i32** %2
%19 = call i32 @fread(i8* %10, i32 1, i32 %17, i32* %18)
store i32 %19, i32* %5
br label %20
20: ; preds = %23, %16
%21 = load i32, i32* %5
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %10, i64 %26
store i8 0, i8* %27
%28 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%29 = load i32, i32* @BUFSIZ
%30 = load i32*, i32** %2
%31 = call i32 @fread(i8* %10, i32 1, i32 %29, i32* %30)
store i32 %31, i32* %5
br label %20
32: ; preds = %20
%33 = load i32*, i32** %2
%34 = call i32 @pclose(i32* %33)
%35 = load i32, i32* @EXIT_SUCCESS
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %0
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [21 x i8] c"cat popen*.c | wc -l\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"Reading:-\0A %s\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = load i32, i32* @BUFSIZ
%2 = add nsw i32 %1, 1
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @memset(i8* %4, i8 signext 0, i32 %2)
%6 = call i32* @popen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %25, label %8
8: ; preds = %0
%9 = load i32, i32* @BUFSIZ
%10 = call i32 @fread(i8* %4, i32 1, i32 %9, i32* %6)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %8, %12
%13 = phi i32 [ %19, %12 ], [ %10, %8 ]
%14 = add nsw i32 %13, -1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %4, i64 %15
store i8 0, i8* %16
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%18 = load i32, i32* @BUFSIZ
%19 = call i32 @fread(i8* %4, i32 1, i32 %18, i32* %6)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %12, label %21
21: ; preds = %12, %8
%22 = call i32 @pclose(i32* %6)
%23 = load i32, i32* @EXIT_SUCCESS
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %0
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
}