#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ counting_free(char *);
scalar_t__ counting_malloc(int);
scalar_t__ do_exit(char **);
int /*<<< orphan*/ execute_command(char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ get_tokens(char *, char, char **, int);
int num_tokens(char *, char);
int /*<<< orphan*/ perror(char *);
char *read_prompt();
int /*<<< orphan*/ wait(void *);
int main(int argc, char **argv) {
  char *input;
  int num_arguments;
  char **arguments;
  while ((input = read_prompt())) {
    num_arguments = num_tokens(input, ' ');
    arguments = (char **)counting_malloc(sizeof(char *) * (num_arguments + 1));
    if (arguments == NULL) {
      perror("Unable to allocate necessary memory");
      exit(EXIT_FAILURE);
    }
    get_tokens(input, ' ', arguments, num_arguments);
    arguments[num_arguments] = (char *)NULL;
    if (do_exit(arguments)) {
      break;
    }
    execute_command(arguments);
    wait((void *)NULL);
    counting_free(input);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <read_prompt@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1275 <main+0xd5>
mov    -0x18(%rbp),%rdi
mov    $0x20,%esi
call   1070 <num_tokens@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <counting_malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1218 <main+0x78>
lea    0xdfb(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    $0x20,%esi
call   10c0 <get_tokens@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rdi
call   1040 <do_exit@plt>
cmp    $0x0,%rax
je     1255 <main+0xb5>
jmp    1275 <main+0xd5>
mov    -0x28(%rbp),%rdi
call   1090 <execute_command@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <wait@plt>
mov    -0x18(%rbp),%rdi
call   1030 <counting_free@plt>
jmp    11b6 <main+0x16>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <read_prompt@plt>
test   %rax,%rax
je     1236 <main+0x96>
mov    %rax,%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x20,%esi
call   1070 <num_tokens@plt>
mov    %eax,%r15d
lea    0x8(,%r15,8),%edi
call   1060 <counting_malloc@plt>
test   %rax,%rax
je     1244 <main+0xa4>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x20,%esi
mov    %rax,%rdx
mov    %r15d,%ecx
call   10c0 <get_tokens@plt>
movslq %r15d,%rax
movq   $0x0,(%rbx,%rax,8)
mov    %rbx,%rdi
call   1040 <do_exit@plt>
test   %rax,%rax
jne    1236 <main+0x96>
mov    %rbx,%rdi
call   1090 <execute_command@plt>
xor    %edi,%edi
call   10b0 <wait@plt>
mov    %r14,%rdi
call   1030 <counting_free@plt>
xor    %eax,%eax
call   1050 <read_prompt@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11c0 <main+0x20>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xdb5(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Unable to allocate necessary memory\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %9
9: ; preds = %41, %2
%10 = call i8* (...) @read_prompt()
store i8* %10, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %47
12: ; preds = %9
%13 = load i8*, i8** %6
%14 = call i32 @num_tokens(i8* %13, i8 signext 32)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = mul i64 8, %17
%19 = trunc i64 %18 to i32
%20 = call i64 @counting_malloc(i32 %19)
%21 = inttoptr i64 %20 to i8**
store i8** %21, i8*** %8
%22 = load i8**, i8*** %8
%23 = icmp eq i8** %22, null
br i1 %23, label %24, label %28
24: ; preds = %12
%25 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %12
%29 = load i8*, i8** %6
%30 = load i8**, i8*** %8
%31 = load i32, i32* %7
%32 = call i32 @get_tokens(i8* %29, i8 signext 32, i8** %30, i32 %31)
%33 = load i8**, i8*** %8
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
store i8* null, i8** %36
%37 = load i8**, i8*** %8
%38 = call i64 @do_exit(i8** %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %28
br label %47
41: ; preds = %28
%42 = load i8**, i8*** %8
%43 = call i32 @execute_command(i8** %42)
%44 = call i32 @wait(i8* null)
%45 = load i8*, i8** %6
%46 = call i32 @counting_free(i8* %45)
br label %9
47: ; preds = %40, %9
%48 = load i32, i32* @EXIT_SUCCESS
%49 = call i32 @exit(i32 %48)
unreachable
}

LLVM IR (-O2):
@.str = [36 x i8] c"Unable to allocate necessary memory\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8* (...) @read_prompt()
%4 = icmp eq i8* %3, null
br i1 %4, label %29, label %5
5: ; preds = %2, %23
%6 = phi i8* [ %27, %23 ], [ %3, %2 ]
%7 = tail call i32 @num_tokens(i8* %6, i8 signext 32)
%8 = shl i32 %7, 3
%9 = add i32 %8, 8
%10 = tail call i64 @counting_malloc(i32 %9)
%11 = inttoptr i64 %10 to i8**
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %17
13: ; preds = %5
%14 = tail call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %5
%18 = tail call i32 @get_tokens(i8* %6, i8 signext 32, i8** %11, i32 %7)
%19 = sext i32 %7 to i64
%20 = getelementptr inbounds i8*, i8** %11, i64 %19
store i8* null, i8** %20
%21 = tail call i64 @do_exit(i8** %11)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %17
%24 = tail call i32 @execute_command(i8** %11)
%25 = tail call i32 @wait(i8* null)
%26 = tail call i32 @counting_free(i8* %6)
%27 = tail call i8* (...) @read_prompt()
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %5
29: ; preds = %23, %17, %2
%30 = load i32, i32* @EXIT_SUCCESS
%31 = tail call i32 @exit(i32 %30)
unreachable
}