#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*/ Delay();
int /*<<< orphan*/ ShiftDisplayUpOneLine();
int /*<<< orphan*/ outb(int, unsigned char);
void Print(char text[]) {
  static unsigned int CurrentLocation = 0;
  unsigned short *DisplayMemoryPtr = (unsigned short *)0xB8000;
  int i;
  for (i = 0; text[i] != 0; i++) {
    if (CurrentLocation == 2000) {
      ShiftDisplayUpOneLine();
      CurrentLocation -= 80;
    }
    if (text[i] == '\n') {
      CurrentLocation += (80 - (CurrentLocation % 80));
    } else {
      DisplayMemoryPtr[CurrentLocation++] = (unsigned short)(0x0200 | text[i]);
    }
    outb(0x3D4, 14);
    outb(0x3D5, (unsigned char)(CurrentLocation >> 8));
    outb(0x3D4, 15);
    outb(0x3D5, (unsigned char)(CurrentLocation));
    Delay();
  }
}


x86 assembly (clang, -O0):
<Print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0xb8000,%eax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     124e <Print+0x11e>
cmpl   $0x7d0,0x2ed1(%rip)
jne    1187 <Print+0x57>
mov    $0x0,%al
call   1050 <ShiftDisplayUpOneLine@plt>
mov    0x2ebe(%rip),%eax
sub    $0x50,%eax
mov    %eax,0x2eb5(%rip)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11c3 <Print+0x93>
mov    0x2e9a(%rip),%eax
mov    $0x50,%ecx
xor    %edx,%edx
div    %ecx
mov    $0x50,%eax
sub    %edx,%eax
add    0x2e84(%rip),%eax
mov    %eax,0x2e7e(%rip)
jmp    11f2 <Print+0xc2>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
or     $0x200,%eax
mov    %ax,%dx
mov    -0x10(%rbp),%rax
mov    0x2e5b(%rip),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,0x2e50(%rip)
mov    %ecx,%ecx
mov    %dx,(%rax,%rcx,2)
mov    $0x3d4,%edi
mov    $0xe,%esi
call   1040 <outb@plt>
mov    0x2e35(%rip),%eax
shr    $0x8,%eax
mov    $0x3d5,%edi
movzbl %al,%esi
call   1040 <outb@plt>
mov    $0x3d4,%edi
mov    $0xf,%esi
call   1040 <outb@plt>
mov    0x2e10(%rip),%eax
mov    $0x3d5,%edi
movzbl %al,%esi
call   1040 <outb@plt>
mov    $0x0,%al
call   1030 <Delay@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114c <Print+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Print>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1205 <Print+0xd5>
mov    %rdi,%rbx
add    $0x1,%rbx
mov    $0xcccccccd,%r14d
jmp    11bd <Print+0x8d>
nopl   (%rax)
movsbl %al,%eax
or     $0x200,%eax
lea    0x1(%rcx),%edx
mov    %edx,0x2edb(%rip)
mov    %ecx,%ecx
mov    %ax,0xb8000(%rcx,%rcx,1)
mov    $0x3d4,%edi
mov    $0xe,%esi
call   1040 <outb@plt>
movzbl 0x2ebc(%rip),%esi
mov    $0x3d5,%edi
call   1040 <outb@plt>
mov    $0x3d4,%edi
mov    $0xf,%esi
call   1040 <outb@plt>
movzbl 0x2e9b(%rip),%esi
mov    $0x3d5,%edi
call   1040 <outb@plt>
xor    %eax,%eax
call   1030 <Delay@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1205 <Print+0xd5>
mov    0x2e79(%rip),%ecx
cmp    $0x7d0,%ecx
jne    11df <Print+0xaf>
xor    %eax,%eax
call   1050 <ShiftDisplayUpOneLine@plt>
mov    0x2e64(%rip),%ecx
add    $0xffffffb0,%ecx
movzbl -0x1(%rbx),%eax
cmp    $0xa,%al
jne    1150 <Print+0x20>
mov    %ecx,%eax
imul   %r14,%rax
shr    $0x26,%rax
lea    (%rax,%rax,4),%eax
shl    $0x4,%eax
add    $0x50,%eax
mov    %eax,0x2e3c(%rip)
jmp    116b <Print+0x3b>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@Print.CurrentLocation = internal global i32 0
define void @Print(i8* %0) {
%2 = alloca i8*
%3 = alloca i16*
%4 = alloca i32
store i8* %0, i8** %2
store i16* inttoptr (i64 753664 to i16*), i16** %3
store i32 0, i32* %4
br label %5
5: ; preds = %59, %1
%6 = load i8*, i8** %2
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %62
13: ; preds = %5
%14 = load i32, i32* @Print.CurrentLocation
%15 = icmp eq i32 %14, 2000
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = call i32 (...) @ShiftDisplayUpOneLine()
%18 = load i32, i32* @Print.CurrentLocation
%19 = sub i32 %18, 80
store i32 %19, i32* @Print.CurrentLocation
br label %20
20: ; preds = %16, %13
%21 = load i8*, i8** %2
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %34
28: ; preds = %20
%29 = load i32, i32* @Print.CurrentLocation
%30 = urem i32 %29, 80
%31 = sub i32 80, %30
%32 = load i32, i32* @Print.CurrentLocation
%33 = add i32 %32, %31
store i32 %33, i32* @Print.CurrentLocation
br label %48
34: ; preds = %20
%35 = load i8*, i8** %2
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = or i32 512, %40
%42 = trunc i32 %41 to i16
%43 = load i16*, i16** %3
%44 = load i32, i32* @Print.CurrentLocation
%45 = add i32 %44, 1
store i32 %45, i32* @Print.CurrentLocation
%46 = zext i32 %44 to i64
%47 = getelementptr inbounds i16, i16* %43, i64 %46
store i16 %42, i16* %47
br label %48
48: ; preds = %34, %28
%49 = call i32 @outb(i32 980, i8 zeroext 14)
%50 = load i32, i32* @Print.CurrentLocation
%51 = lshr i32 %50, 8
%52 = trunc i32 %51 to i8
%53 = call i32 @outb(i32 981, i8 zeroext %52)
%54 = call i32 @outb(i32 980, i8 zeroext 15)
%55 = load i32, i32* @Print.CurrentLocation
%56 = trunc i32 %55 to i8
%57 = call i32 @outb(i32 981, i8 zeroext %56)
%58 = call i32 (...) @Delay()
br label %59
59: ; preds = %48
%60 = load i32, i32* %4
%61 = add nsw i32 %60, 1
store i32 %61, i32* %4
br label %5
62: ; preds = %5
ret void
}

LLVM IR (-O2):
@Print.CurrentLocation = internal unnamed_addr global i32 0
define void @Print(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %44, label %4
4: ; preds = %1, %29
%5 = phi i64 [ %40, %29 ], [ 0, %1 ]
%6 = phi i8 [ %42, %29 ], [ %2, %1 ]
%7 = phi i8* [ %41, %29 ], [ %0, %1 ]
%8 = load i32, i32* @Print.CurrentLocation
%9 = icmp eq i32 %8, 2000
br i1 %9, label %10, label %15
10: ; preds = %4
%11 = tail call i32 (...) @ShiftDisplayUpOneLine()
%12 = load i32, i32* @Print.CurrentLocation
%13 = add i32 %12, -80
%14 = load i8, i8* %7
br label %15
15: ; preds = %10, %4
%16 = phi i32 [ %13, %10 ], [ %8, %4 ]
%17 = phi i8 [ %14, %10 ], [ %6, %4 ]
%18 = icmp eq i8 %17, 10
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = urem i32 %16, 80
%21 = add i32 %16, 80
%22 = sub i32 %21, %20
store i32 %22, i32* @Print.CurrentLocation
br label %29
23: ; preds = %15
%24 = sext i8 %17 to i16
%25 = or i16 %24, 512
%26 = add i32 %16, 1
store i32 %26, i32* @Print.CurrentLocation
%27 = zext i32 %16 to i64
%28 = getelementptr inbounds i16, i16* inttoptr (i64 753664 to i16*), i64 %27
store i16 %25, i16* %28
br label %29
29: ; preds = %23, %19
%30 = tail call i32 @outb(i32 980, i8 zeroext 14)
%31 = load i32, i32* @Print.CurrentLocation
%32 = lshr i32 %31, 8
%33 = trunc i32 %32 to i8
%34 = tail call i32 @outb(i32 981, i8 zeroext %33)
%35 = tail call i32 @outb(i32 980, i8 zeroext 15)
%36 = load i32, i32* @Print.CurrentLocation
%37 = trunc i32 %36 to i8
%38 = tail call i32 @outb(i32 981, i8 zeroext %37)
%39 = tail call i32 (...) @Delay()
%40 = add nuw i64 %5, 1
%41 = getelementptr inbounds i8, i8* %0, i64 %40
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 0
br i1 %43, label %44, label %4
44: ; preds = %29, %1
ret void
}