#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*/ getline(char **, int *, int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strcmp(char *, char *);
int main(void) {
  FILE *in;
  extern FILE *popen();
  char buff[512];
  char *entrada;
  int n = 512;
  char salir[4];
  entrada = (char *)malloc(n);
  printf("\n");
  while (1) {
    printf("Mini_shell@tarea:~$ ");
    getline(&entrada, &n, stdin);
    salir[0] = entrada[0];
    salir[1] = entrada[1];
    salir[2] = entrada[2];
    salir[3] = entrada[3];
    if (strcmp(salir, "quit") == 1) {
      printf("Saliendo de la Mini_shell\n");
      printf("\n");
      exit(0);
    }
    if (!(in = popen(entrada, "r"))) {
      exit(1);
    }
    while (fgets(buff, sizeof(buff), in) != NULL) {
      printf("%s", buff);
    }
  }
  pclose(in);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x200,-0x21c(%rbp)
mov    -0x21c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x218(%rbp)
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
lea    -0x218(%rbp),%rdi
lea    -0x21c(%rbp),%rsi
call   1080 <getline@plt>
mov    -0x218(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x220(%rbp)
mov    -0x218(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x21f(%rbp)
mov    -0x218(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x21e(%rbp)
mov    -0x218(%rbp),%rax
mov    0x3(%rax),%al
mov    %al,-0x21d(%rbp)
lea    -0x220(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x1,%eax
jne    1254 <main+0xe4>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x218(%rbp),%rdi
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1070 <popen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1281 <main+0x111>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1286 <main+0x116>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     12bf <main+0x14f>
lea    -0x210(%rbp),%rsi
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1286 <main+0x116>
jmp    11ac <main+0x3c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
movl   $0x200,0x4(%rsp)
mov    $0x200,%edi
call   1080 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rsp,%r13
lea    0xe4e(%rip),%rbp
lea    0x10(%rsp),%r14
lea    0xe44(%rip),%r15
nopl   0x0(%rax,%rax,1)
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
call   10a0 <getline@plt>
mov    0x8(%rsp),%rbx
mov    (%rbx),%al
mov    %al,(%rsp)
mov    0x1(%rbx),%al
mov    %al,0x1(%rsp)
mov    0x2(%rbx),%al
mov    %al,0x2(%rsp)
mov    0x3(%rbx),%al
mov    %al,0x3(%rsp)
mov    %r13,%rdi
lea    0xde6(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x1,%eax
je     1278 <main+0xe8>
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1090 <popen@plt>
test   %rax,%rax
je     1295 <main+0x105>
mov    %rax,%r12
xchg   %ax,%ax
mov    %r14,%rdi
mov    $0x200,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11e0 <main+0x50>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1250 <main+0xc0>
lea    0xda0(%rip),%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [21 x i8] c"Mini_shell@tarea:~$ \00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"quit\00"
@.str.3 = [27 x i8] c"Saliendo de la Mini_shell\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [512 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [4 x i8]
store i32 0, i32* %1
store i32 512, i32* %5
%7 = load i32, i32* %5
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %0, %53
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = call i32 @getline(i8** %4, i32* %5, i32 %13)
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
store i8 %17, i8* %18
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
store i8 %21, i8* %22
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 2
%25 = load i8, i8* %24
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
store i8 %25, i8* %26
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 3
%29 = load i8, i8* %28
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
store i8 %29, i8* %30
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %38
34: ; preds = %11
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %11
%39 = load i8*, i8** %4
%40 = call i32* (i8*, i8*, ...) bitcast (i32* (...)* @popen to i32* (i8*, i8*, ...)*)(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %40, i32** %2
%41 = icmp ne i32* %40, null
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %38
br label %45
45: ; preds = %50, %44
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%47 = load i32*, i32** %2
%48 = call i32* @fgets(i8* %46, i32 512, i32* %47)
%49 = icmp ne i32* %48, null
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %51)
br label %45
53: ; preds = %45
br label %11
}

LLVM IR (-O2):
@.str.1 = [21 x i8] c"Mini_shell@tarea:~$ \00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"quit\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%s\00"
@str = [26 x i8] c"Saliendo de la Mini_shell\00"
define i32 @main() {
%1 = alloca [512 x i8]
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [4 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%6 = bitcast i8** %2 to i8*
%7 = bitcast i32* %3 to i8*
store i32 512, i32* %3
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%9 = tail call i64 @malloc(i32 512)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %2
%11 = tail call i32 @putchar(i32 10)
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
br label %15
15: ; preds = %39, %0
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @stdin
%18 = call i32 @getline(i8** %2, i32* %3, i32 %17)
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
store i8 %20, i8* %8
%21 = getelementptr inbounds i8, i8* %19, i64 1
%22 = load i8, i8* %21
store i8 %22, i8* %12
%23 = getelementptr inbounds i8, i8* %19, i64 2
%24 = load i8, i8* %23
store i8 %24, i8* %13
%25 = getelementptr inbounds i8, i8* %19, i64 3
%26 = load i8, i8* %25
store i8 %26, i8* %14
%27 = call i32 @strcmp(i8* %8, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %33
29: ; preds = %15
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%31 = call i32 @putchar(i32 10)
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %15
%34 = call i32* (i8*, i8*, ...) bitcast (i32* (...)* @popen to i32* (i8*, i8*, ...)*)(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%35 = icmp eq i32* %34, null
br i1 %35, label %40, label %36
36: ; preds = %33
%37 = call i32* @fgets(i8* %5, i32 512, i32* %34)
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %42
39: ; preds = %42, %36
br label %15
40: ; preds = %33
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %36, %42
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%44 = call i32* @fgets(i8* %5, i32 512, i32* %34)
%45 = icmp eq i32* %44, null
br i1 %45, label %39, label %42
}