#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();
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]);
    }
  }
}


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     11e5 <Print+0xd5>
cmpl   $0x7d0,0x2ee1(%rip)
jne    1167 <Print+0x57>
mov    $0x0,%al
call   1030 <ShiftDisplayUpOneLine@plt>
mov    0x2ece(%rip),%eax
sub    $0x50,%eax
mov    %eax,0x2ec5(%rip)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11a3 <Print+0x93>
mov    0x2eaa(%rip),%eax
mov    $0x50,%ecx
xor    %edx,%edx
div    %ecx
mov    $0x50,%eax
sub    %edx,%eax
add    0x2e94(%rip),%eax
mov    %eax,0x2e8e(%rip)
jmp    11d2 <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    0x2e6b(%rip),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,0x2e60(%rip)
mov    %ecx,%ecx
mov    %dx,(%rax,%rcx,2)
jmp    11d7 <Print+0xc7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112c <Print+0x1c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Print>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%cl
test   %cl,%cl
je     1192 <Print+0x82>
mov    %rdi,%rbx
mov    0x2f09(%rip),%eax
add    $0x1,%rbx
mov    $0xcccccccd,%r14d
jmp    1157 <Print+0x47>
nop
movsbl %cl,%ecx
or     $0x200,%ecx
mov    %eax,%edx
add    $0x1,%eax
mov    %eax,0x2ee8(%rip)
mov    %cx,0xb8000(%rdx,%rdx,1)
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
je     1192 <Print+0x82>
cmp    $0x7d0,%eax
jne    1172 <Print+0x62>
xor    %eax,%eax
call   1030 <ShiftDisplayUpOneLine@plt>
mov    0x2ec1(%rip),%eax
add    $0xffffffb0,%eax
movzbl -0x1(%rbx),%ecx
cmp    $0xa,%cl
jne    1130 <Print+0x20>
mov    %eax,%eax
imul   %r14,%rax
shr    $0x26,%rax
lea    (%rax,%rax,4),%eax
shl    $0x4,%eax
add    $0x50,%eax
mov    %eax,0x2e9c(%rip)
jmp    114c <Print+0x3c>
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 = %49, %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 %52
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
br label %49
49: ; preds = %48
%50 = load i32, i32* %4
%51 = add nsw i32 %50, 1
store i32 %51, i32* %4
br label %5
52: ; 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 %37, label %4
4: ; preds = %1
%5 = load i32, i32* @Print.CurrentLocation
br label %6
6: ; preds = %4, %31
%7 = phi i32 [ %5, %4 ], [ %32, %31 ]
%8 = phi i64 [ 0, %4 ], [ %33, %31 ]
%9 = phi i8 [ %2, %4 ], [ %35, %31 ]
%10 = phi i8* [ %0, %4 ], [ %34, %31 ]
%11 = icmp eq i32 %7, 2000
br i1 %11, label %12, label %17
12: ; preds = %6
%13 = tail call i32 (...) @ShiftDisplayUpOneLine()
%14 = load i32, i32* @Print.CurrentLocation
%15 = add i32 %14, -80
%16 = load i8, i8* %10
br label %17
17: ; preds = %12, %6
%18 = phi i32 [ %15, %12 ], [ %7, %6 ]
%19 = phi i8 [ %16, %12 ], [ %9, %6 ]
%20 = icmp eq i8 %19, 10
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = urem i32 %18, 80
%23 = add i32 %18, 80
%24 = sub i32 %23, %22
store i32 %24, i32* @Print.CurrentLocation
br label %31
25: ; preds = %17
%26 = sext i8 %19 to i16
%27 = or i16 %26, 512
%28 = add i32 %18, 1
store i32 %28, i32* @Print.CurrentLocation
%29 = zext i32 %18 to i64
%30 = getelementptr inbounds i16, i16* inttoptr (i64 753664 to i16*), i64 %29
store i16 %27, i16* %30
br label %31
31: ; preds = %21, %25
%32 = phi i32 [ %24, %21 ], [ %28, %25 ]
%33 = add nuw i64 %8, 1
%34 = getelementptr inbounds i8, i8* %0, i64 %33
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 0
br i1 %36, label %37, label %6
37: ; preds = %31, %1
ret void
}