#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 */
scalar_t__ EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stdout;
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main() {
  char line[(8092)] = {0};
  FILE *fpin;
  char *result = "result:";
  strncpy(line, result, strlen(result));
  if ((fpin = popen("ps", "r")) == NULL) {
    printf("error: popen\n");
  }
  while (1) {
    fputs("prompt> ", stdout);
    fflush(stdout);
    if (fgets(line + strlen(result), (8092), fpin) == NULL) {
      break;
    }
    if (fputs(line, stdout) == EOF) {
      printf("error: fputs\n");
    }
  }
  if (pclose(fpin) == -1) {
    printf("error: pclose\n");
  }
  putchar('\n');
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1fd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x1fa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1f9c,%edx
call   1090 <memset@plt>
lea    0xe24(%rip),%rax
mov    %rax,-0x1fb0(%rbp)
lea    -0x1fa0(%rbp),%rax
mov    %rax,-0x1fc0(%rbp)
mov    -0x1fb0(%rbp),%rax
mov    %rax,-0x1fb8(%rbp)
mov    -0x1fb0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1fc0(%rbp),%rdi
mov    -0x1fb8(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
lea    0xde1(%rip),%rdi
lea    0xddd(%rip),%rsi
call   10c0 <popen@plt>
mov    %rax,-0x1fa8(%rbp)
cmp    $0x0,%rax
jne    1250 <main+0xa0>
lea    0xdc2(%rip),%rdi
call   1060 <printf@plt>
jmp    1255 <main+0xa5>
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
lea    0xdb6(%rip),%rdi
call   1080 <fputs@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
lea    -0x1fa0(%rbp),%rax
mov    %rax,-0x1fc8(%rbp)
mov    -0x1fb0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1fc8(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x1fa8(%rbp),%rdx
mov    $0x1f9c,%esi
call   10a0 <fgets@plt>
cmp    $0x0,%rax
jne    12be <main+0x10e>
jmp    12f4 <main+0x144>
lea    -0x1fa0(%rbp),%rdi
mov    0x2d0c(%rip),%rax
mov    (%rax),%esi
call   1080 <fputs@plt>
mov    0x2d0e(%rip),%rcx
cmp    (%rcx),%rax
jne    12ef <main+0x13f>
lea    0xd3a(%rip),%rdi
call   1060 <printf@plt>
jmp    1255 <main+0xa5>
mov    -0x1fa8(%rbp),%rdi
call   1070 <pclose@plt>
cmp    $0xffffffff,%eax
jne    1315 <main+0x165>
lea    0xd22(%rip),%rdi
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1fa8,%rsp
mov    %rsp,%r14
mov    $0x1f9c,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <memset@plt>
lea    0xe26(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
lea    0xe12(%rip),%rdi
lea    0xe0e(%rip),%rsi
call   10c0 <popen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1216 <main+0x66>
lea    0xe20(%rip),%rdi
call   1050 <puts@plt>
mov    0x2dbb(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xde6(%rip),%rdi
call   1080 <fputs@plt>
mov    0x0(%rbp),%edi
call   10b0 <fflush@plt>
lea    0xdc5(%rip),%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
mov    $0x1f9c,%esi
mov    %rbx,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
jne    1282 <main+0xd2>
mov    %rbx,%rdi
call   1070 <pclose@plt>
cmp    $0xffffffff,%eax
jne    1271 <main+0xc1>
lea    0xdb7(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    %rsp,%r14
mov    0x2d5c(%rip),%r15
lea    0xd7a(%rip),%r12
lea    0xd66(%rip),%r13
jmp    12d3 <main+0x123>
nopl   0x0(%rax)
mov    0x0(%rbp),%esi
mov    %r12,%rdi
call   1080 <fputs@plt>
mov    0x0(%rbp),%edi
call   10b0 <fflush@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
mov    $0x1f9c,%esi
mov    %rbx,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     1258 <main+0xa8>
mov    0x0(%rbp),%esi
mov    %r14,%rdi
call   1080 <fputs@plt>
cmp    (%r15),%rax
jne    12a0 <main+0xf0>
lea    0xd2c(%rip),%rdi
call   1050 <puts@plt>
jmp    12a0 <main+0xf0>

LLVM IR (-O0):
@.str = [8 x i8] c"result:\00"
@.str.1 = [3 x i8] c"ps\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [14 x i8] c"error: popen\0A\00"
@.str.4 = [9 x i8] c"prompt> \00"
@stdout = global i32 0
@EOF = global i64 0
@.str.5 = [14 x i8] c"error: fputs\0A\00"
@.str.6 = [15 x i8] c"error: pclose\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [8092 x i8]
%3 = alloca i32*
%4 = alloca i8*
store i32 0, i32* %1
%5 = bitcast [8092 x i8]* %2 to i8*
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %4
%6 = getelementptr inbounds [8092 x i8], [8092 x i8]* %2, i64 0, i64 0
%7 = load i8*, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = call i32 @strncpy(i8* %6, i8* %7, i32 %9)
%11 = call i32* @popen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %3
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
br label %16
16: ; preds = %15, %38
%17 = load i32, i32* @stdout
%18 = call i64 @fputs(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = load i32, i32* @stdout
%20 = call i32 @fflush(i32 %19)
%21 = getelementptr inbounds [8092 x i8], [8092 x i8]* %2, i64 0, i64 0
%22 = load i8*, i8** %4
%23 = call i32 @strlen(i8* %22)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i32*, i32** %3
%27 = call i32* @fgets(i8* %25, i32 8092, i32* %26)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %16
br label %39
30: ; preds = %16
%31 = getelementptr inbounds [8092 x i8], [8092 x i8]* %2, i64 0, i64 0
%32 = load i32, i32* @stdout
%33 = call i64 @fputs(i8* %31, i32 %32)
%34 = load i64, i64* @EOF
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %38
38: ; preds = %36, %30
br label %16
39: ; preds = %29
%40 = load i32*, i32** %3
%41 = call i32 @pclose(i32* %40)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %45
45: ; preds = %43, %39
%46 = call i32 @putchar(i8 signext 10)
%47 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"result:\00"
@.str.1 = [3 x i8] c"ps\00"
@.str.2 = [2 x i8] c"r\00"
@.str.4 = [9 x i8] c"prompt> \00"
@stdout = global i32 0
@EOF = global i64 0
@str = [13 x i8] c"error: fputs\00"
@str.7 = [14 x i8] c"error: pclose\00"
@str.8 = [13 x i8] c"error: popen\00"
define i32 @main() {
%1 = alloca [8092 x i8]
%2 = getelementptr inbounds [8092 x i8], [8092 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32* @popen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.8, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = load i32, i32* @stdout
%11 = call i64 @fputs(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @stdout
%13 = call i32 @fflush(i32 %12)
%14 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [8092 x i8], [8092 x i8]* %1, i64 0, i64 %15
%17 = call i32* @fgets(i8* %16, i32 8092, i32* %5)
%18 = icmp eq i32* %17, null
br i1 %18, label %36, label %19
19: ; preds = %9, %26
%20 = load i32, i32* @stdout
%21 = call i64 @fputs(i8* %2, i32 %20)
%22 = load i64, i64* @EOF
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %26
26: ; preds = %24, %19
%27 = load i32, i32* @stdout
%28 = call i64 @fputs(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @stdout
%30 = call i32 @fflush(i32 %29)
%31 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [8092 x i8], [8092 x i8]* %1, i64 0, i64 %32
%34 = call i32* @fgets(i8* %33, i32 8092, i32* %5)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %19
36: ; preds = %26, %9
%37 = call i32 @pclose(i32* %5)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.7, i64 0, i64 0))
br label %41
41: ; preds = %39, %36
%42 = call i32 @putchar(i8 signext 10)
%43 = call i32 @exit(i32 0)
unreachable
}