#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 */
char *bf_create_array(int);
char *bf_execute(char *, char *, char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ show_shell_help();
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int run_brainfuck_shell() {
  char *prog_array = bf_create_array(30000);
  char *ptr = prog_array;
  char buffer[80];
  while (buffer[0] != 'q') {
    memset(buffer, '\0', 80);
    printf(">>> ");
    fgets(buffer, 80, stdin);
    if (strcmp(buffer, "help\n") == 0) {
      show_shell_help();
    } else {
      ptr = bf_execute(buffer, prog_array, ptr);
      if (!ptr) {
        ptr = prog_array;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<run_brainfuck_shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    $0x7530,%edi
call   1060 <bf_create_array@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movsbl -0x60(%rbp),%eax
cmp    $0x71,%eax
je     1226 <run_brainfuck_shell+0xb6>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1070 <memset@plt>
lea    0xe4e(%rip),%rdi
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1080 <fgets@plt>
lea    -0x60(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    11f4 <run_brainfuck_shell+0x84>
mov    $0x0,%al
call   1030 <show_shell_help@plt>
jmp    1221 <run_brainfuck_shell+0xb1>
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <bf_execute@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    121c <run_brainfuck_shell+0xac>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1221 <run_brainfuck_shell+0xb1>
jmp    118e <run_brainfuck_shell+0x1e>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_brainfuck_shell>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    $0x7530,%edi
call   1060 <bf_create_array@plt>
mov    %rax,%r14
mov    %rsp,%r13
lea    0xe6b(%rip),%r15
mov    0x2e4c(%rip),%rbp
lea    0xe62(%rip),%r12
mov    %rax,%rbx
jmp    11ce <run_brainfuck_shell+0x5e>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <bf_execute@plt>
mov    %rax,%rbx
test   %rax,%rax
cmove  %r14,%rbx
cmpb   $0x71,(%rsp)
je     1212 <run_brainfuck_shell+0xa2>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1070 <memset@plt>
mov    %r15,%rdi
call   1050 <printf@plt>
mov    0x0(%rbp),%edx
mov    %r13,%rdi
mov    $0x50,%esi
call   1080 <fgets@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    11b0 <run_brainfuck_shell+0x40>
xor    %eax,%eax
call   1030 <show_shell_help@plt>
cmpb   $0x71,(%rsp)
jne    11ce <run_brainfuck_shell+0x5e>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c">>> \00"
@stdin = global i32 0
@.str.1 = [6 x i8] c"help\0A\00"
define i32 @run_brainfuck_shell() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca [80 x i8]
%4 = call i8* @bf_create_array(i32 30000)
store i8* %4, i8** %1
%5 = load i8*, i8** %1
store i8* %5, i8** %2
br label %6
6: ; preds = %33, %0
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 113
br i1 %10, label %11, label %34
11: ; preds = %6
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i8 signext 0, i32 80)
%14 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %15, i32 80, i32 %16)
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %11
%22 = call i32 (...) @show_shell_help()
br label %33
23: ; preds = %11
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%25 = load i8*, i8** %1
%26 = load i8*, i8** %2
%27 = call i8* @bf_execute(i8* %24, i8* %25, i8* %26)
store i8* %27, i8** %2
%28 = load i8*, i8** %2
%29 = icmp ne i8* %28, null
br i1 %29, label %32, label %30
30: ; preds = %23
%31 = load i8*, i8** %1
store i8* %31, i8** %2
br label %32
32: ; preds = %30, %23
br label %33
33: ; preds = %32, %21
br label %6
34: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c">>> \00"
@stdin = global i32 0
@.str.1 = [6 x i8] c"help\0A\00"
define i32 @run_brainfuck_shell() {
%1 = alloca [80 x i8]
%2 = tail call i8* @bf_create_array(i32 30000)
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
br label %4
4: ; preds = %0, %18
%5 = phi i8* [ %19, %18 ], [ %2, %0 ]
%6 = call i32 @memset(i8* %3, i8 signext 0, i32 80)
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %3, i32 80, i32 %8)
%10 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = call i32 (...) @show_shell_help()
br label %18
14: ; preds = %4
%15 = call i8* @bf_execute(i8* %3, i8* %2, i8* %5)
%16 = icmp eq i8* %15, null
%17 = select i1 %16, i8* %2, i8* %15
br label %18
18: ; preds = %14, %12
%19 = phi i8* [ %5, %12 ], [ %17, %14 ]
%20 = load i8, i8* %3
%21 = icmp eq i8 %20, 113
br i1 %21, label %22, label %4
22: ; preds = %18
ret i32 0
}