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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  printf("----------------------------------------------------------------\n");
  FILE *in;
  char salir[5];
  extern FILE *popen();
  char command[256];
  char buff[1024];
  while (1) {
    printf("mini_shell> ");
    fgets(command, sizeof(command), stdin);
    salir[0] = command[0];
    salir[1] = command[1];
    salir[2] = command[2];
    salir[3] = command[3];
    if (!strcmp(salir, "exit")) {
      exit(0);
    } else {
      in = popen(command, "r");
      while (fgets(buff, sizeof(buff), in) != NULL) {
        printf("%s", buff);
      }
      pclose(in);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x520,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
mov    -0x120(%rbp),%al
mov    %al,-0x1d(%rbp)
mov    -0x11f(%rbp),%al
mov    %al,-0x1c(%rbp)
mov    -0x11e(%rbp),%al
mov    %al,-0x1b(%rbp)
mov    -0x11d(%rbp),%al
mov    %al,-0x1a(%rbp)
lea    -0x1d(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11f4 <main+0x94>
xor    %edi,%edi
call   1080 <exit@plt>
lea    -0x120(%rbp),%rdi
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1070 <popen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x520(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1246 <main+0xe6>
lea    -0x520(%rbp),%rsi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120d <main+0xad>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
jmp    1187 <main+0x27>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x518,%rsp
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e64(%rip),%r14
lea    0x10(%rsp),%r12
lea    0xe82(%rip),%r15
lea    0x110(%rsp),%rbx
lea    0xe75(%rip),%r13
jmp    11b8 <main+0x58>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1050 <pclose@plt>
lea    0xe41(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%rdx
mov    %r12,%rdi
mov    $0x100,%esi
call   1060 <fgets@plt>
mov    0x10(%rsp),%eax
mov    %eax,0xb(%rsp)
xor    $0x74697865,%eax
movzbl 0xf(%rsp),%ecx
or     %eax,%ecx
je     1234 <main+0xd4>
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <popen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
nopw   0x0(%rax,%rax,1)
call   1060 <fgets@plt>
test   %rax,%rax
je     11b0 <main+0x50>
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rbp,%rdx
jmp    1210 <main+0xb0>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [66 x i8] c"----------------------------------------------------------------\0A\00"
@.str.1 = [13 x i8] c"mini_shell> \00"
@stdin = global i32* null
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [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 [5 x i8]
%8 = alloca [256 x i8]
%9 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %2, %47
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%14 = load i32*, i32** @stdin
%15 = call i32* @fgets(i8* %13, i32 256, i32* %14)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%17 = load i8, i8* %16
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
store i8 %17, i8* %18
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 1
%20 = load i8, i8* %19
%21 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 1
store i8 %20, i8* %21
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 2
%23 = load i8, i8* %22
%24 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 2
store i8 %23, i8* %24
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 3
%26 = load i8, i8* %25
%27 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 3
store i8 %26, i8* %27
%28 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %11
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %11
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%35 = call i32* (i8*, i8*, ...) bitcast (i32* (...)* @popen to i32* (i8*, i8*, ...)*)(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %35, i32** %6
br label %36
36: ; preds = %41, %33
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%38 = load i32*, i32** %6
%39 = call i32* @fgets(i8* %37, i32 1024, i32* %38)
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %42)
br label %36
44: ; preds = %36
%45 = load i32*, i32** %6
%46 = call i32 @pclose(i32* %45)
br label %47
47: ; preds = %44
br label %11
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"mini_shell> \00"
@stdin = global i32* null
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"%s\00"
@str = [65 x i8] c"----------------------------------------------------------------\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [5 x i8]
%4 = alloca [256 x i8]
%5 = alloca [1024 x i8]
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str, i64 0, i64 0))
%7 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 1
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 1
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 2
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 2
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 3
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 3
br label %16
16: ; preds = %36, %2
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32*, i32** @stdin
%19 = call i32* @fgets(i8* %8, i32 256, i32* %18)
%20 = load i8, i8* %8
store i8 %20, i8* %7
%21 = load i8, i8* %10
store i8 %21, i8* %11
%22 = load i8, i8* %12
store i8 %22, i8* %13
%23 = load i8, i8* %14
store i8 %23, i8* %15
%24 = call i32 @bcmp(i8* dereferenceable(5) %7, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 5)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %16
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %16
%29 = call i32* (i8*, i8*, ...) bitcast (i32* (...)* @popen to i32* (i8*, i8*, ...)*)(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32* @fgets(i8* %9, i32 1024, i32* %29)
%31 = icmp eq i32* %30, null
br i1 %31, label %36, label %32
32: ; preds = %28, %32
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%34 = call i32* @fgets(i8* %9, i32 1024, i32* %29)
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %32
36: ; preds = %32, %28
%37 = call i32 @pclose(i32* %29)
br label %16
}