#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*/ fetch_cursor();
int /*<<< orphan*/ inb(int);
int /*<<< orphan*/ outb(int, char const);
int /*<<< orphan*/ print_char(int /*<<< orphan*/);
int /*<<< orphan*/ update_cursor();
void print_string(const char *s) {
  fetch_cursor();
  while (*s != '\0') {
    print_char(*s++);
    while (!inb(0x3FD) & 0x20)
      ;
    outb(0x3F8, s[-1]);
  }
  update_cursor();
}


x86 assembly (clang, -O0):
<print_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <fetch_cursor@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c9 <print_string+0x79>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1070 <print_char@plt>
mov    $0x3fd,%edi
call   1040 <inb@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     11b2 <print_string+0x62>
jmp    118a <print_string+0x3a>
mov    -0x8(%rbp),%rax
mov    $0x3f8,%edi
movsbl -0x1(%rax),%esi
call   1030 <outb@plt>
jmp    1163 <print_string+0x13>
mov    $0x0,%al
call   1060 <update_cursor@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_string>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <fetch_cursor@plt>
mov    (%rbx),%al
test   %al,%al
je     119b <print_string+0x4b>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%edi
call   1070 <print_char@plt>
mov    $0x3fd,%edi
call   1040 <inb@plt>
movsbl -0x1(%rbx),%esi
mov    $0x3f8,%edi
call   1030 <outb@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1170 <print_string+0x20>
xor    %eax,%eax
pop    %rbx
jmp    1060 <update_cursor@plt>

LLVM IR (-O0):
define void @print_string(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i32 (...) @fetch_cursor()
br label %4
4: ; preds = %23, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %4
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %2
%12 = load i8, i8* %10
%13 = sext i8 %12 to i32
%14 = call i32 @print_char(i32 %13)
br label %15
15: ; preds = %22, %9
%16 = call i32 @inb(i32 1021)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
%19 = zext i1 %18 to i32
%20 = and i32 %19, 32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %15
br label %15
23: ; preds = %15
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 -1
%26 = load i8, i8* %25
%27 = call i32 @outb(i32 1016, i8 signext %26)
br label %4
28: ; preds = %4
%29 = call i32 (...) @update_cursor()
ret void
}

LLVM IR (-O2):
define void @print_string(i8* nocapture %0) {
%2 = tail call i32 (...) @fetch_cursor()
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %1, %5
%6 = phi i8 [ %14, %5 ], [ %3, %1 ]
%7 = phi i8* [ %9, %5 ], [ %0, %1 ]
%8 = sext i8 %6 to i32
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = tail call i32 @print_char(i32 %8)
%11 = tail call i32 @inb(i32 1021)
%12 = load i8, i8* %7
%13 = tail call i32 @outb(i32 1016, i8 signext %12)
%14 = load i8, i8* %9
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %5
16: ; preds = %5, %1
%17 = tail call i32 (...) @update_cursor()
ret void
}