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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *stdin;
int shell() {
  FILE *in;
  extern FILE *popen();
  char buff[512];
  char entrada[500];
  printf("---");
  fgets(entrada, 500, stdin);
  if (!(in = popen(entrada, "r"))) {
    exit(1);
  }
  while (fgets(buff, sizeof(buff), in) != NULL) {
    printf("%s", buff);
  }
  pclose(in);
}


x86 assembly (clang, -O0):
<shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%rdx
mov    $0x1f4,%esi
call   1050 <fgets@plt>
lea    -0x410(%rbp),%rdi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1060 <popen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b1 <shell+0x61>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11b6 <shell+0x66>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11ef <shell+0x9f>
lea    -0x210(%rbp),%rsi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b6 <shell+0x66>
mov    -0x10(%rbp),%rdi
call   1040 <pclose@plt>
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shell>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%rdx
lea    0x200(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1f4,%esi
call   1050 <fgets@plt>
lea    0xe74(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <popen@plt>
test   %rax,%rax
je     1207 <shell+0xb7>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11f2 <shell+0xa2>
lea    0xe48(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11d0 <shell+0x80>
mov    %r15,%rdi
call   1040 <pclose@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0x1,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@.str = [4 x i8] c"---\00"
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @shell() {
%1 = alloca [512 x i8]
%2 = alloca [500 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = load i32*, i32** @stdin
%7 = call i32* @fgets(i8* %4, i32 500, i32* %6)
%8 = call i32* (i8*, i8*, ...) bitcast (i32* (...)* @popen to i32* (i8*, i8*, ...)*)(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = call i32* @fgets(i8* %3, i32 512, i32* %8)
%12 = icmp eq i32* %11, null
br i1 %12, label %19, label %15
13: ; preds = %0
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %10, %15
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%17 = call i32* @fgets(i8* %3, i32 512, i32* %8)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %15
19: ; preds = %15, %10
%20 = call i32 @pclose(i32* %8)
ret i32 undef
}