void serial_print(unsigned port, char *s) {
  while (*s != 0 || *s != '\0') {
    switch (port) {
    case (0):
      while ((((*(volatile unsigned *)((((0x03ff0000) + 0xD000)) + 0x08))) &
              (1 << 6)) == 0)
        ;
      (*(unsigned *)((((0x03ff0000) + 0xD000)) + 0x0C) = (unsigned)(*s++));
      break;
    case (1):
      while ((((*(volatile unsigned *)((((0x03ff0000) + 0xE000)) + 0x08))) &
              (1 << 6)) == 0)
        ;
      (*(unsigned *)((((0x03ff0000) + 0xE000)) + 0x0C) = (unsigned)(*s++));
      break;
    }
  }
}


x86 assembly (clang, -O0):
<serial_print>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
jne    1130 <serial_print+0x30>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1140 <serial_print+0x40>
jmp    11da <serial_print+0xda>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
test   %eax,%eax
je     1164 <serial_print+0x64>
jmp    1153 <serial_print+0x53>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
je     119f <serial_print+0x9f>
jmp    11d5 <serial_print+0xd5>
jmp    1169 <serial_print+0x69>
mov    $0x3ffd008,%eax
mov    (%rax),%eax
and    $0x40,%eax
cmp    $0x0,%eax
jne    1181 <serial_print+0x81>
jmp    1169 <serial_print+0x69>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%ecx
mov    $0x3ffd00c,%eax
mov    %ecx,(%rax)
jmp    11d5 <serial_print+0xd5>
jmp    11a4 <serial_print+0xa4>
mov    $0x3ffe008,%eax
mov    (%rax),%eax
and    $0x40,%eax
cmp    $0x0,%eax
jne    11bc <serial_print+0xbc>
jmp    11a4 <serial_print+0xa4>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%ecx
mov    $0x3ffe00c,%eax
mov    %ecx,(%rax)
jmp    110b <serial_print+0xb>
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_print>:
jmp    1119 <serial_print+0x19>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rsi
movsbl %al,%eax
mov    %eax,(%rcx)
mov    (%rsi),%al
test   %al,%al
je     1164 <serial_print+0x64>
test   %edi,%edi
je     1150 <serial_print+0x50>
cmp    $0x1,%edi
jne    1119 <serial_print+0x19>
nopl   0x0(%rax,%rax,1)
testl  $0x40,0x3ffe008
je     1130 <serial_print+0x30>
mov    $0x3ffe00c,%ecx
jmp    1110 <serial_print+0x10>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
testl  $0x40,0x3ffd008
je     1150 <serial_print+0x50>
mov    $0x3ffd00c,%ecx
jmp    1110 <serial_print+0x10>
ret

LLVM IR (-O0):
define void @serial_print(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
br label %5
5: ; preds = %41, %2
%6 = load i8*, i8** %4
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br label %15
15: ; preds = %10, %5
%16 = phi i1 [ true, %5 ], [ %14, %10 ]
br i1 %16, label %17, label %42
17: ; preds = %15
%18 = load i32, i32* %3
switch i32 %18, label %41 [
i32 0, label %19
i32 1, label %30
]
19: ; preds = %17
br label %20
20: ; preds = %24, %19
%21 = load volatile i32, i32* inttoptr (i64 67096584 to i32*)
%22 = and i32 %21, 64
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
br label %20
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
%28 = load i8, i8* %26
%29 = sext i8 %28 to i32
store i32 %29, i32* inttoptr (i64 67096588 to i32*)
br label %41
30: ; preds = %17
br label %31
31: ; preds = %35, %30
%32 = load volatile i32, i32* inttoptr (i64 67100680 to i32*)
%33 = and i32 %32, 64
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
br label %31
36: ; preds = %31
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %4
%39 = load i8, i8* %37
%40 = sext i8 %39 to i32
store i32 %40, i32* inttoptr (i64 67100684 to i32*)
br label %41
41: ; preds = %17, %36, %25
br label %5
42: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @serial_print(i32 %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %24, label %5
5: ; preds = %2, %20
%6 = phi i8 [ %22, %20 ], [ %3, %2 ]
%7 = phi i8* [ %21, %20 ], [ %1, %2 ]
switch i32 %0, label %20 [
i32 0, label %8
i32 1, label %12
]
8: ; preds = %5, %8
%9 = load volatile i32, i32* inttoptr (i64 67096584 to i32*)
%10 = and i32 %9, 64
%11 = icmp eq i32 %10, 0
br i1 %11, label %8, label %16
12: ; preds = %5, %12
%13 = load volatile i32, i32* inttoptr (i64 67100680 to i32*)
%14 = and i32 %13, 64
%15 = icmp eq i32 %14, 0
br i1 %15, label %12, label %16
16: ; preds = %12, %8
%17 = phi i32* [ inttoptr (i64 67096588 to i32*), %8 ], [ inttoptr (i64 67100684 to i32*), %12 ]
%18 = getelementptr inbounds i8, i8* %7, i64 1
%19 = sext i8 %6 to i32
store i32 %19, i32* %17
br label %20
20: ; preds = %16, %5
%21 = phi i8* [ %7, %5 ], [ %18, %16 ]
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %5
24: ; preds = %20, %2
ret void
}