#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 */
unsigned short in(int);
int /*<<< orphan*/ out(int, unsigned char);
void print(const char *_message) {
  unsigned short offset;
  unsigned long i;
  unsigned char *vidmem = (unsigned char *)0xB8000;
  out(0x3D4, 14);
  offset = in(0x3D5) << 8;
  out(0x3D4, 15);
  offset |= in(0x3D5);
  vidmem += offset * 2;
  i = 0;
  while (_message[i] != 0) {
    *vidmem = _message[i++];
    vidmem += 2;
  }
  offset += i;
  out(0x3D5, (unsigned char)(offset));
  out(0x3D4, 14);
  out(0x3D5, (unsigned char)(offset >> 8));
}


x86 assembly (clang, -O0):
<print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0xb8000,%eax
mov    %rax,-0x20(%rbp)
mov    $0x3d4,%edi
mov    $0xe,%esi
call   1030 <out@plt>
mov    $0x3d5,%edi
call   1040 <in@plt>
movzwl %ax,%eax
shl    $0x8,%eax
mov    %ax,-0xa(%rbp)
mov    $0x3d4,%edi
mov    $0xf,%esi
call   1030 <out@plt>
mov    $0x3d5,%edi
call   1040 <in@plt>
movzwl %ax,%ecx
movzwl -0xa(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%ecx
shl    $0x1,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11dd <print+0xbd>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    119b <print+0x7b>
mov    -0x18(%rbp),%rcx
movzwl -0xa(%rbp),%eax
add    %rcx,%rax
mov    %ax,-0xa(%rbp)
mov    -0xa(%rbp),%ax
mov    $0x3d5,%edi
movzbl %al,%esi
call   1030 <out@plt>
mov    $0x3d4,%edi
mov    $0xe,%esi
call   1030 <out@plt>
movzwl -0xa(%rbp),%eax
sar    $0x8,%eax
mov    $0x3d5,%edi
movzbl %al,%esi
call   1030 <out@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x3d4,%edi
mov    $0xe,%esi
call   1030 <out@plt>
mov    $0x3d5,%edi
call   1040 <in@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
mov    $0x3d4,%edi
mov    $0xf,%esi
call   1030 <out@plt>
mov    $0x3d5,%edi
call   1040 <in@plt>
or     %ebp,%eax
mov    (%rbx),%cl
test   %cl,%cl
je     1186 <print+0x66>
mov    %eax,%esi
movzwl %ax,%edx
xor    %eax,%eax
add    %rdx,%rdx
nop
mov    %cl,0xb8000(%rdx,%rax,2)
movzbl 0x1(%rbx,%rax,1),%ecx
add    $0x1,%rax
test   %cl,%cl
jne    1170 <print+0x50>
jmp    118a <print+0x6a>
mov    %eax,%esi
xor    %eax,%eax
mov    %esi,%ebx
add    %eax,%ebx
movzbl %bl,%esi
mov    $0x3d5,%edi
call   1030 <out@plt>
mov    $0x3d4,%edi
mov    $0xe,%esi
call   1030 <out@plt>
movzbl %bh,%esi
mov    $0x3d5,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <out@plt>

LLVM IR (-O0):
define void @print(i8* %0) {
%2 = alloca i8*
%3 = alloca i16
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %2
store i8* inttoptr (i64 753664 to i8*), i8** %5
%6 = call i32 @out(i32 980, i8 zeroext 14)
%7 = call zeroext i16 @in(i32 981)
%8 = zext i16 %7 to i32
%9 = shl i32 %8, 8
%10 = trunc i32 %9 to i16
store i16 %10, i16* %3
%11 = call i32 @out(i32 980, i8 zeroext 15)
%12 = call zeroext i16 @in(i32 981)
%13 = zext i16 %12 to i32
%14 = load i16, i16* %3
%15 = zext i16 %14 to i32
%16 = or i32 %15, %13
%17 = trunc i32 %16 to i16
store i16 %17, i16* %3
%18 = load i16, i16* %3
%19 = zext i16 %18 to i32
%20 = mul nsw i32 %19, 2
%21 = load i8*, i8** %5
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i8, i8* %21, i64 %22
store i8* %23, i8** %5
store i64 0, i64* %4
br label %24
24: ; preds = %31, %1
%25 = load i8*, i8** %2
%26 = load i64, i64* %4
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %24
%32 = load i8*, i8** %2
%33 = load i64, i64* %4
%34 = add i64 %33, 1
store i64 %34, i64* %4
%35 = getelementptr inbounds i8, i8* %32, i64 %33
%36 = load i8, i8* %35
%37 = load i8*, i8** %5
store i8 %36, i8* %37
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 2
store i8* %39, i8** %5
br label %24
40: ; preds = %24
%41 = load i64, i64* %4
%42 = load i16, i16* %3
%43 = zext i16 %42 to i64
%44 = add i64 %43, %41
%45 = trunc i64 %44 to i16
store i16 %45, i16* %3
%46 = load i16, i16* %3
%47 = trunc i16 %46 to i8
%48 = call i32 @out(i32 981, i8 zeroext %47)
%49 = call i32 @out(i32 980, i8 zeroext 14)
%50 = load i16, i16* %3
%51 = zext i16 %50 to i32
%52 = ashr i32 %51, 8
%53 = trunc i32 %52 to i8
%54 = call i32 @out(i32 981, i8 zeroext %53)
ret void
}

LLVM IR (-O2):
define void @print(i8* nocapture %0) {
%2 = tail call i32 @out(i32 980, i8 zeroext 14)
%3 = tail call zeroext i16 @in(i32 981)
%4 = shl i16 %3, 8
%5 = tail call i32 @out(i32 980, i8 zeroext 15)
%6 = tail call zeroext i16 @in(i32 981)
%7 = or i16 %6, %4
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %1
%11 = zext i16 %7 to i64
%12 = shl nuw nsw i64 %11, 1
%13 = getelementptr inbounds i8, i8* inttoptr (i64 753664 to i8*), i64 %12
br label %14
14: ; preds = %10, %14
%15 = phi i8 [ %21, %14 ], [ %8, %10 ]
%16 = phi i8* [ %19, %14 ], [ %13, %10 ]
%17 = phi i64 [ %18, %14 ], [ 0, %10 ]
%18 = add i64 %17, 1
store i8 %15, i8* %16
%19 = getelementptr inbounds i8, i8* %16, i64 2
%20 = getelementptr inbounds i8, i8* %0, i64 %18
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %14
23: ; preds = %14
%24 = trunc i64 %18 to i16
br label %25
25: ; preds = %23, %1
%26 = phi i16 [ 0, %1 ], [ %24, %23 ]
%27 = add i16 %7, %26
%28 = trunc i16 %27 to i8
%29 = tail call i32 @out(i32 981, i8 zeroext %28)
%30 = tail call i32 @out(i32 980, i8 zeroext 14)
%31 = lshr i16 %27, 8
%32 = trunc i16 %31 to i8
%33 = tail call i32 @out(i32 981, i8 zeroext %32)
ret void
}