#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*/ call_command(char *, unsigned int, char **);
int /*<<< orphan*/ free_argv(char **, unsigned int);
unsigned int parse_console_line(char *, char ***);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read_console_line(char const *, char *, unsigned int);
void console_run(const char *prompt, unsigned int buffer_size,
                 int (*stop_func)()) {
  char buffer[buffer_size];
  while (!stop_func()) {
    if (read_console_line(prompt, buffer, buffer_size)) {
      char **argv;
      unsigned int argc;
      argc = parse_console_line(buffer, &argv);
      if (argc > 0) {
        if (!call_command(argv[0], argc, argv)) {
          printf("Unknown command '%s' entered\n", argv[0]);
        }
      }
      free_argv(argv, argc);
    }
  }
}


x86 assembly (clang, -O0):
<console_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   *-0x18(%rbp)
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a3 <console_run+0x53>
jmp    121c <console_run+0xcc>
mov    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
call   1040 <read_console_line@plt>
cmp    $0x0,%rax
je     1217 <console_run+0xc7>
mov    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <parse_console_line@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jbe    120b <console_run+0xbb>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1070 <call_command@plt>
cmp    $0x0,%eax
jne    1206 <console_run+0xb6>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    0xdff(%rip),%rdi
call   1060 <printf@plt>
jmp    120b <console_run+0xbb>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1030 <free_argv@plt>
jmp    1189 <console_run+0x39>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<console_run>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%r15
mov    %esi,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
xor    %eax,%eax
call   *%rdx
jmp    1191 <console_run+0x41>
mov    -0x30(%rbp),%rdi
mov    %r13d,%esi
call   1030 <free_argv@plt>
xor    %eax,%eax
call   *%r14
test   %eax,%eax
jne    11e3 <console_run+0x93>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1040 <read_console_line@plt>
test   %rax,%rax
je     118c <console_run+0x3c>
mov    %rbx,%rdi
lea    -0x30(%rbp),%rsi
call   1050 <parse_console_line@plt>
mov    %eax,%r13d
test   %eax,%eax
je     1180 <console_run+0x30>
mov    -0x30(%rbp),%rdx
mov    (%rdx),%rdi
mov    %r13d,%esi
call   1070 <call_command@plt>
test   %eax,%eax
jne    1180 <console_run+0x30>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    0xe24(%rip),%rdi
call   1060 <printf@plt>
jmp    1180 <console_run+0x30>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Unknown command '%s' entered\0A\00"
define void @console_run(i8* %0, i32 %1, i32 (...)* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32 (...)*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8**
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 (...)* %2, i32 (...)** %6
%11 = load i32, i32* %5
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8, i64 %12
store i64 %12, i64* %8
br label %15
15: ; preds = %47, %3
%16 = load i32 (...)*, i32 (...)** %6
%17 = call i32 (...) %16()
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %48
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = call i64 @read_console_line(i8* %21, i8* %14, i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %47
25: ; preds = %20
%26 = call i32 @parse_console_line(i8* %14, i8*** %9)
store i32 %26, i32* %10
%27 = load i32, i32* %10
%28 = icmp ugt i32 %27, 0
br i1 %28, label %29, label %43
29: ; preds = %25
%30 = load i8**, i8*** %9
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = load i32, i32* %10
%34 = load i8**, i8*** %9
%35 = call i32 @call_command(i8* %32, i32 %33, i8** %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %42, label %37
37: ; preds = %29
%38 = load i8**, i8*** %9
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %37, %29
br label %43
43: ; preds = %42, %25
%44 = load i8**, i8*** %9
%45 = load i32, i32* %10
%46 = call i32 @free_argv(i8** %44, i32 %45)
br label %47
47: ; preds = %43, %20
br label %15
48: ; preds = %15
%49 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"Unknown command '%s' entered\0A\00"
define void @console_run(i8* %0, i32 %1, i32 (...)* nocapture %2) {
%4 = alloca i8**
%5 = zext i32 %1 to i64
%6 = alloca i8, i64 %5
%7 = call i32 (...) %2()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %32
9: ; preds = %3
%10 = bitcast i8*** %4 to i8*
br label %11
11: ; preds = %9, %29
%12 = call i64 @read_console_line(i8* %0, i8* %6, i32 %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %29, label %14
14: ; preds = %11
%15 = call i32 @parse_console_line(i8* %6, i8*** %4)
%16 = icmp eq i32 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %14
%18 = load i8**, i8*** %4
%19 = load i8*, i8** %18
%20 = call i32 @call_command(i8* %19, i32 %15, i8** %18)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i8**, i8*** %4
%24 = load i8*, i8** %23
%25 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %17, %22, %14
%27 = load i8**, i8*** %4
%28 = call i32 @free_argv(i8** %27, i32 %15)
br label %29
29: ; preds = %26, %11
%30 = call i32 (...) %2()
%31 = icmp eq i32 %30, 0
br i1 %31, label %11, label %32
32: ; preds = %29, %3
ret void
}