void monitor(struct Trapframe *tf) {
  char *buf;
  cprintf("Welcome to the DamnOS Kernel Monitor!\n");
  cprintf("Type 'help' for a list of commands.\n");
  while (1) {
    buf = readline("D> ");
    if (buf != ((void *)0))
      if (runcmd(buf, tf) < 0)
        break;
  }
}


x86 assembly (clang, -O0):
<monitor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1050 <cprintf@plt>
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1050 <cprintf@plt>
lea    0xeed(%rip),%rdi
mov    $0x0,%al
call   1040 <readline@plt>
cltq
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1199 <monitor+0x69>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1030 <runcmd@plt>
cmp    $0x0,%eax
jge    1194 <monitor+0x64>
jmp    119e <monitor+0x6e>
jmp    1199 <monitor+0x69>
jmp    1158 <monitor+0x28>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<monitor>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1050 <cprintf@plt>
lea    0xedb(%rip),%rdi
xor    %eax,%eax
call   1050 <cprintf@plt>
lea    0xef2(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <readline@plt>
test   %eax,%eax
je     1160 <monitor+0x30>
movslq %eax,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <runcmd@plt>
test   %eax,%eax
jns    1160 <monitor+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.Trapframe = type opaque
@.str = [39 x i8] c"Welcome to the DamnOS Kernel Monitor!\0A\00"
@.str.1 = [37 x i8] c"Type 'help' for a list of commands.\0A\00"
@.str.2 = [4 x i8] c"D> \00"
define void @monitor(%struct.Trapframe* %0) {
%2 = alloca %struct.Trapframe*
%3 = alloca i8*
store %struct.Trapframe* %0, %struct.Trapframe** %2
%4 = call i32 (i8*, ...) bitcast (i32 (...)* @cprintf to i32 (i8*, ...)*)(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) bitcast (i32 (...)* @cprintf to i32 (i8*, ...)*)(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %1, %19
%7 = call i32 (i8*, ...) bitcast (i32 (...)* @readline to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %19
12: ; preds = %6
%13 = load i8*, i8** %3
%14 = load %struct.Trapframe*, %struct.Trapframe** %2
%15 = call i32 (i8*, %struct.Trapframe*, ...) bitcast (i32 (...)* @runcmd to i32 (i8*, %struct.Trapframe*, ...)*)(i8* %13, %struct.Trapframe* %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
br label %20
18: ; preds = %12
br label %19
19: ; preds = %18, %6
br label %6
20: ; preds = %17
ret void
}

LLVM IR (-O2):
%struct.Trapframe = type opaque
@.str = [39 x i8] c"Welcome to the DamnOS Kernel Monitor!\0A\00"
@.str.1 = [37 x i8] c"Type 'help' for a list of commands.\0A\00"
@.str.2 = [4 x i8] c"D> \00"
define void @monitor(%struct.Trapframe* %0) {
%2 = tail call i32 (i8*, ...) bitcast (i32 (...)* @cprintf to i32 (i8*, ...)*)(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) bitcast (i32 (...)* @cprintf to i32 (i8*, ...)*)(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %4
4: ; preds = %12, %1
%5 = tail call i32 (i8*, ...) bitcast (i32 (...)* @readline to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = sext i32 %5 to i64
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 (i8*, %struct.Trapframe*, ...) bitcast (i32 (...)* @runcmd to i32 (i8*, %struct.Trapframe*, ...)*)(i8* %9, %struct.Trapframe* %0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %7, %4
br label %4
13: ; preds = %7
ret void
}