#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*/ execute_command(char *, char **);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char getchar();
scalar_t__ isdigit(char);
int /*<<< orphan*/ isspace(char);
void *malloc(int);
int /*<<< orphan*/ print_history(char **, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ run_history(char **, int, int);
int save_history(char **, char *, int);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ wait();
void interactive() {
  char last[80];
  char **args, **history;
  args = malloc(80 * sizeof(char *));
  history = malloc(10 * sizeof(char *));
  int i;
  for (i = 0; i < 80; i++) {
    args[i] = malloc(80 * sizeof(char));
    args[i][0] = '\0';
  }
  for (i = 0; i < 10; i++) {
    history[i] = malloc(10 * sizeof(char));
    history[i][0] = '\0';
  }
  int run = 1, counter = 0, commands_run = 0;
  while (run) {
    printf("osh> ");
    fflush(stdout);
    size_t argc = 0;
    char c;
    int line_length = 0;
    do {
      c = getchar();
      for (counter = 0; !isspace(c); counter++, c = getchar()) {
        args[argc][counter] = c;
        last[line_length++] = c;
      }
      args[argc++][counter] = '\0';
      last[line_length] = '\0';
    } while (c == ' ');
    if (strcmp(args[0], "exit") == 0 || strcmp(args[0], "quit") == 0) {
      run = 0;
    } else if (strcmp(args[0], "history") == 0) {
      print_history(history, commands_run);
    } else if (strcmp(args[0], "!!") == 0) {
      run_history(history, commands_run, 0);
    } else if (args[0][0] == '!' && isdigit(args[0][1])) {
      int history_num = 0;
      if (sscanf(args[0], "!%d", &history_num) == 1) {
        if (history_num > 0 && history_num <= 10 && history_num <= commands_run)
          run_history(history, commands_run, history_num - 1);
        else
          printf("Error: Invalid history request\n");
      } else
        printf("!shitwentwrong\n");
    } else {
      free(args[argc]);
      args[argc] = NULL;
      execute_command(args[0], args);
      if (!(argc > 0 && args[argc - 1][0] == '&'))
        wait();
      args[argc] = malloc(80 * sizeof(char));
      args[argc][0] = '\0';
      commands_run = save_history(history, last, commands_run);
    }
  }
  return;
}


x86 assembly (clang, -O0):
<interactive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    $0x280,%edi
call   1090 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    $0x50,%edi
call   1090 <malloc@plt>
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0x50,-0x64(%rbp)
jge    124e <interactive+0x6e>
mov    $0x50,%edi
call   1090 <malloc@plt>
mov    %rax,%rdx
mov    -0x58(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x58(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movb   $0x0,(%rax)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    120e <interactive+0x2e>
movl   $0x0,-0x64(%rbp)
cmpl   $0xa,-0x64(%rbp)
jge    1295 <interactive+0xb5>
mov    $0xa,%edi
call   1090 <malloc@plt>
mov    %rax,%rdx
mov    -0x60(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x60(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movb   $0x0,(%rax)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1255 <interactive+0x75>
movl   $0x1,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
movl   $0x0,-0x70(%rbp)
cmpl   $0x0,-0x68(%rbp)
je     1594 <interactive+0x3b4>
lea    0xd45(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
movq   $0x0,-0x78(%rbp)
movl   $0x0,-0x80(%rbp)
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %al,-0x79(%rbp)
movl   $0x0,-0x6c(%rbp)
movsbl -0x79(%rbp),%edi
call   1060 <isspace@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    130c <interactive+0x12c>
jmp    134e <interactive+0x16e>
mov    -0x79(%rbp),%dl
mov    -0x58(%rbp),%rax
mov    -0x78(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x6c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x79(%rbp),%cl
mov    -0x80(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x80(%rbp)
cltq
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %al,-0x79(%rbp)
jmp    12ee <interactive+0x10e>
mov    -0x58(%rbp),%rax
mov    -0x78(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x78(%rbp)
mov    (%rax,%rcx,8),%rax
movslq -0x6c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movslq -0x80(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
movsbl -0x79(%rbp),%eax
cmp    $0x20,%eax
je     12dd <interactive+0xfd>
mov    -0x58(%rbp),%rax
mov    (%rax),%rdi
lea    0xc75(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     13bd <interactive+0x1dd>
mov    -0x58(%rbp),%rax
mov    (%rax),%rdi
lea    0xc5d(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    13c9 <interactive+0x1e9>
movl   $0x0,-0x68(%rbp)
jmp    158f <interactive+0x3af>
mov    -0x58(%rbp),%rax
mov    (%rax),%rdi
lea    0xc39(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    13f7 <interactive+0x217>
mov    -0x60(%rbp),%rdi
mov    -0x70(%rbp),%esi
call   10d0 <print_history@plt>
jmp    158a <interactive+0x3aa>
mov    -0x58(%rbp),%rax
mov    (%rax),%rdi
lea    0xc13(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1427 <interactive+0x247>
mov    -0x60(%rbp),%rdi
mov    -0x70(%rbp),%esi
xor    %edx,%edx
call   1100 <run_history@plt>
jmp    1585 <interactive+0x3a5>
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x21,%eax
jne    14e6 <interactive+0x306>
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     14e6 <interactive+0x306>
movl   $0x0,-0x84(%rbp)
mov    -0x58(%rbp),%rax
mov    (%rax),%rdi
lea    0xbaf(%rip),%rsi
lea    -0x84(%rbp),%rdx
call   10b0 <sscanf@plt>
cmp    $0x1,%eax
jne    14d5 <interactive+0x2f5>
cmpl   $0x0,-0x84(%rbp)
jle    14c4 <interactive+0x2e4>
cmpl   $0xa,-0x84(%rbp)
jg     14c4 <interactive+0x2e4>
mov    -0x84(%rbp),%eax
cmp    -0x70(%rbp),%eax
jg     14c4 <interactive+0x2e4>
mov    -0x60(%rbp),%rdi
mov    -0x70(%rbp),%esi
mov    -0x84(%rbp),%edx
sub    $0x1,%edx
call   1100 <run_history@plt>
jmp    14d0 <interactive+0x2f0>
lea    0xb54(%rip),%rdi
call   1050 <printf@plt>
jmp    14e1 <interactive+0x301>
lea    0xb63(%rip),%rdi
call   1050 <printf@plt>
jmp    1580 <interactive+0x3a0>
mov    -0x58(%rbp),%rax
mov    -0x78(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rax
mov    -0x78(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x58(%rbp),%rax
mov    (%rax),%rdi
mov    -0x58(%rbp),%rsi
call   10e0 <execute_command@plt>
cmpq   $0x0,-0x78(%rbp)
jbe    153e <interactive+0x35e>
mov    -0x58(%rbp),%rax
mov    -0x78(%rbp),%rcx
sub    $0x1,%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
je     1545 <interactive+0x365>
mov    $0x0,%al
call   10f0 <wait@plt>
mov    $0x50,%edi
call   1090 <malloc@plt>
mov    %rax,%rdx
mov    -0x58(%rbp),%rax
mov    -0x78(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x58(%rbp),%rax
mov    -0x78(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movb   $0x0,(%rax)
mov    -0x60(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x70(%rbp),%edx
call   10c0 <save_history@plt>
mov    %eax,-0x70(%rbp)
jmp    1585 <interactive+0x3a5>
jmp    158a <interactive+0x3aa>
jmp    158f <interactive+0x3af>
jmp    12aa <interactive+0xca>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interactive>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    $0x280,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    $0x50,%edi
call   10a0 <malloc@plt>
mov    %rax,0x10(%rsp)
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    $0x50,%edi
call   10a0 <malloc@plt>
mov    %rax,(%rbx,%rbp,8)
movb   $0x0,(%rax)
add    $0x1,%rbp
cmp    $0x50,%rbp
jne    1220 <interactive+0x30>
mov    $0xa,%edi
call   10a0 <malloc@plt>
mov    0x10(%rsp),%rbp
mov    %rax,0x0(%rbp)
movb   $0x0,(%rax)
mov    $0xa,%edi
call   10a0 <malloc@plt>
mov    %rax,0x8(%rbp)
movb   $0x0,(%rax)
mov    $0xa,%edi
call   10a0 <malloc@plt>
mov    %rax,0x10(%rbp)
movb   $0x0,(%rax)
mov    $0xa,%edi
call   10a0 <malloc@plt>
mov    %rax,0x18(%rbp)
movb   $0x0,(%rax)
mov    $0xa,%edi
call   10a0 <malloc@plt>
mov    %rax,0x20(%rbp)
movb   $0x0,(%rax)
mov    $0xa,%edi
call   10a0 <malloc@plt>
mov    %rax,0x28(%rbp)
movb   $0x0,(%rax)
mov    $0xa,%edi
call   10a0 <malloc@plt>
mov    %rax,0x30(%rbp)
movb   $0x0,(%rax)
mov    $0xa,%edi
call   10a0 <malloc@plt>
mov    %rax,0x38(%rbp)
movb   $0x0,(%rax)
mov    $0xa,%edi
call   10a0 <malloc@plt>
mov    %rax,0x40(%rbp)
movb   $0x0,(%rax)
mov    $0xa,%edi
call   10a0 <malloc@plt>
mov    %rax,0x48(%rbp)
movb   $0x0,(%rax)
movl   $0x0,0xc(%rsp)
jmp    130e <interactive+0x11e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
call   10e0 <print_history@plt>
lea    0xceb(%rip),%rdi
call   1060 <printf@plt>
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
xor    %r12d,%r12d
xor    %ebp,%ebp
jmp    1350 <interactive+0x160>
nop
xor    %r14d,%r14d
lea    0x1(%r15),%r12
mov    (%rbx,%r15,8),%rax
mov    %r14d,%ecx
movb   $0x0,(%rax,%rcx,1)
movslq %ebp,%rax
movb   $0x0,0x20(%rsp,%rax,1)
cmp    $0x20,%r13b
jne    13b0 <interactive+0x1c0>
mov    %r12,%r15
xor    %eax,%eax
call   1090 <getchar@plt>
mov    %eax,%r13d
movsbl %al,%edi
call   1070 <isspace@plt>
test   %eax,%eax
jne    1330 <interactive+0x140>
mov    %ebp,%r12d
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rbp
add    $0x20,%rbp
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    (%rbx,%r15,8),%rax
mov    %r13b,(%rax,%r14,1)
mov    %r13b,0x0(%rbp,%r14,1)
add    $0x1,%r14
xor    %eax,%eax
call   1090 <getchar@plt>
mov    %eax,%r13d
movsbl %al,%edi
call   1070 <isspace@plt>
test   %eax,%eax
je     1380 <interactive+0x190>
mov    %r12d,%ebp
add    %r14d,%ebp
jmp    1333 <interactive+0x143>
nop
mov    (%rbx),%rdi
lea    0xc4c(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1505 <interactive+0x315>
mov    (%rbx),%rdi
lea    0xc39(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1505 <interactive+0x315>
mov    (%rbx),%rdi
lea    0xc26(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1300 <interactive+0x110>
mov    (%rbx),%rdi
lea    0xc16(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1470 <interactive+0x280>
mov    (%rbx),%rax
cmpb   $0x21,(%rax)
jne    14a7 <interactive+0x2b7>
movsbl 0x1(%rax),%edi
call   1040 <isdigit@plt>
test   %rax,%rax
je     14a7 <interactive+0x2b7>
movl   $0x0,0x1c(%rsp)
mov    (%rbx),%rdi
lea    0xbdf(%rip),%rsi
lea    0x1c(%rsp),%rdx
call   10c0 <sscanf@plt>
cmp    $0x1,%eax
jne    1485 <interactive+0x295>
mov    0x1c(%rsp),%eax
lea    -0x1(%rax),%edx
cmp    $0x9,%edx
ja     1496 <interactive+0x2a6>
cmp    0xc(%rsp),%eax
jg     1496 <interactive+0x2a6>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
call   1110 <run_history@plt>
jmp    130e <interactive+0x11e>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
xor    %edx,%edx
call   1110 <run_history@plt>
jmp    130e <interactive+0x11e>
lea    0xb93(%rip),%rdi
call   1050 <puts@plt>
jmp    130e <interactive+0x11e>
lea    0xb91(%rip),%rdi
call   1050 <puts@plt>
jmp    130e <interactive+0x11e>
mov    (%rbx,%r12,8),%rdi
call   1030 <free@plt>
movq   $0x0,(%rbx,%r12,8)
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   10f0 <execute_command@plt>
test   %r12,%r12
je     14d1 <interactive+0x2e1>
mov    (%rbx,%r15,8),%rax
cmpb   $0x26,(%rax)
je     14d8 <interactive+0x2e8>
xor    %eax,%eax
call   1100 <wait@plt>
mov    $0x50,%edi
call   10a0 <malloc@plt>
mov    %rax,(%rbx,%r12,8)
movb   $0x0,(%rax)
mov    0x10(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    0xc(%rsp),%edx
call   10d0 <save_history@plt>
mov    %eax,0xc(%rsp)
jmp    130e <interactive+0x11e>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"osh> \00"
@stdout = global i32 0
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [5 x i8] c"quit\00"
@.str.3 = [8 x i8] c"history\00"
@.str.4 = [3 x i8] c"!!\00"
@.str.5 = [4 x i8] c"!%d\00"
@.str.6 = [32 x i8] c"Error: Invalid history request\0A\00"
@.str.7 = [16 x i8] c"!shitwentwrong\0A\00"
define void @interactive() {
%1 = alloca [80 x i8]
%2 = alloca i8**
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
%12 = call i8* @malloc(i32 640)
%13 = bitcast i8* %12 to i8**
store i8** %13, i8*** %2
%14 = call i8* @malloc(i32 80)
%15 = bitcast i8* %14 to i8**
store i8** %15, i8*** %3
store i32 0, i32* %4
br label %16
16: ; preds = %31, %0
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 80
br i1 %18, label %19, label %34
19: ; preds = %16
%20 = call i8* @malloc(i32 80)
%21 = load i8**, i8*** %2
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
store i8* %20, i8** %24
%25 = load i8**, i8*** %2
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = getelementptr inbounds i8, i8* %29, i64 0
store i8 0, i8* %30
br label %31
31: ; preds = %19
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %16
34: ; preds = %16
store i32 0, i32* %4
br label %35
35: ; preds = %50, %34
%36 = load i32, i32* %4
%37 = icmp slt i32 %36, 10
br i1 %37, label %38, label %53
38: ; preds = %35
%39 = call i8* @malloc(i32 10)
%40 = load i8**, i8*** %3
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
store i8* %39, i8** %43
%44 = load i8**, i8*** %3
%45 = load i32, i32* %4
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = getelementptr inbounds i8, i8* %48, i64 0
store i8 0, i8* %49
br label %50
50: ; preds = %38
%51 = load i32, i32* %4
%52 = add nsw i32 %51, 1
store i32 %52, i32* %4
br label %35
53: ; preds = %35
store i32 1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %54
54: ; preds = %224, %53
%55 = load i32, i32* %5
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %225
57: ; preds = %54
%58 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%59 = load i32, i32* @stdout
%60 = call i32 @fflush(i32 %59)
store i64 0, i64* %8
store i32 0, i32* %10
br label %61
61: ; preds = %98, %57
%62 = call signext i8 (...) @getchar()
store i8 %62, i8* %9
store i32 0, i32* %6
br label %63
63: ; preds = %82, %61
%64 = load i8, i8* %9
%65 = call i32 @isspace(i8 signext %64)
%66 = icmp ne i32 %65, 0
%67 = xor i1 %66, true
br i1 %67, label %68, label %86
68: ; preds = %63
%69 = load i8, i8* %9
%70 = load i8**, i8*** %2
%71 = load i64, i64* %8
%72 = getelementptr inbounds i8*, i8** %70, i64 %71
%73 = load i8*, i8** %72
%74 = load i32, i32* %6
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %73, i64 %75
store i8 %69, i8* %76
%77 = load i8, i8* %9
%78 = load i32, i32* %10
%79 = add nsw i32 %78, 1
store i32 %79, i32* %10
%80 = sext i32 %78 to i64
%81 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %80
store i8 %77, i8* %81
br label %82
82: ; preds = %68
%83 = load i32, i32* %6
%84 = add nsw i32 %83, 1
store i32 %84, i32* %6
%85 = call signext i8 (...) @getchar()
store i8 %85, i8* %9
br label %63
86: ; preds = %63
%87 = load i8**, i8*** %2
%88 = load i64, i64* %8
%89 = add i64 %88, 1
store i64 %89, i64* %8
%90 = getelementptr inbounds i8*, i8** %87, i64 %88
%91 = load i8*, i8** %90
%92 = load i32, i32* %6
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8, i8* %91, i64 %93
store i8 0, i8* %94
%95 = load i32, i32* %10
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %96
store i8 0, i8* %97
br label %98
98: ; preds = %86
%99 = load i8, i8* %9
%100 = sext i8 %99 to i32
%101 = icmp eq i32 %100, 32
br i1 %101, label %61, label %102
102: ; preds = %98
%103 = load i8**, i8*** %2
%104 = getelementptr inbounds i8*, i8** %103, i64 0
%105 = load i8*, i8** %104
%106 = call i64 @strcmp(i8* %105, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%107 = icmp eq i64 %106, 0
br i1 %107, label %114, label %108
108: ; preds = %102
%109 = load i8**, i8*** %2
%110 = getelementptr inbounds i8*, i8** %109, i64 0
%111 = load i8*, i8** %110
%112 = call i64 @strcmp(i8* %111, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%113 = icmp eq i64 %112, 0
br i1 %113, label %114, label %115
114: ; preds = %108, %102
store i32 0, i32* %5
br label %224
115: ; preds = %108
%116 = load i8**, i8*** %2
%117 = getelementptr inbounds i8*, i8** %116, i64 0
%118 = load i8*, i8** %117
%119 = call i64 @strcmp(i8* %118, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%120 = icmp eq i64 %119, 0
br i1 %120, label %121, label %125
121: ; preds = %115
%122 = load i8**, i8*** %3
%123 = load i32, i32* %7
%124 = call i32 @print_history(i8** %122, i32 %123)
br label %223
125: ; preds = %115
%126 = load i8**, i8*** %2
%127 = getelementptr inbounds i8*, i8** %126, i64 0
%128 = load i8*, i8** %127
%129 = call i64 @strcmp(i8* %128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%130 = icmp eq i64 %129, 0
br i1 %130, label %131, label %135
131: ; preds = %125
%132 = load i8**, i8*** %3
%133 = load i32, i32* %7
%134 = call i32 @run_history(i8** %132, i32 %133, i32 0)
br label %222
135: ; preds = %125
%136 = load i8**, i8*** %2
%137 = getelementptr inbounds i8*, i8** %136, i64 0
%138 = load i8*, i8** %137
%139 = getelementptr inbounds i8, i8* %138, i64 0
%140 = load i8, i8* %139
%141 = sext i8 %140 to i32
%142 = icmp eq i32 %141, 33
br i1 %142, label %143, label %179
143: ; preds = %135
%144 = load i8**, i8*** %2
%145 = getelementptr inbounds i8*, i8** %144, i64 0
%146 = load i8*, i8** %145
%147 = getelementptr inbounds i8, i8* %146, i64 1
%148 = load i8, i8* %147
%149 = call i64 @isdigit(i8 signext %148)
%150 = icmp ne i64 %149, 0
br i1 %150, label %151, label %179
151: ; preds = %143
store i32 0, i32* %11
%152 = load i8**, i8*** %2
%153 = getelementptr inbounds i8*, i8** %152, i64 0
%154 = load i8*, i8** %153
%155 = call i32 @sscanf(i8* %154, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* %11)
%156 = icmp eq i32 %155, 1
br i1 %156, label %157, label %176
157: ; preds = %151
%158 = load i32, i32* %11
%159 = icmp sgt i32 %158, 0
br i1 %159, label %160, label %173
160: ; preds = %157
%161 = load i32, i32* %11
%162 = icmp sle i32 %161, 10
br i1 %162, label %163, label %173
163: ; preds = %160
%164 = load i32, i32* %11
%165 = load i32, i32* %7
%166 = icmp sle i32 %164, %165
br i1 %166, label %167, label %173
167: ; preds = %163
%168 = load i8**, i8*** %3
%169 = load i32, i32* %7
%170 = load i32, i32* %11
%171 = sub nsw i32 %170, 1
%172 = call i32 @run_history(i8** %168, i32 %169, i32 %171)
br label %175
173: ; preds = %163, %160, %157
%174 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
br label %175
175: ; preds = %173, %167
br label %178
176: ; preds = %151
%177 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %178
178: ; preds = %176, %175
br label %221
179: ; preds = %143, %135
%180 = load i8**, i8*** %2
%181 = load i64, i64* %8
%182 = getelementptr inbounds i8*, i8** %180, i64 %181
%183 = load i8*, i8** %182
%184 = call i32 @free(i8* %183)
%185 = load i8**, i8*** %2
%186 = load i64, i64* %8
%187 = getelementptr inbounds i8*, i8** %185, i64 %186
store i8* null, i8** %187
%188 = load i8**, i8*** %2
%189 = getelementptr inbounds i8*, i8** %188, i64 0
%190 = load i8*, i8** %189
%191 = load i8**, i8*** %2
%192 = call i32 @execute_command(i8* %190, i8** %191)
%193 = load i64, i64* %8
%194 = icmp ugt i64 %193, 0
br i1 %194, label %195, label %205
195: ; preds = %179
%196 = load i8**, i8*** %2
%197 = load i64, i64* %8
%198 = sub i64 %197, 1
%199 = getelementptr inbounds i8*, i8** %196, i64 %198
%200 = load i8*, i8** %199
%201 = getelementptr inbounds i8, i8* %200, i64 0
%202 = load i8, i8* %201
%203 = sext i8 %202 to i32
%204 = icmp eq i32 %203, 38
br i1 %204, label %207, label %205
205: ; preds = %195, %179
%206 = call i32 (...) @wait()
br label %207
207: ; preds = %205, %195
%208 = call i8* @malloc(i32 80)
%209 = load i8**, i8*** %2
%210 = load i64, i64* %8
%211 = getelementptr inbounds i8*, i8** %209, i64 %210
store i8* %208, i8** %211
%212 = load i8**, i8*** %2
%213 = load i64, i64* %8
%214 = getelementptr inbounds i8*, i8** %212, i64 %213
%215 = load i8*, i8** %214
%216 = getelementptr inbounds i8, i8* %215, i64 0
store i8 0, i8* %216
%217 = load i8**, i8*** %3
%218 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%219 = load i32, i32* %7
%220 = call i32 @save_history(i8** %217, i8* %218, i32 %219)
store i32 %220, i32* %7
br label %221
221: ; preds = %207, %178
br label %222
222: ; preds = %221, %131
br label %223
223: ; preds = %222, %121
br label %224
224: ; preds = %223, %114
br label %54
225: ; preds = %54
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"osh> \00"
@stdout = global i32 0
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [5 x i8] c"quit\00"
@.str.3 = [8 x i8] c"history\00"
@.str.4 = [3 x i8] c"!!\00"
@.str.5 = [4 x i8] c"!%d\00"
@str = [15 x i8] c"!shitwentwrong\00"
@str.8 = [31 x i8] c"Error: Invalid history request\00"
define void @interactive() {
%1 = alloca [80 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%4 = tail call dereferenceable_or_null(640) i8* @malloc(i32 640)
%5 = bitcast i8* %4 to i8**
%6 = tail call dereferenceable_or_null(80) i8* @malloc(i32 80)
br label %7
7: ; preds = %0, %7
%8 = phi i64 [ 0, %0 ], [ %11, %7 ]
%9 = tail call dereferenceable_or_null(80) i8* @malloc(i32 80)
%10 = getelementptr inbounds i8*, i8** %5, i64 %8
store i8* %9, i8** %10
store i8 0, i8* %9
%11 = add nuw nsw i64 %8, 1
%12 = icmp eq i64 %11, 80
br i1 %12, label %13, label %7
13: ; preds = %7
%14 = bitcast i8* %6 to i8**
%15 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
store i8* %15, i8** %14
store i8 0, i8* %15
%16 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%17 = getelementptr inbounds i8*, i8** %14, i64 1
store i8* %16, i8** %17
store i8 0, i8* %16
%18 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%19 = getelementptr inbounds i8*, i8** %14, i64 2
store i8* %18, i8** %19
store i8 0, i8* %18
%20 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%21 = getelementptr inbounds i8*, i8** %14, i64 3
store i8* %20, i8** %21
store i8 0, i8* %20
%22 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%23 = getelementptr inbounds i8*, i8** %14, i64 4
store i8* %22, i8** %23
store i8 0, i8* %22
%24 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%25 = getelementptr inbounds i8*, i8** %14, i64 5
store i8* %24, i8** %25
store i8 0, i8* %24
%26 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%27 = getelementptr inbounds i8*, i8** %14, i64 6
store i8* %26, i8** %27
store i8 0, i8* %26
%28 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%29 = getelementptr inbounds i8*, i8** %14, i64 7
store i8* %28, i8** %29
store i8 0, i8* %28
%30 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%31 = getelementptr inbounds i8*, i8** %14, i64 8
store i8* %30, i8** %31
store i8 0, i8* %30
%32 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%33 = getelementptr inbounds i8*, i8** %14, i64 9
store i8* %32, i8** %33
store i8 0, i8* %32
%34 = bitcast i32* %2 to i8*
br label %35
35: ; preds = %137, %13
%36 = phi i32 [ %139, %137 ], [ 0, %13 ]
br label %37
37: ; preds = %90, %35
%38 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%39 = load i32, i32* @stdout
%40 = call i32 @fflush(i32 %39)
br label %41
41: ; preds = %64, %37
%42 = phi i64 [ 0, %37 ], [ %68, %64 ]
%43 = phi i32 [ 0, %37 ], [ %67, %64 ]
%44 = call signext i8 (...) @getchar()
%45 = call i32 @isspace(i8 signext %44)
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %64
47: ; preds = %41
%48 = getelementptr inbounds i8*, i8** %5, i64 %42
%49 = sext i32 %43 to i64
br label %50
50: ; preds = %47, %50
%51 = phi i64 [ 0, %47 ], [ %58, %50 ]
%52 = phi i64 [ %49, %47 ], [ %56, %50 ]
%53 = phi i8 [ %44, %47 ], [ %59, %50 ]
%54 = load i8*, i8** %48
%55 = getelementptr inbounds i8, i8* %54, i64 %51
store i8 %53, i8* %55
%56 = add i64 %52, 1
%57 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %52
store i8 %53, i8* %57
%58 = add nuw i64 %51, 1
%59 = call signext i8 (...) @getchar()
%60 = call i32 @isspace(i8 signext %59)
%61 = icmp eq i32 %60, 0
br i1 %61, label %50, label %62
62: ; preds = %50
%63 = trunc i64 %56 to i32
br label %64
64: ; preds = %62, %41
%65 = phi i64 [ 0, %41 ], [ %58, %62 ]
%66 = phi i8 [ %44, %41 ], [ %59, %62 ]
%67 = phi i32 [ %43, %41 ], [ %63, %62 ]
%68 = add i64 %42, 1
%69 = getelementptr inbounds i8*, i8** %5, i64 %42
%70 = load i8*, i8** %69
%71 = and i64 %65, 4294967295
%72 = getelementptr inbounds i8, i8* %70, i64 %71
store i8 0, i8* %72
%73 = sext i32 %67 to i64
%74 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %73
store i8 0, i8* %74
%75 = icmp eq i8 %66, 32
br i1 %75, label %41, label %76
76: ; preds = %64
%77 = load i8*, i8** %5
%78 = call i64 @strcmp(i8* %77, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%79 = icmp eq i64 %78, 0
br i1 %79, label %140, label %80
80: ; preds = %76
%81 = load i8*, i8** %5
%82 = call i64 @strcmp(i8* %81, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%83 = icmp eq i64 %82, 0
br i1 %83, label %140, label %84
84: ; preds = %80
%85 = load i8*, i8** %5
%86 = call i64 @strcmp(i8* %85, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%87 = icmp eq i64 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %84
%89 = call i32 @print_history(i8** %14, i32 %36)
br label %90
90: ; preds = %88, %122, %95
br label %37
91: ; preds = %84
%92 = load i8*, i8** %5
%93 = call i64 @strcmp(i8* %92, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%94 = icmp eq i64 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %91
%96 = call i32 @run_history(i8** %14, i32 %36, i32 0)
br label %90
97: ; preds = %91
%98 = load i8*, i8** %5
%99 = load i8, i8* %98
%100 = icmp eq i8 %99, 33
br i1 %100, label %101, label %123
101: ; preds = %97
%102 = getelementptr inbounds i8, i8* %98, i64 1
%103 = load i8, i8* %102
%104 = call i64 @isdigit(i8 signext %103)
%105 = icmp eq i64 %104, 0
br i1 %105, label %123, label %106
106: ; preds = %101
store i32 0, i32* %2
%107 = load i8*, i8** %5
%108 = call i32 @sscanf(i8* %107, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%109 = icmp eq i32 %108, 1
br i1 %109, label %110, label %120
110: ; preds = %106
%111 = load i32, i32* %2
%112 = add i32 %111, -1
%113 = icmp ugt i32 %112, 9
%114 = icmp sgt i32 %111, %36
%115 = select i1 %113, i1 true, i1 %114
br i1 %115, label %118, label %116
116: ; preds = %110
%117 = call i32 @run_history(i8** %14, i32 %36, i32 %112)
br label %122
118: ; preds = %110
%119 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.8, i64 0, i64 0))
br label %122
120: ; preds = %106
%121 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %122
122: ; preds = %116, %118, %120
br label %90
123: ; preds = %101, %97
%124 = getelementptr inbounds i8*, i8** %5, i64 %42
%125 = getelementptr inbounds i8*, i8** %5, i64 %68
%126 = load i8*, i8** %125
%127 = call i32 @free(i8* %126)
store i8* null, i8** %125
%128 = load i8*, i8** %5
%129 = call i32 @execute_command(i8* %128, i8** %5)
%130 = icmp eq i64 %68, 0
br i1 %130, label %135, label %131
131: ; preds = %123
%132 = load i8*, i8** %124
%133 = load i8, i8* %132
%134 = icmp eq i8 %133, 38
br i1 %134, label %137, label %135
135: ; preds = %131, %123
%136 = call i32 (...) @wait()
br label %137
137: ; preds = %135, %131
%138 = call dereferenceable_or_null(80) i8* @malloc(i32 80)
store i8* %138, i8** %125
store i8 0, i8* %138
%139 = call i32 @save_history(i8** %14, i8* %3, i32 %36)
br label %35
140: ; preds = %76, %80
ret void
}