#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*/ perror(char *);
char *read_prompt();
int /*<<< orphan*/ wait(void *);
int main(int argc, char **argv) {
  char *input;
  char **arguments;
  while ((input = read_prompt())) {
    arguments = (char **)counting_malloc(sizeof(char *) * (1 + 1));
    if (arguments == NULL) {
      perror("Unable to allocate necessary memory");
      exit(EXIT_FAILURE);
    }
    arguments[0] = input;
    arguments[1] = (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    $0x20,%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     122d <main+0xad>
mov    $0x10,%edi
call   1060 <counting_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11de <main+0x5e>
lea    0xe35(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <do_exit@plt>
cmp    $0x0,%rax
je     120d <main+0x8d>
jmp    122d <main+0xad>
mov    -0x20(%rbp),%rdi
call   1080 <execute_command@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <wait@plt>
mov    -0x18(%rbp),%rdi
call   1030 <counting_free@plt>
jmp    1196 <main+0x16>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <read_prompt@plt>
test   %rax,%rax
je     11f0 <main+0x70>
mov    %rax,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x10,%edi
call   1060 <counting_malloc@plt>
test   %rax,%rax
je     11fe <main+0x7e>
mov    %rax,%rbx
mov    %r14,(%rax)
movq   $0x0,0x8(%rax)
mov    %rax,%rdi
call   1040 <do_exit@plt>
test   %rax,%rax
jne    11f0 <main+0x70>
mov    %rbx,%rdi
call   1080 <execute_command@plt>
xor    %edi,%edi
call   10a0 <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    11a0 <main+0x20>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xdfb(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1090 <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 i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %30, %2
%9 = call i8* (...) @read_prompt()
store i8* %9, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %36
11: ; preds = %8
%12 = call i64 @counting_malloc(i32 16)
%13 = inttoptr i64 %12 to i8**
store i8** %13, i8*** %7
%14 = load i8**, i8*** %7
%15 = icmp eq i8** %14, null
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %11
%21 = load i8*, i8** %6
%22 = load i8**, i8*** %7
%23 = getelementptr inbounds i8*, i8** %22, i64 0
store i8* %21, i8** %23
%24 = load i8**, i8*** %7
%25 = getelementptr inbounds i8*, i8** %24, i64 1
store i8* null, i8** %25
%26 = load i8**, i8*** %7
%27 = call i64 @do_exit(i8** %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %20
br label %36
30: ; preds = %20
%31 = load i8**, i8*** %7
%32 = call i32 @execute_command(i8** %31)
%33 = call i32 @wait(i8* null)
%34 = load i8*, i8** %6
%35 = call i32 @counting_free(i8* %34)
br label %8
36: ; preds = %29, %8
%37 = load i32, i32* @EXIT_SUCCESS
%38 = call i32 @exit(i32 %37)
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 %24, label %5
5: ; preds = %2, %18
%6 = phi i8* [ %22, %18 ], [ %3, %2 ]
%7 = tail call i64 @counting_malloc(i32 16)
%8 = inttoptr i64 %7 to i8**
%9 = icmp eq i64 %7, 0
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = tail call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %5
store i8* %6, i8** %8
%15 = getelementptr inbounds i8*, i8** %8, i64 1
store i8* null, i8** %15
%16 = tail call i64 @do_exit(i8** %8)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = tail call i32 @execute_command(i8** %8)
%20 = tail call i32 @wait(i8* null)
%21 = tail call i32 @counting_free(i8* %6)
%22 = tail call i8* (...) @read_prompt()
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %5
24: ; preds = %18, %14, %2
%25 = load i32, i32* @EXIT_SUCCESS
%26 = tail call i32 @exit(i32 %25)
unreachable
}