#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;
  out(0x3D4, 14);
  offset = in(0x3D5) << 8;
  out(0x3D4, 15);
  offset |= in(0x3D5);
  unsigned char *vidmem = (unsigned char *)0xB8000;
  vidmem += offset * 2;
  int i = 0;
  while (_message[i] != 0) {
    *vidmem++ = _message[i];
    *vidmem++ = 0x0F;
    i++;
  }
  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    $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)
mov    $0xb8000,%eax
mov    %rax,-0x18(%rbp)
movzwl -0xa(%rbp),%ecx
shl    $0x1,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11eb <print+0xcb>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0xf,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119a <print+0x7a>
mov    -0x1c(%rbp),%ecx
movzwl -0xa(%rbp),%eax
add    %ecx,%eax
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     118e <print+0x6e>
mov    %eax,%esi
movzwl %ax,%edx
xor    %eax,%eax
add    %rdx,%rdx
nop
mov    %cl,0xb8000(%rdx,%rax,2)
movb   $0xf,0xb8001(%rdx,%rax,2)
0f
movzbl 0x1(%rbx,%rax,1),%ecx
add    $0x1,%rax
test   %cl,%cl
jne    1170 <print+0x50>
jmp    1192 <print+0x72>
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 i8*
%5 = alloca i32
store i8* %0, i8** %2
%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
store i8* inttoptr (i64 753664 to i8*), i8** %4
%18 = load i16, i16* %3
%19 = zext i16 %18 to i32
%20 = mul nsw i32 %19, 2
%21 = load i8*, i8** %4
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i8, i8* %21, i64 %22
store i8* %23, i8** %4
store i32 0, i32* %5
br label %24
24: ; preds = %32, %1
%25 = load i8*, i8** %2
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %44
32: ; preds = %24
%33 = load i8*, i8** %2
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %4
store i8 %37, i8* %38
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %4
store i8 15, i8* %40
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %24
44: ; preds = %24
%45 = load i32, i32* %5
%46 = load i16, i16* %3
%47 = zext i16 %46 to i32
%48 = add nsw i32 %47, %45
%49 = trunc i32 %48 to i16
store i16 %49, i16* %3
%50 = load i16, i16* %3
%51 = trunc i16 %50 to i8
%52 = call i32 @out(i32 981, i8 zeroext %51)
%53 = call i32 @out(i32 980, i8 zeroext 14)
%54 = load i16, i16* %3
%55 = zext i16 %54 to i32
%56 = ashr i32 %55, 8
%57 = trunc i32 %56 to i8
%58 = call i32 @out(i32 981, i8 zeroext %57)
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 %26, 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 i64 [ 0, %10 ], [ %20, %14 ]
%16 = phi i8 [ %8, %10 ], [ %22, %14 ]
%17 = phi i8* [ %13, %10 ], [ %19, %14 ]
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 %16, i8* %17
%19 = getelementptr inbounds i8, i8* %17, i64 2
store i8 15, i8* %18
%20 = add nuw nsw i64 %15, 1
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %14
24: ; preds = %14
%25 = trunc i64 %20 to i16
br label %26
26: ; preds = %24, %1
%27 = phi i16 [ 0, %1 ], [ %25, %24 ]
%28 = add i16 %7, %27
%29 = trunc i16 %28 to i8
%30 = tail call i32 @out(i32 981, i8 zeroext %29)
%31 = tail call i32 @out(i32 980, i8 zeroext 14)
%32 = lshr i16 %28, 8
%33 = trunc i16 %32 to i8
%34 = tail call i32 @out(i32 981, i8 zeroext %33)
ret void
}