#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*/ b_input(char *, int);
int /*<<< orphan*/ b_output(char *);
int /*<<< orphan*/ b_system_misc(int, ...);
int strlen(char *);
int main() {
  char cmd[129];
  int ti, i;
  unsigned long sleeptime;
  b_output("Console ready.\n");
  while (1) {
    b_output("term> ");
    b_input(cmd, 128);
    if (*cmd == 'h') {
      b_output(
          "Help for Console:\nCommands:\nhelp\tDisplay help\necho\techos "
          "text\nsleep\tdelays for <x> seconds\nexit\treturn to the boring "
          "BMOS shell\ncores\tget number of cores\n\twell, that's it.");
      continue;
    } else if (*cmd == 'e') {
      if (*(cmd + 1) == 'x') {
        return 0;
      } else {
        b_output(cmd + 5);
        continue;
      }
    } else if (*cmd == 's') {
      sleeptime = 0;
      ti = strlen(cmd + 6);
      i = 6;
      for (; ti > 0; ti--) {
        sleeptime += (*(cmd + i) - 30) * (ti * 10);
        i++;
      }
      sleeptime *= 8;
      b_system_misc(6, &sleeptime, 0x0);
      continue;
    } else if (*cmd == 'c') {
      i = 0;
      b_system_misc(9, 0x0, &i);
      b_output("cores: TBI");
      continue;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
call   1050 <b_output@plt>
lea    0xeab(%rip),%rdi
call   1050 <b_output@plt>
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
call   1040 <b_input@plt>
movsbl -0x90(%rbp),%eax
cmp    $0x68,%eax
jne    119c <main+0x5c>
lea    0xe85(%rip),%rdi
call   1050 <b_output@plt>
jmp    115e <main+0x1e>
movsbl -0x90(%rbp),%eax
cmp    $0x65,%eax
jne    11dc <main+0x9c>
movsbl -0x8f(%rbp),%eax
cmp    $0x78,%eax
jne    11c7 <main+0x87>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret
lea    -0x90(%rbp),%rdi
add    $0x5,%rdi
call   1050 <b_output@plt>
jmp    115e <main+0x1e>
movsbl -0x90(%rbp),%eax
cmp    $0x73,%eax
jne    129f <main+0x15f>
movq   $0x0,-0xa0(%rbp)
lea    -0x90(%rbp),%rdi
add    $0x6,%rdi
call   1030 <strlen@plt>
mov    %eax,-0x94(%rbp)
movl   $0x6,-0x98(%rbp)
cmpl   $0x0,-0x94(%rbp)
jle    1273 <main+0x133>
movslq -0x98(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%eax
ff
sub    $0x1e,%eax
imul   $0xa,-0x94(%rbp),%ecx
imul   %ecx,%eax
cltq
add    -0xa0(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
mov    -0x94(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x94(%rbp)
jmp    1217 <main+0xd7>
mov    -0xa0(%rbp),%rax
shl    $0x3,%rax
mov    %rax,-0xa0(%rbp)
mov    $0x6,%edi
lea    -0xa0(%rbp),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1060 <b_system_misc@plt>
jmp    115e <main+0x1e>
movsbl -0x90(%rbp),%eax
cmp    $0x63,%eax
jne    12df <main+0x19f>
movl   $0x0,-0x98(%rbp)
mov    $0x9,%edi
xor    %esi,%esi
lea    -0x98(%rbp),%rdx
mov    $0x0,%al
call   1060 <b_system_misc@plt>
lea    0xdee(%rip),%rdi
call   1050 <b_output@plt>
jmp    115e <main+0x1e>
jmp    12e4 <main+0x1a4>
jmp    12e9 <main+0x1a9>
jmp    12ee <main+0x1ae>
jmp    115e <main+0x1e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
lea    0xeec(%rip),%rdi
call   1050 <b_output@plt>
lea    0x16(%rsp),%rbx
lea    0x15(%rsp),%rbp
lea    0xee6(%rip),%r12
lea    0x10(%rsp),%r14
lea    0xe86(%rip),%r13
lea    0x8(%rsp),%r15
jmp    119c <main+0x5c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xec4(%rip),%rdi
call   1050 <b_output@plt>
mov    %r12,%rdi
call   1050 <b_output@plt>
mov    %r14,%rdi
mov    $0x80,%esi
call   1040 <b_input@plt>
mov    0x10(%rsp),%al
add    $0x9d,%al
cmp    $0x10,%al
ja     119c <main+0x5c>
movzbl %al,%eax
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
movl   $0x0,0x4(%rsp)
mov    $0x9,%edi
xor    %esi,%esi
lea    0x4(%rsp),%rdx
xor    %eax,%eax
call   1060 <b_system_misc@plt>
lea    0xf1d(%rip),%rdi
call   1050 <b_output@plt>
jmp    119c <main+0x5c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movq   $0x0,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
movl   $0x6,0x4(%rsp)
mov    0x8(%rsp),%rcx
test   %eax,%eax
jle    12e6 <main+0x1a6>
lea    0x6(%rax),%r8d
cmp    $0x7,%r8d
jne    1268 <main+0x128>
mov    $0x6,%esi
test   $0x1,%r8b
jne    12c9 <main+0x189>
jmp    12e1 <main+0x1a1>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x78,0x11(%rsp)
je     1305 <main+0x1c5>
mov    %rbp,%rdi
call   1050 <b_output@plt>
jmp    119c <main+0x5c>
mov    %rbp,%r10
mov    %rbx,%r9
lea    -0x6(%r8),%rsi
and    $0xfffffffffffffffe,%rsi
lea    (%rax,%rax,1),%edi
lea    (%rdi,%rdi,4),%ebp
xor    %edi,%edi
xchg   %ax,%ax
movsbq 0x16(%rsp,%rdi,1),%rbx
add    $0xffffffffffffffe2,%rbx
movslq %ebp,%rbp
imul   %rbp,%rbx
add    %rcx,%rbx
movsbq 0x17(%rsp,%rdi,1),%rdx
add    $0xffffffffffffffe2,%rdx
lea    -0xa(%rbp),%ecx
movslq %ecx,%rcx
imul   %rdx,%rcx
add    %rbx,%rcx
add    $0x2,%rdi
add    $0xffffffec,%ebp
cmp    %rdi,%rsi
jne    1280 <main+0x140>
lea    0x6(%rdi),%rsi
sub    %edi,%eax
mov    %r9,%rbx
mov    %r10,%rbp
test   $0x1,%r8b
je     12e1 <main+0x1a1>
movsbq 0x10(%rsp,%rsi,1),%rdx
add    $0xffffffffffffffe2,%rdx
cltq
imul   %rdx,%rax
lea    (%rax,%rax,4),%rax
lea    (%rcx,%rax,2),%rcx
mov    %r8d,0x4(%rsp)
shl    $0x3,%rcx
mov    %rcx,0x8(%rsp)
mov    $0x6,%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <b_system_misc@plt>
jmp    119c <main+0x5c>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Console ready.\0A\00"
@.str.1 = [7 x i8] c"term> \00"
@.str.2 = [172 x i8] c"Help for Console:\0ACommands:\0Ahelp\09Display help\0Aecho\09echos text\0Asleep\09delays for <x> seconds\0Aexit\09return to the boring BMOS shell\0Acores\09get number of cores\0A\09well, that's it.\00"
@.str.3 = [11 x i8] c"cores: TBI\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [129 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 @b_output(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %0, %15, %29, %64, %73, %79
%8 = call i32 @b_output(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [129 x i8], [129 x i8]* %2, i64 0, i64 0
%10 = call i32 @b_input(i8* %9, i32 128)
%11 = getelementptr inbounds [129 x i8], [129 x i8]* %2, i64 0, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 104
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = call i32 @b_output(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str.2, i64 0, i64 0))
br label %7
17: ; preds = %7
%18 = getelementptr inbounds [129 x i8], [129 x i8]* %2, i64 0, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 101
br i1 %21, label %22, label %33
22: ; preds = %17
%23 = getelementptr inbounds [129 x i8], [129 x i8]* %2, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 120
br i1 %27, label %28, label %29
28: ; preds = %22
ret i32 0
29: ; preds = %22
%30 = getelementptr inbounds [129 x i8], [129 x i8]* %2, i64 0, i64 0
%31 = getelementptr inbounds i8, i8* %30, i64 5
%32 = call i32 @b_output(i8* %31)
br label %7
33: ; preds = %17
%34 = getelementptr inbounds [129 x i8], [129 x i8]* %2, i64 0, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 115
br i1 %37, label %38, label %68
38: ; preds = %33
store i64 0, i64* %5
%39 = getelementptr inbounds [129 x i8], [129 x i8]* %2, i64 0, i64 0
%40 = getelementptr inbounds i8, i8* %39, i64 6
%41 = call i32 @strlen(i8* %40)
store i32 %41, i32* %3
store i32 6, i32* %4
br label %42
42: ; preds = %61, %38
%43 = load i32, i32* %3
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %64
45: ; preds = %42
%46 = getelementptr inbounds [129 x i8], [129 x i8]* %2, i64 0, i64 0
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = sub nsw i32 %51, 30
%53 = load i32, i32* %3
%54 = mul nsw i32 %53, 10
%55 = mul nsw i32 %52, %54
%56 = sext i32 %55 to i64
%57 = load i64, i64* %5
%58 = add i64 %57, %56
store i64 %58, i64* %5
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
br label %61
61: ; preds = %45
%62 = load i32, i32* %3
%63 = add nsw i32 %62, -1
store i32 %63, i32* %3
br label %42
64: ; preds = %42
%65 = load i64, i64* %5
%66 = mul i64 %65, 8
store i64 %66, i64* %5
%67 = call i32 (i32, ...) @b_system_misc(i32 6, i64* %5, i32 0)
br label %7
68: ; preds = %33
%69 = getelementptr inbounds [129 x i8], [129 x i8]* %2, i64 0, i64 0
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp eq i32 %71, 99
br i1 %72, label %73, label %76
73: ; preds = %68
store i32 0, i32* %4
%74 = call i32 (i32, ...) @b_system_misc(i32 9, i32 0, i32* %4)
%75 = call i32 @b_output(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %7
76: ; preds = %68
br label %77
77: ; preds = %76
br label %78
78: ; preds = %77
br label %79
79: ; preds = %78
br label %7
}

LLVM IR (-O2):
@.str = [16 x i8] c"Console ready.\0A\00"
@.str.1 = [7 x i8] c"term> \00"
@.str.2 = [172 x i8] c"Help for Console:\0ACommands:\0Ahelp\09Display help\0Aecho\09echos text\0Asleep\09delays for <x> seconds\0Aexit\09return to the boring BMOS shell\0Acores\09get number of cores\0A\09well, that's it.\00"
@.str.3 = [11 x i8] c"cores: TBI\00"
define i32 @main() {
%1 = alloca [129 x i8]
%2 = alloca i32
%3 = alloca i64
%4 = getelementptr inbounds [129 x i8], [129 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = tail call i32 @b_output(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [129 x i8], [129 x i8]* %1, i64 0, i64 1
%9 = getelementptr inbounds [129 x i8], [129 x i8]* %1, i64 0, i64 6
%10 = getelementptr inbounds [129 x i8], [129 x i8]* %1, i64 0, i64 5
br label %11
11: ; preds = %17, %0
%12 = call i32 @b_output(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @b_input(i8* %4, i32 128)
%14 = load i8, i8* %4
switch i8 %14, label %17 [
i8 104, label %15
i8 101, label %18
i8 115, label %24
i8 99, label %85
]
15: ; preds = %11
%16 = call i32 @b_output(i8* getelementptr inbounds ([172 x i8], [172 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %22, %81, %85, %11
br label %11
18: ; preds = %11
%19 = load i8, i8* %8
%20 = icmp eq i8 %19, 120
br i1 %20, label %21, label %22
21: ; preds = %18
ret i32 0
22: ; preds = %18
%23 = call i32 @b_output(i8* %10)
br label %17
24: ; preds = %11
store i64 0, i64* %3
%25 = call i32 @strlen(i8* %9)
store i32 6, i32* %2
%26 = load i64, i64* %3
%27 = icmp sgt i32 %25, 0
br i1 %27, label %28, label %81
28: ; preds = %24
%29 = add nuw i32 %25, 6
%30 = zext i32 %29 to i64
%31 = and i64 %30, 1
%32 = icmp eq i32 %29, 7
br i1 %32, label %63, label %33
33: ; preds = %28
%34 = add nsw i64 %30, -6
%35 = and i64 %34, -2
br label %36
36: ; preds = %36, %33
%37 = phi i64 [ 6, %33 ], [ %59, %36 ]
%38 = phi i32 [ %25, %33 ], [ %60, %36 ]
%39 = phi i64 [ %26, %33 ], [ %58, %36 ]
%40 = phi i64 [ 0, %33 ], [ %61, %36 ]
%41 = getelementptr inbounds [129 x i8], [129 x i8]* %1, i64 0, i64 %37
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = add nsw i32 %43, -30
%45 = mul nsw i32 %38, 10
%46 = mul nsw i32 %45, %44
%47 = sext i32 %46 to i64
%48 = add i64 %39, %47
%49 = or i64 %37, 1
%50 = getelementptr inbounds [129 x i8], [129 x i8]* %1, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = add nsw i32 %52, -30
%54 = mul i32 %38, 10
%55 = add i32 %54, -10
%56 = mul nsw i32 %55, %53
%57 = sext i32 %56 to i64
%58 = add i64 %48, %57
%59 = add nuw nsw i64 %37, 2
%60 = add nsw i32 %38, -2
%61 = add i64 %40, 2
%62 = icmp eq i64 %61, %35
br i1 %62, label %63, label %36
63: ; preds = %36, %28
%64 = phi i64 [ undef, %28 ], [ %58, %36 ]
%65 = phi i64 [ 6, %28 ], [ %59, %36 ]
%66 = phi i32 [ %25, %28 ], [ %60, %36 ]
%67 = phi i64 [ %26, %28 ], [ %58, %36 ]
%68 = icmp eq i64 %31, 0
br i1 %68, label %78, label %69
69: ; preds = %63
%70 = getelementptr inbounds [129 x i8], [129 x i8]* %1, i64 0, i64 %65
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = add nsw i32 %72, -30
%74 = mul nsw i32 %66, 10
%75 = mul nsw i32 %74, %73
%76 = sext i32 %75 to i64
%77 = add i64 %67, %76
br label %78
78: ; preds = %63, %69
%79 = phi i64 [ %64, %63 ], [ %77, %69 ]
%80 = add i32 %25, 6
store i32 %80, i32* %2
br label %81
81: ; preds = %78, %24
%82 = phi i64 [ %79, %78 ], [ %26, %24 ]
%83 = shl i64 %82, 3
store i64 %83, i64* %3
%84 = call i32 (i32, ...) @b_system_misc(i32 6, i64* %3, i32 0)
br label %17
85: ; preds = %11
store i32 0, i32* %2
%86 = call i32 (i32, ...) @b_system_misc(i32 9, i32 0, i32* %2)
%87 = call i32 @b_output(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %17
}