void boot_putchar(int c) {
  static int xpos;
  static int ypos;
  if (c == '\n' || c == '\r') {
  newline:
    xpos = 0;
    ypos++;
    if (ypos >= 24)
      ypos = 0;
    return;
  }
  *((unsigned char *)0xB8000 + (xpos + ypos * 80) * 2) = c & 0xFF;
  *((unsigned char *)0xB8000 + (xpos + ypos * 80) * 2 + 1) = 7;
  xpos++;
  if (xpos >= 80)
    goto newline;
}


x86 assembly (clang, -O0):
<boot_putchar>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
je     111b <boot_putchar+0x1b>
cmpl   $0xd,-0x4(%rbp)
jne    1155 <boot_putchar+0x55>
jmp    1120 <boot_putchar+0x20>
movl   $0x0,0x2efa(%rip)
mov    0x2ef8(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2eef(%rip)
cmpl   $0x18,0x2ee8(%rip)
jl     1150 <boot_putchar+0x50>
movl   $0x0,0x2ed8(%rip)
jmp    11bc <boot_putchar+0xbc>
mov    -0x4(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    0x2ebf(%rip),%eax
imul   $0x50,0x2ebc(%rip),%ecx
add    %ecx,%eax
shl    $0x1,%eax
movslq %eax,%rcx
mov    $0xb8000,%eax
mov    %dl,(%rax,%rcx,1)
mov    0x2ea2(%rip),%eax
imul   $0x50,0x2e9f(%rip),%ecx
add    %ecx,%eax
shl    $0x1,%eax
movslq %eax,%rcx
mov    $0xb8000,%eax
movb   $0x7,0x1(%rax,%rcx,1)
mov    0x2e83(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e7a(%rip)
cmpl   $0x50,0x2e73(%rip)
jl     11bc <boot_putchar+0xbc>
jmp    1120 <boot_putchar+0x20>
pop    %rbp
ret

x86 assembly (clang, -O2):
<boot_putchar>:
cmp    $0xd,%edi
je     1160 <boot_putchar+0x60>
cmp    $0xa,%edi
je     1160 <boot_putchar+0x60>
movslq 0x2f13(%rip),%rax
movslq 0x2f10(%rip),%rcx
lea    (%rcx,%rcx,4),%rcx
shl    $0x4,%rcx
add    %rax,%rcx
mov    %dil,0xb8000(%rcx,%rcx,1)
movslq 0x2ef2(%rip),%rax
movslq 0x2eef(%rip),%rcx
lea    (%rcx,%rcx,4),%rcx
shl    $0x4,%rcx
add    %rax,%rcx
movb   $0x7,0xb8001(%rcx,%rcx,1)
07
mov    0x2ed2(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2ec9(%rip)
cmp    $0x4e,%eax
jle    1181 <boot_putchar+0x81>
movl   $0x0,0x2eba(%rip)
mov    0x2eb8(%rip),%eax
lea    0x1(%rax),%ecx
xor    %edx,%edx
cmp    $0x17,%eax
cmovl  %ecx,%edx
mov    %edx,0x2ea7(%rip)
ret

LLVM IR (-O0):
@boot_putchar.xpos = internal global i32 0
@boot_putchar.ypos = internal global i32 0
define void @boot_putchar(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp eq i32 %3, 10
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 13
br i1 %7, label %8, label %16
8: ; preds = %5, %1
br label %9
9: ; preds = %39, %8
store i32 0, i32* @boot_putchar.xpos
%10 = load i32, i32* @boot_putchar.ypos
%11 = add nsw i32 %10, 1
store i32 %11, i32* @boot_putchar.ypos
%12 = load i32, i32* @boot_putchar.ypos
%13 = icmp sge i32 %12, 24
br i1 %13, label %14, label %15
14: ; preds = %9
store i32 0, i32* @boot_putchar.ypos
br label %15
15: ; preds = %14, %9
br label %40
16: ; preds = %5
%17 = load i32, i32* %2
%18 = and i32 %17, 255
%19 = trunc i32 %18 to i8
%20 = load i32, i32* @boot_putchar.xpos
%21 = load i32, i32* @boot_putchar.ypos
%22 = mul nsw i32 %21, 80
%23 = add nsw i32 %20, %22
%24 = mul nsw i32 %23, 2
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* inttoptr (i64 753664 to i8*), i64 %25
store i8 %19, i8* %26
%27 = load i32, i32* @boot_putchar.xpos
%28 = load i32, i32* @boot_putchar.ypos
%29 = mul nsw i32 %28, 80
%30 = add nsw i32 %27, %29
%31 = mul nsw i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* inttoptr (i64 753664 to i8*), i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8 7, i8* %34
%35 = load i32, i32* @boot_putchar.xpos
%36 = add nsw i32 %35, 1
store i32 %36, i32* @boot_putchar.xpos
%37 = load i32, i32* @boot_putchar.xpos
%38 = icmp sge i32 %37, 80
br i1 %38, label %39, label %40
39: ; preds = %16
br label %9
40: ; preds = %15, %16
ret void
}

LLVM IR (-O2):
@boot_putchar.xpos = internal unnamed_addr global i32 0
@boot_putchar.ypos = internal unnamed_addr global i32 0
define void @boot_putchar(i32 %0) {
switch i32 %0, label %7 [
i32 13, label %2
i32 10, label %2
]
2: ; preds = %1, %1, %7
store i32 0, i32* @boot_putchar.xpos
%3 = load i32, i32* @boot_putchar.ypos
%4 = add nsw i32 %3, 1
%5 = icmp sgt i32 %3, 22
%6 = select i1 %5, i32 0, i32 %4
store i32 %6, i32* @boot_putchar.ypos
br label %27
7: ; preds = %1
%8 = trunc i32 %0 to i8
%9 = load i32, i32* @boot_putchar.xpos
%10 = load i32, i32* @boot_putchar.ypos
%11 = mul nsw i32 %10, 80
%12 = add nsw i32 %11, %9
%13 = shl nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* inttoptr (i64 753664 to i8*), i64 %14
store i8 %8, i8* %15
%16 = load i32, i32* @boot_putchar.xpos
%17 = load i32, i32* @boot_putchar.ypos
%18 = mul nsw i32 %17, 80
%19 = add nsw i32 %18, %16
%20 = shl nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* inttoptr (i64 753664 to i8*), i64 %21
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 7, i8* %23
%24 = load i32, i32* @boot_putchar.xpos
%25 = add nsw i32 %24, 1
store i32 %25, i32* @boot_putchar.xpos
%26 = icmp sgt i32 %24, 78
br i1 %26, label %2, label %27
27: ; preds = %2, %7
ret void
}