#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*/ 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 if (text[i] == '\t') {
      int spaces;
      for (spaces = 0; spaces < 4; spaces++) {
        if (CurrentLocation == 2000) {
          ShiftDisplayUpOneLine();
          CurrentLocation -= 80;
        }
        DisplayMemoryPtr[CurrentLocation++] = (unsigned short)(0x0200 | ' ');
      }
    } else if (text[i] == '\b') {
      if (CurrentLocation > 0) {
        DisplayMemoryPtr[--CurrentLocation] = (unsigned short)(0x0200 | ' ');
      }
    } 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));
  }
}


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     12ff <Print+0x1df>
cmpl   $0x7d0,0x2ed9(%rip)
jne    1177 <Print+0x57>
mov    $0x0,%al
call   1040 <ShiftDisplayUpOneLine@plt>
mov    0x2ec6(%rip),%eax
sub    $0x50,%eax
mov    %eax,0x2ebd(%rip)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11b3 <Print+0x93>
mov    0x2ea2(%rip),%eax
mov    $0x50,%ecx
xor    %edx,%edx
div    %ecx
mov    $0x50,%eax
sub    %edx,%eax
add    0x2e8c(%rip),%eax
mov    %eax,0x2e86(%rip)
jmp    12aa <Print+0x18a>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
jne    122f <Print+0x10f>
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    122a <Print+0x10a>
cmpl   $0x7d0,0x2e51(%rip)
jne    11ff <Print+0xdf>
mov    $0x0,%al
call   1040 <ShiftDisplayUpOneLine@plt>
mov    0x2e3e(%rip),%eax
sub    $0x50,%eax
mov    %eax,0x2e35(%rip)
mov    -0x10(%rbp),%rax
mov    0x2e2b(%rip),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,0x2e20(%rip)
mov    %ecx,%ecx
movw   $0x220,(%rax,%rcx,2)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11cf <Print+0xaf>
jmp    12a5 <Print+0x185>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x8,%eax
jne    1271 <Print+0x151>
cmpl   $0x0,0x2de9(%rip)
jbe    126c <Print+0x14c>
mov    -0x10(%rbp),%rax
mov    0x2dd9(%rip),%ecx
add    $0xffffffff,%ecx
mov    %ecx,0x2dd0(%rip)
mov    %ecx,%ecx
movw   $0x220,(%rax,%rcx,2)
jmp    12a0 <Print+0x180>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
or     $0x200,%eax
mov    %ax,%dx
mov    -0x10(%rbp),%rax
mov    0x2da5(%rip),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,0x2d9a(%rip)
mov    %ecx,%ecx
mov    %dx,(%rax,%rcx,2)
jmp    12a5 <Print+0x185>
jmp    12aa <Print+0x18a>
mov    $0x3d4,%edi
mov    $0xe,%esi
call   1030 <outb@plt>
mov    0x2d75(%rip),%eax
shr    $0x8,%eax
mov    $0x3d5,%edi
movzbl %al,%esi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0xf,%esi
call   1030 <outb@plt>
mov    0x2d50(%rip),%eax
mov    $0x3d5,%edi
movzbl %al,%esi
call   1030 <outb@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113c <Print+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Print>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%cl
test   %cl,%cl
je     12ee <Print+0x1ce>
mov    %rdi,%rbx
mov    $0xb8000,%r14d
add    $0x1,%rbx
mov    $0xcccccccd,%r15d
jmp    11b8 <Print+0x98>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%eax
imul   %r15,%rax
shr    $0x26,%rax
lea    (%rax,%rax,4),%eax
shl    $0x4,%eax
add    $0x50,%eax
mov    %eax,0x2ecb(%rip)
mov    $0x3d4,%edi
mov    $0xe,%esi
call   1030 <outb@plt>
movzbl 0x2eb6(%rip),%esi
mov    $0x3d5,%edi
call   1030 <outb@plt>
mov    $0x3d4,%edi
mov    $0xf,%esi
call   1030 <outb@plt>
movzbl 0x2e95(%rip),%esi
mov    $0x3d5,%edi
call   1030 <outb@plt>
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
je     12ee <Print+0x1ce>
mov    0x2e76(%rip),%eax
cmp    $0x7d0,%eax
jne    11df <Print+0xbf>
xor    %eax,%eax
call   1040 <ShiftDisplayUpOneLine@plt>
mov    0x2e62(%rip),%eax
add    $0xffffffb0,%eax
mov    %eax,0x2e59(%rip)
movzbl -0x1(%rbx),%ecx
cmp    $0x8,%cl
je     12b0 <Print+0x190>
cmp    $0xa,%cl
je     1150 <Print+0x30>
cmp    $0x9,%cl
jne    12d0 <Print+0x1b0>
cmp    $0x7d0,%eax
jne    1211 <Print+0xf1>
xor    %eax,%eax
call   1040 <ShiftDisplayUpOneLine@plt>
mov    0x2e26(%rip),%eax
add    $0xffffffb0,%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2e1a(%rip)
mov    %eax,%eax
movw   $0x220,(%r14,%rax,2)
cmp    $0x7d0,%ecx
jne    123b <Print+0x11b>
xor    %eax,%eax
call   1040 <ShiftDisplayUpOneLine@plt>
mov    0x2dfc(%rip),%ecx
add    $0xffffffb0,%ecx
lea    0x1(%rcx),%eax
mov    %eax,0x2df0(%rip)
mov    %ecx,%ecx
movw   $0x220,(%r14,%rcx,2)
cmp    $0x7d0,%eax
jne    1264 <Print+0x144>
xor    %eax,%eax
call   1040 <ShiftDisplayUpOneLine@plt>
mov    0x2dd3(%rip),%eax
add    $0xffffffb0,%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2dc7(%rip)
mov    %eax,%eax
movw   $0x220,(%r14,%rax,2)
cmp    $0x7d0,%ecx
jne    128e <Print+0x16e>
xor    %eax,%eax
call   1040 <ShiftDisplayUpOneLine@plt>
mov    0x2da9(%rip),%ecx
add    $0xffffffb0,%ecx
lea    0x1(%rcx),%eax
mov    %eax,0x2d9d(%rip)
mov    %ecx,%eax
movw   $0x220,(%r14,%rax,2)
jmp    1169 <Print+0x49>
cs nopw 0x0(%rax,%rax,1)
nop
test   %eax,%eax
je     1169 <Print+0x49>
add    $0xffffffff,%eax
mov    %eax,0x2d73(%rip)
movw   $0x220,(%r14,%rax,2)
jmp    1169 <Print+0x49>
nopl   (%rax)
movsbl %cl,%ecx
or     $0x200,%ecx
lea    0x1(%rax),%edx
mov    %edx,0x2d52(%rip)
mov    %eax,%eax
mov    %cx,(%r14,%rax,2)
jmp    1169 <Print+0x49>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@Print.CurrentLocation = internal global i32 0
define void @Print(i8* %0) {
%2 = alloca i8*
%3 = alloca i16*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i16* inttoptr (i64 753664 to i16*), i16** %3
store i32 0, i32* %4
br label %6
6: ; preds = %108, %1
%7 = load i8*, i8** %2
%8 = load i32, i32* %4
%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 %111
14: ; preds = %6
%15 = load i32, i32* @Print.CurrentLocation
%16 = icmp eq i32 %15, 2000
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = call i32 (...) @ShiftDisplayUpOneLine()
%19 = load i32, i32* @Print.CurrentLocation
%20 = sub i32 %19, 80
store i32 %20, i32* @Print.CurrentLocation
br label %21
21: ; preds = %17, %14
%22 = load i8*, i8** %2
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 10
br i1 %28, label %29, label %35
29: ; preds = %21
%30 = load i32, i32* @Print.CurrentLocation
%31 = urem i32 %30, 80
%32 = sub i32 80, %31
%33 = load i32, i32* @Print.CurrentLocation
%34 = add i32 %33, %32
store i32 %34, i32* @Print.CurrentLocation
br label %98
35: ; preds = %21
%36 = load i8*, i8** %2
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 9
br i1 %42, label %43, label %64
43: ; preds = %35
store i32 0, i32* %5
br label %44
44: ; preds = %60, %43
%45 = load i32, i32* %5
%46 = icmp slt i32 %45, 4
br i1 %46, label %47, label %63
47: ; preds = %44
%48 = load i32, i32* @Print.CurrentLocation
%49 = icmp eq i32 %48, 2000
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = call i32 (...) @ShiftDisplayUpOneLine()
%52 = load i32, i32* @Print.CurrentLocation
%53 = sub i32 %52, 80
store i32 %53, i32* @Print.CurrentLocation
br label %54
54: ; preds = %50, %47
%55 = load i16*, i16** %3
%56 = load i32, i32* @Print.CurrentLocation
%57 = add i32 %56, 1
store i32 %57, i32* @Print.CurrentLocation
%58 = zext i32 %56 to i64
%59 = getelementptr inbounds i16, i16* %55, i64 %58
store i16 544, i16* %59
br label %60
60: ; preds = %54
%61 = load i32, i32* %5
%62 = add nsw i32 %61, 1
store i32 %62, i32* %5
br label %44
63: ; preds = %44
br label %97
64: ; preds = %35
%65 = load i8*, i8** %2
%66 = load i32, i32* %4
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 8
br i1 %71, label %72, label %82
72: ; preds = %64
%73 = load i32, i32* @Print.CurrentLocation
%74 = icmp ugt i32 %73, 0
br i1 %74, label %75, label %81
75: ; preds = %72
%76 = load i16*, i16** %3
%77 = load i32, i32* @Print.CurrentLocation
%78 = add i32 %77, -1
store i32 %78, i32* @Print.CurrentLocation
%79 = zext i32 %78 to i64
%80 = getelementptr inbounds i16, i16* %76, i64 %79
store i16 544, i16* %80
br label %81
81: ; preds = %75, %72
br label %96
82: ; preds = %64
%83 = load i8*, i8** %2
%84 = load i32, i32* %4
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = or i32 512, %88
%90 = trunc i32 %89 to i16
%91 = load i16*, i16** %3
%92 = load i32, i32* @Print.CurrentLocation
%93 = add i32 %92, 1
store i32 %93, i32* @Print.CurrentLocation
%94 = zext i32 %92 to i64
%95 = getelementptr inbounds i16, i16* %91, i64 %94
store i16 %90, i16* %95
br label %96
96: ; preds = %82, %81
br label %97
97: ; preds = %96, %63
br label %98
98: ; preds = %97, %29
%99 = call i32 @outb(i32 980, i8 zeroext 14)
%100 = load i32, i32* @Print.CurrentLocation
%101 = lshr i32 %100, 8
%102 = trunc i32 %101 to i8
%103 = call i32 @outb(i32 981, i8 zeroext %102)
%104 = call i32 @outb(i32 980, i8 zeroext 15)
%105 = load i32, i32* @Print.CurrentLocation
%106 = trunc i32 %105 to i8
%107 = call i32 @outb(i32 981, i8 zeroext %106)
br label %108
108: ; preds = %98
%109 = load i32, i32* %4
%110 = add nsw i32 %109, 1
store i32 %110, i32* %4
br label %6
111: ; preds = %6
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 %89, label %4
4: ; preds = %1, %75
%5 = phi i64 [ %85, %75 ], [ 0, %1 ]
%6 = phi i8 [ %87, %75 ], [ %2, %1 ]
%7 = phi i8* [ %86, %75 ], [ %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
store i32 %13, i32* @Print.CurrentLocation
%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 ]
switch i8 %17, label %69 [
i8 10, label %20
i8 9, label %18
i8 8, label %63
]
18: ; preds = %15
%19 = icmp eq i32 %16, 2000
br i1 %19, label %24, label %28
20: ; preds = %15
%21 = urem i32 %16, 80
%22 = add i32 %16, 80
%23 = sub i32 %22, %21
store i32 %23, i32* @Print.CurrentLocation
br label %75
24: ; preds = %18
%25 = tail call i32 (...) @ShiftDisplayUpOneLine()
%26 = load i32, i32* @Print.CurrentLocation
%27 = add i32 %26, -80
br label %28
28: ; preds = %24, %18
%29 = phi i32 [ %27, %24 ], [ %16, %18 ]
%30 = add i32 %29, 1
store i32 %30, i32* @Print.CurrentLocation
%31 = zext i32 %29 to i64
%32 = getelementptr inbounds i16, i16* inttoptr (i64 753664 to i16*), i64 %31
store i16 544, i16* %32
%33 = icmp eq i32 %30, 2000
br i1 %33, label %34, label %38
34: ; preds = %28
%35 = tail call i32 (...) @ShiftDisplayUpOneLine()
%36 = load i32, i32* @Print.CurrentLocation
%37 = add i32 %36, -80
br label %38
38: ; preds = %34, %28
%39 = phi i32 [ %37, %34 ], [ %30, %28 ]
%40 = add i32 %39, 1
store i32 %40, i32* @Print.CurrentLocation
%41 = zext i32 %39 to i64
%42 = getelementptr inbounds i16, i16* inttoptr (i64 753664 to i16*), i64 %41
store i16 544, i16* %42
%43 = icmp eq i32 %40, 2000
br i1 %43, label %44, label %48
44: ; preds = %38
%45 = tail call i32 (...) @ShiftDisplayUpOneLine()
%46 = load i32, i32* @Print.CurrentLocation
%47 = add i32 %46, -80
br label %48
48: ; preds = %44, %38
%49 = phi i32 [ %47, %44 ], [ %40, %38 ]
%50 = add i32 %49, 1
store i32 %50, i32* @Print.CurrentLocation
%51 = zext i32 %49 to i64
%52 = getelementptr inbounds i16, i16* inttoptr (i64 753664 to i16*), i64 %51
store i16 544, i16* %52
%53 = icmp eq i32 %50, 2000
br i1 %53, label %54, label %58
54: ; preds = %48
%55 = tail call i32 (...) @ShiftDisplayUpOneLine()
%56 = load i32, i32* @Print.CurrentLocation
%57 = add i32 %56, -80
br label %58
58: ; preds = %54, %48
%59 = phi i32 [ %57, %54 ], [ %50, %48 ]
%60 = add i32 %59, 1
store i32 %60, i32* @Print.CurrentLocation
%61 = zext i32 %59 to i64
%62 = getelementptr inbounds i16, i16* inttoptr (i64 753664 to i16*), i64 %61
store i16 544, i16* %62
br label %75
63: ; preds = %15
%64 = icmp eq i32 %16, 0
br i1 %64, label %75, label %65
65: ; preds = %63
%66 = add i32 %16, -1
store i32 %66, i32* @Print.CurrentLocation
%67 = zext i32 %66 to i64
%68 = getelementptr inbounds i16, i16* inttoptr (i64 753664 to i16*), i64 %67
store i16 544, i16* %68
br label %75
69: ; preds = %15
%70 = sext i8 %17 to i16
%71 = or i16 %70, 512
%72 = add i32 %16, 1
store i32 %72, i32* @Print.CurrentLocation
%73 = zext i32 %16 to i64
%74 = getelementptr inbounds i16, i16* inttoptr (i64 753664 to i16*), i64 %73
store i16 %71, i16* %74
br label %75
75: ; preds = %58, %63, %65, %69, %20
%76 = tail call i32 @outb(i32 980, i8 zeroext 14)
%77 = load i32, i32* @Print.CurrentLocation
%78 = lshr i32 %77, 8
%79 = trunc i32 %78 to i8
%80 = tail call i32 @outb(i32 981, i8 zeroext %79)
%81 = tail call i32 @outb(i32 980, i8 zeroext 15)
%82 = load i32, i32* @Print.CurrentLocation
%83 = trunc i32 %82 to i8
%84 = tail call i32 @outb(i32 981, i8 zeroext %83)
%85 = add nuw i64 %5, 1
%86 = getelementptr inbounds i8, i8* %0, i64 %85
%87 = load i8, i8* %86
%88 = icmp eq i8 %87, 0
br i1 %88, label %89, label %4
89: ; preds = %75, %1
ret void
}