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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main(int argc, char **argv) {
  FILE *fp;
  char buf[1024];
  while (1) {
    printf("> ");
    scanf("%1023[^;];", buf);
    fp = popen(buf, "r");
    if (fp == NULL)
      return 1;
    while (fgets(buf, sizeof(buf) - 1, fp) != NULL)
      printf("%s", buf);
    pclose(fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x420(%rbp),%rsi
lea    0xe7e(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x420(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ba <main+0x6a>
mov    $0x1,%eax
add    $0x420,%rsp
pop    %rbp
ret
jmp    11bf <main+0x6f>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x3ff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11f8 <main+0xa8>
lea    -0x420(%rbp),%rsi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bf <main+0x6f>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
jmp    1169 <main+0x19>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe8d(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xe86(%rip),%rsi
mov    %rbx,%rdi
call   1070 <popen@plt>
test   %rax,%rax
je     1212 <main+0xc2>
mov    %rax,%rbp
mov    %rsp,%rbx
lea    0xe5e(%rip),%r14
lea    0xe5a(%rip),%r15
lea    0xe5e(%rip),%r12
lea    0xe59(%rip),%r13
jmp    11cd <main+0x7d>
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x3ff,%esi
mov    %rbp,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11c0 <main+0x70>
mov    %rbp,%rdi
call   1040 <pclose@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <popen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11cd <main+0x7d>
mov    $0x1,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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