#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);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int main(void) {
  char line[4096];
  FILE *fpin;
  if ((fpin = popen("./myuclc", "r")) == NULL) {
    fprintf(stderr, "popen error");
    exit(1);
  }
  while (strcmp(line, "111\n") != 0) {
    fputs("prompt> ", stdout);
    fflush(stdout);
    if (fgets(line, 4096, fpin) == NULL)
      break;
    if (fputs(line, stdout) == EOF)
      fprintf(stderr, "fputs error to pipe");
  }
  if (pclose(fpin) == -1) {
    fprintf(stderr, "pclose error");
    exit(1);
  }
  putchar('\n');
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rdi
lea    0xe92(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x1018(%rbp)
cmp    $0x0,%rax
jne    11e5 <main+0x55>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    11ea <main+0x5a>
lea    -0x1010(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1290 <main+0x100>
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
lea    0xe03(%rip),%rdi
call   1050 <fputs@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
lea    -0x1010(%rbp),%rdi
mov    -0x1018(%rbp),%rdx
mov    $0x1000,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1251 <main+0xc1>
jmp    1290 <main+0x100>
lea    -0x1010(%rbp),%rdi
mov    0x2d71(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    0x2d7b(%rip),%rcx
cmp    (%rcx),%rax
jne    128b <main+0xfb>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
lea    0xd9d(%rip),%rsi
call   1080 <fprintf@plt>
jmp    11ea <main+0x5a>
mov    -0x1018(%rbp),%rdi
call   1040 <pclose@plt>
cmp    $0xffffffff,%eax
jne    12c4 <main+0x134>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
lea    0xd82(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
lea    0xe58(%rip),%rdi
lea    0xe93(%rip),%rsi
call   10a0 <popen@plt>
test   %rax,%rax
jne    11cb <main+0x3b>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
jmp    1203 <main+0x73>
mov    %rax,%r15
lea    0xe40(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1212 <main+0x82>
mov    %r15,%rdi
call   1040 <pclose@plt>
cmp    $0xffffffff,%eax
jne    12a4 <main+0x114>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2db7(%rip),%rbp
lea    0xdfa(%rip),%r14
mov    %rsp,%rbx
mov    0x2dbe(%rip),%r12
lea    0xde4(%rip),%r13
jmp    1250 <main+0xc0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11e2 <main+0x52>
mov    0x0(%rbp),%esi
mov    %r14,%rdi
call   1050 <fputs@plt>
mov    0x0(%rbp),%edi
call   1090 <fflush@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11e2 <main+0x52>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1050 <fputs@plt>
cmp    (%r12),%rax
jne    1240 <main+0xb0>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
lea    0xd86(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1240 <main+0xb0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

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

LLVM IR (-O2):
@.str = [9 x i8] c"./myuclc\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [12 x i8] c"popen error\00"
@.str.3 = [5 x i8] c"111\0A\00"
@.str.4 = [9 x i8] c"prompt> \00"
@stdout = global i32 0
@EOF = global i64 0
@.str.5 = [20 x i8] c"fputs error to pipe\00"
@.str.6 = [13 x i8] c"pclose error\00"
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @popen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %30, label %12
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %5, %27
%13 = load i32, i32* @stdout
%14 = call i64 @fputs(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @stdout
%16 = call i32 @fflush(i32 %15)
%17 = call i32* @fgets(i8* %2, i32 4096, i32* %3)
%18 = icmp eq i32* %17, null
br i1 %18, label %30, label %19
19: ; preds = %12
%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 %27
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %27
27: ; preds = %24, %19
%28 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %12
30: ; preds = %27, %12, %5
%31 = call i32 @pclose(i32* %3)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %30
%38 = call i32 @putchar(i8 signext 10)
%39 = call i32 @exit(i32 0)
unreachable
}