#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 */

/* Variables and functions */
int ejecuta_comando(char **, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ help();
int /*<<< orphan*/ init_shell();
int lee_linea(char *, char **);
int /*<<< orphan*/ libera_mem_arg(char **, int);
int /*<<< orphan*/ nueva_linea(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ show_prompt();
main() {
  char *argumentos[256];
  int narg, i, j, status;
  int fin = 0;
  char linea[1024];
  init_shell();
  help();
  while (!fin) {
    show_prompt();
    nueva_linea(linea, 1024);
    narg = lee_linea(linea, argumentos);
    fin = ejecuta_comando(argumentos, narg);
    libera_mem_arg(argumentos, narg);
  }
  printf("Bye\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x824(%rbp)
mov    $0x0,%al
call   1050 <init_shell@plt>
mov    $0x0,%al
call   10a0 <help@plt>
cmpl   $0x0,-0x824(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d3 <main+0x43>
jmp    1233 <main+0xa3>
mov    $0x0,%al
call   1040 <show_prompt@plt>
lea    -0xc30(%rbp),%rdi
mov    $0x400,%esi
call   1030 <nueva_linea@plt>
lea    -0xc30(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1070 <lee_linea@plt>
mov    %eax,-0x814(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x814(%rbp),%esi
call   1090 <ejecuta_comando@plt>
mov    %eax,-0x824(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x814(%rbp),%esi
call   1080 <libera_mem_arg@plt>
jmp    11ba <main+0x2a>
lea    0xdc6(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xc08,%rsp
xor    %eax,%eax
call   1060 <init_shell@plt>
xor    %eax,%eax
call   10a0 <help@plt>
mov    %rsp,%r14
lea    0x400(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <show_prompt@plt>
mov    %r14,%rdi
mov    $0x400,%esi
call   1040 <nueva_linea@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <lee_linea@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
call   1090 <ejecuta_comando@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %ebp,%esi
call   1080 <libera_mem_arg@plt>
test   %ebx,%ebx
je     11c0 <main+0x30>
lea    0xdfe(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"Bye\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8*]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
store i32 0, i32* %1
store i32 0, i32* %7
%9 = call i32 (...) @init_shell()
%10 = call i32 (...) @help()
br label %11
11: ; preds = %15, %0
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = call i32 (...) @show_prompt()
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%18 = call i32 @nueva_linea(i8* %17, i32 1024)
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%20 = getelementptr inbounds [256 x i8*], [256 x i8*]* %2, i64 0, i64 0
%21 = call i32 @lee_linea(i8* %19, i8** %20)
store i32 %21, i32* %3
%22 = getelementptr inbounds [256 x i8*], [256 x i8*]* %2, i64 0, i64 0
%23 = load i32, i32* %3
%24 = call i32 @ejecuta_comando(i8** %22, i32 %23)
store i32 %24, i32* %7
%25 = getelementptr inbounds [256 x i8*], [256 x i8*]* %2, i64 0, i64 0
%26 = load i32, i32* %3
%27 = call i32 @libera_mem_arg(i8** %25, i32 %26)
br label %11
28: ; preds = %11
%29 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@str = [4 x i8] c"Bye\00"
define i32 @main() {
%1 = alloca [256 x i8*]
%2 = alloca [1024 x i8]
%3 = bitcast [256 x i8*]* %1 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (...) @init_shell()
%6 = tail call i32 (...) @help()
%7 = getelementptr inbounds [256 x i8*], [256 x i8*]* %1, i64 0, i64 0
br label %8
8: ; preds = %0, %8
%9 = call i32 (...) @show_prompt()
%10 = call i32 @nueva_linea(i8* %4, i32 1024)
%11 = call i32 @lee_linea(i8* %4, i8** %7)
%12 = call i32 @ejecuta_comando(i8** %7, i32 %11)
%13 = call i32 @libera_mem_arg(i8** %7, i32 %11)
%14 = icmp eq i32 %12, 0
br i1 %14, label %8, label %15
15: ; preds = %8
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
}