void hw_console_output(const char *str) {
  while (*str) {
    if (*str == '\n') {
      while ((*((volatile unsigned char *)(0x90000000 + 5)) & 0x20) != 0x20)
        ;
      *((volatile unsigned char *)(0x90000000 + 0)) = '\r';
    }
    while ((*((volatile unsigned char *)(0x90000000 + 5)) & 0x20) != 0x20)
      ;
    *((volatile unsigned char *)(0x90000000 + 0)) = *str;
    str++;
  }
}


x86 assembly (clang, -O0):
<hw_console_output>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     118b <hw_console_output+0x8b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    114d <hw_console_output+0x4d>
jmp    112a <hw_console_output+0x2a>
mov    $0x90000005,%eax
mov    (%rax),%al
movzbl %al,%eax
and    $0x20,%eax
cmp    $0x20,%eax
je     1145 <hw_console_output+0x45>
jmp    112a <hw_console_output+0x2a>
mov    $0x90000000,%eax
movb   $0xd,(%rax)
jmp    1152 <hw_console_output+0x52>
mov    $0x90000005,%eax
mov    (%rax),%al
movzbl %al,%eax
and    $0x20,%eax
cmp    $0x20,%eax
je     116d <hw_console_output+0x6d>
jmp    1152 <hw_console_output+0x52>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    $0x90000000,%eax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1108 <hw_console_output+0x8>
pop    %rbp
ret

x86 assembly (clang, -O2):
<hw_console_output>:
mov    $0x90000000,%eax
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rdi),%cl
cmp    $0xa,%cl
je     1120 <hw_console_output+0x20>
test   %cl,%cl
jne    1130 <hw_console_output+0x30>
jmp    1140 <hw_console_output+0x40>
nopl   (%rax)
testb  $0x20,0x5(%rax)
je     1120 <hw_console_output+0x20>
movb   $0xd,(%rax)
nopl   0x0(%rax)
testb  $0x20,0x5(%rax)
je     1130 <hw_console_output+0x30>
mov    (%rdi),%cl
mov    %cl,(%rax)
add    $0x1,%rdi
jmp    1110 <hw_console_output+0x10>
ret

LLVM IR (-O0):
define void @hw_console_output(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
br label %3
3: ; preds = %27, %1
%4 = load i8*, i8** %2
%5 = load i8, i8* %4
%6 = icmp ne i8 %5, 0
br i1 %6, label %7, label %32
7: ; preds = %3
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 10
br i1 %11, label %12, label %20
12: ; preds = %7
br label %13
13: ; preds = %18, %12
%14 = load volatile i8, i8* inttoptr (i64 2415919109 to i8*)
%15 = zext i8 %14 to i32
%16 = and i32 %15, 32
%17 = icmp ne i32 %16, 32
br i1 %17, label %18, label %19
18: ; preds = %13
br label %13
19: ; preds = %13
store volatile i8 13, i8* inttoptr (i64 2415919104 to i8*)
br label %20
20: ; preds = %19, %7
br label %21
21: ; preds = %26, %20
%22 = load volatile i8, i8* inttoptr (i64 2415919109 to i8*)
%23 = zext i8 %22 to i32
%24 = and i32 %23, 32
%25 = icmp ne i32 %24, 32
br i1 %25, label %26, label %27
26: ; preds = %21
br label %21
27: ; preds = %21
%28 = load i8*, i8** %2
%29 = load i8, i8* %28
store volatile i8 %29, i8* inttoptr (i64 2415919104 to i8*)
%30 = load i8*, i8** %2
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %2
br label %3
32: ; preds = %3
ret void
}

LLVM IR (-O2):
define void @hw_console_output(i8* nocapture %0) {
br label %2
2: ; preds = %15, %1
%3 = phi i8* [ %0, %1 ], [ %17, %15 ]
%4 = load i8, i8* %3
switch i8 %4, label %10 [
i8 0, label %18
i8 10, label %5
]
5: ; preds = %2, %5
%6 = load volatile i8, i8* inttoptr (i64 2415919109 to i8*)
%7 = and i8 %6, 32
%8 = icmp eq i8 %7, 0
br i1 %8, label %5, label %9
9: ; preds = %5
store volatile i8 13, i8* inttoptr (i64 2415919104 to i8*)
br label %10
10: ; preds = %2, %9
br label %11
11: ; preds = %10, %11
%12 = load volatile i8, i8* inttoptr (i64 2415919109 to i8*)
%13 = and i8 %12, 32
%14 = icmp eq i8 %13, 0
br i1 %14, label %11, label %15
15: ; preds = %11
%16 = load i8, i8* %3
store volatile i8 %16, i8* inttoptr (i64 2415919104 to i8*)
%17 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
18: ; preds = %2
ret void
}