#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 computePosition(int, int);
int /*<<< orphan*/ putInMemory(int, int, int);
void printStringDirect(char *string, int color, int xCoordinate,
                       int yCoordinate) {
  int position = computePosition(xCoordinate, yCoordinate);
  int i = 0;
  while (string[i] != '\0') {
    putInMemory(0xB000, 0x8000 + position, string[i]);
    position++;
    putInMemory(0xB000, 0x8000 + position, color);
    position++;
    i++;
  }
}


x86 assembly (clang, -O0):
<printStringDirect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <computePosition@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11b4 <printStringDirect+0x94>
mov    -0x18(%rbp),%esi
add    $0x8000,%esi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
mov    $0xb000,%edi
call   1030 <putInMemory@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
add    $0x8000,%esi
mov    -0xc(%rbp),%edx
mov    $0xb000,%edi
call   1030 <putInMemory@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114a <printStringDirect+0x2a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printStringDirect>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
mov    %edx,%edi
mov    %ecx,%esi
call   1040 <computePosition@plt>
mov    %eax,%ebp
mov    (%rbx),%al
test   %al,%al
je     117d <printStringDirect+0x5d>
add    $0x1,%rbx
add    $0x8000,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%edx
mov    $0xb000,%edi
mov    %ebp,%esi
call   1030 <putInMemory@plt>
lea    0x1(%rbp),%esi
mov    $0xb000,%edi
mov    %r14d,%edx
call   1030 <putInMemory@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
add    $0x2,%ebp
test   %al,%al
jne    1150 <printStringDirect+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @printStringDirect(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %7
%12 = load i32, i32* %8
%13 = call i32 @computePosition(i32 %11, i32 %12)
store i32 %13, i32* %9
store i32 0, i32* %10
br label %14
14: ; preds = %22, %4
%15 = load i8*, i8** %5
%16 = load i32, i32* %10
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %42
22: ; preds = %14
%23 = load i32, i32* %9
%24 = add nsw i32 32768, %23
%25 = load i8*, i8** %5
%26 = load i32, i32* %10
%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 = call i32 @putInMemory(i32 45056, i32 %24, i32 %30)
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
%34 = load i32, i32* %9
%35 = add nsw i32 32768, %34
%36 = load i32, i32* %6
%37 = call i32 @putInMemory(i32 45056, i32 %35, i32 %36)
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
br label %14
42: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @printStringDirect(i8* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @computePosition(i32 %2, i32 %3)
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %4, %8
%9 = phi i64 [ %18, %8 ], [ 0, %4 ]
%10 = phi i8 [ %20, %8 ], [ %6, %4 ]
%11 = phi i32 [ %17, %8 ], [ %5, %4 ]
%12 = sext i8 %10 to i32
%13 = add nsw i32 %11, 32768
%14 = tail call i32 @putInMemory(i32 45056, i32 %13, i32 %12)
%15 = add nsw i32 %11, 32769
%16 = tail call i32 @putInMemory(i32 45056, i32 %15, i32 %1)
%17 = add nsw i32 %11, 2
%18 = add nuw i64 %9, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %8
22: ; preds = %8, %4
ret void
}