#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 port_byte_in(int);
int /*<<< orphan*/ port_byte_out(int, int);
void main() {
  port_byte_out(0x3d4, 14);
  int position = port_byte_in(0x3d5);
  position = position << 8;
  port_byte_out(0x3d4, 15);
  position += port_byte_in(0x3d5);
  int offset_from_vga = position * 2;
  char *vga = (char *)0xb8000;
  vga[offset_from_vga] = 'X';
  vga[offset_from_vga + 1] = 0x0f;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x3d4,%edi
mov    $0xe,%esi
call   1030 <port_byte_out@plt>
mov    $0x3d5,%edi
call   1040 <port_byte_in@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x4(%rbp)
mov    $0x3d4,%edi
mov    $0xf,%esi
call   1030 <port_byte_out@plt>
mov    $0x3d5,%edi
call   1040 <port_byte_in@plt>
add    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0xb8000,%eax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x58,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0xf,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x3d4,%edi
mov    $0xe,%esi
call   1030 <port_byte_out@plt>
mov    $0x3d5,%edi
call   1040 <port_byte_in@plt>
mov    %eax,%ebx
shl    $0x8,%ebx
mov    $0x3d4,%edi
mov    $0xf,%esi
call   1030 <port_byte_out@plt>
mov    $0x3d5,%edi
call   1040 <port_byte_in@plt>
add    %ebx,%eax
cltq
lea    (%rax,%rax,1),%rcx
movb   $0x58,0xb8000(%rax,%rax,1)
58
movslq %ecx,%rax
movb   $0xf,0xb8001(%rax)
pop    %rbx
ret

LLVM IR (-O0):
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = call i32 @port_byte_out(i32 980, i32 14)
%5 = call i32 @port_byte_in(i32 981)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = shl i32 %6, 8
store i32 %7, i32* %1
%8 = call i32 @port_byte_out(i32 980, i32 15)
%9 = call i32 @port_byte_in(i32 981)
%10 = load i32, i32* %1
%11 = add nsw i32 %10, %9
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = mul nsw i32 %12, 2
store i32 %13, i32* %2
store i8* inttoptr (i64 753664 to i8*), i8** %3
%14 = load i8*, i8** %3
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
store i8 88, i8* %17
%18 = load i8*, i8** %3
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
store i8 15, i8* %22
ret void
}

LLVM IR (-O2):
define void @main() {
%1 = tail call i32 @port_byte_out(i32 980, i32 14)
%2 = tail call i32 @port_byte_in(i32 981)
%3 = shl i32 %2, 8
%4 = tail call i32 @port_byte_out(i32 980, i32 15)
%5 = tail call i32 @port_byte_in(i32 981)
%6 = add nsw i32 %5, %3
%7 = shl nsw i32 %6, 1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* inttoptr (i64 753664 to i8*), i64 %8
store i8 88, i8* %9
%10 = or i32 %7, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* inttoptr (i64 753664 to i8*), i64 %11
store i8 15, i8* %12
ret void
}