#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 *);
char *strdup(char *);
int /*<<< orphan*/ string_input(char *, int /*<<< orphan*/ *, int);
char *pipe2string(char *sys_string) {
  char buffer[131072];
  FILE *p;
  int null_input = 0;
  if (!sys_string)
    return (char *)0;
  *buffer = '\0';
  p = popen(sys_string, "r");
  if (!string_input(buffer, p, 131072))
    null_input = 1;
  pclose(p);
  if (null_input)
    return (char *)0;
  else
    return strdup(buffer);
}


x86 assembly (clang, -O0):
<pipe2string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20020,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x2001c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1171 <pipe2string+0x31>
movq   $0x0,-0x8(%rbp)
jmp    11f0 <pipe2string+0xb0>
movb   $0x0,-0x20010(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x20018(%rbp)
lea    -0x20010(%rbp),%rdi
mov    -0x20018(%rbp),%rsi
mov    $0x20000,%edx
call   1040 <string_input@plt>
cmp    $0x0,%eax
jne    11ba <pipe2string+0x7a>
movl   $0x1,-0x2001c(%rbp)
mov    -0x20018(%rbp),%rdi
call   1030 <pclose@plt>
cmpl   $0x0,-0x2001c(%rbp)
je     11e0 <pipe2string+0xa0>
movq   $0x0,-0x8(%rbp)
jmp    11f0 <pipe2string+0xb0>
lea    -0x20010(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pipe2string>:
push   %rbp
push   %rbx
sub    $0x20008,%rsp
test   %rdi,%rdi
je     1189 <pipe2string+0x49>
movb   $0x0,(%rsp)
lea    0xea7(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    %rax,%rsi
mov    $0x20000,%edx
call   1040 <string_input@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <pclose@plt>
test   %ebp,%ebp
je     1189 <pipe2string+0x49>
mov    %rsp,%rdi
call   1060 <strdup@plt>
jmp    118b <pipe2string+0x4b>
xor    %eax,%eax
add    $0x20008,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i8* @pipe2string(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [131072 x i8]
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %6
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i8* null, i8** %2
br label %28
10: ; preds = %1
%11 = getelementptr inbounds [131072 x i8], [131072 x i8]* %4, i64 0, i64 0
store i8 0, i8* %11
%12 = load i8*, i8** %3
%13 = call i32* @popen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %5
%14 = getelementptr inbounds [131072 x i8], [131072 x i8]* %4, i64 0, i64 0
%15 = load i32*, i32** %5
%16 = call i32 @string_input(i8* %14, i32* %15, i32 131072)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %10
store i32 1, i32* %6
br label %19
19: ; preds = %18, %10
%20 = load i32*, i32** %5
%21 = call i32 @pclose(i32* %20)
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i8* null, i8** %2
br label %28
25: ; preds = %19
%26 = getelementptr inbounds [131072 x i8], [131072 x i8]* %4, i64 0, i64 0
%27 = call i8* @strdup(i8* %26)
store i8* %27, i8** %2
br label %28
28: ; preds = %25, %24, %9
%29 = load i8*, i8** %2
ret i8* %29
}

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