#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*/ init_serial();
int /*<<< orphan*/ outportb(int, char const);
int /*<<< orphan*/ vfb_clear();
int /*<<< orphan*/ vfb_putstr(char const *, int);
void printk(const char *msg) {
  int i;
  init_serial();
  vfb_clear();
  for (i = 0; msg[i] != '\0'; ++i)
    outportb(0x3F8, msg[i]);
  vfb_putstr(msg, i);
}


x86 assembly (clang, -O0):
<printk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <init_serial@plt>
mov    $0x0,%al
call   1040 <vfb_clear@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     119a <printk+0x5a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    $0x3f8,%edi
movsbl (%rax,%rcx,1),%esi
call   1050 <outportb@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1161 <printk+0x21>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <vfb_putstr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printk>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <init_serial@plt>
xor    %eax,%eax
call   1040 <vfb_clear@plt>
mov    (%r14),%al
test   %al,%al
je     117b <printk+0x3b>
xor    %ebx,%ebx
movsbl %al,%esi
mov    $0x3f8,%edi
call   1050 <outportb@plt>
movzbl 0x1(%r14,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <printk+0x20>
mov    %r14,%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <vfb_putstr@plt>

LLVM IR (-O0):
define void @printk(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = call i32 (...) @init_serial()
%5 = call i32 (...) @vfb_clear()
store i32 0, i32* %3
br label %6
6: ; preds = %21, %1
%7 = load i8*, i8** %2
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %6
%15 = load i8*, i8** %2
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @outportb(i32 1016, i8 signext %19)
br label %21
21: ; preds = %14
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %6
24: ; preds = %6
%25 = load i8*, i8** %2
%26 = load i32, i32* %3
%27 = call i32 @vfb_putstr(i8* %25, i32 %26)
ret void
}

LLVM IR (-O2):
define void @printk(i8* %0) {
%2 = tail call i32 (...) @init_serial()
%3 = tail call i32 (...) @vfb_clear()
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %10, %6 ], [ 0, %1 ]
%8 = phi i8 [ %12, %6 ], [ %4, %1 ]
%9 = tail call i32 @outportb(i32 1016, i8 signext %8)
%10 = add nuw i64 %7, 1
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %6
%15 = trunc i64 %10 to i32
br label %16
16: ; preds = %14, %1
%17 = phi i32 [ 0, %1 ], [ %15, %14 ]
%18 = tail call i32 @vfb_putstr(i8* %0, i32 %17)
ret void
}