#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*/ poke(int, unsigned int, unsigned int);
void text(unsigned x, unsigned y, char *s, unsigned color) {
  unsigned ofs = (y * 40 + x) * 2;
  while (*s) {
    unsigned v = (color << 8) | *s++;
    poke(0xB800, ofs, v);
    ofs += 2;
  }
}


x86 assembly (clang, -O0):
<text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
imul   $0x28,-0x8(%rbp),%eax
add    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     117a <text+0x6a>
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
movsbl (%rcx),%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    $0xb800,%edi
call   1030 <poke@plt>
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    1132 <text+0x22>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdx),%al
test   %al,%al
je     1150 <text+0x40>
mov    %ecx,%r14d
mov    %rdx,%rbx
lea    (%rsi,%rsi,4),%ecx
lea    (%rdi,%rcx,8),%ebp
add    %ebp,%ebp
shl    $0x8,%r14d
add    $0x1,%rbx
movsbl %al,%edx
or     %r14d,%edx
mov    $0xb800,%edi
mov    %ebp,%esi
call   1030 <poke@plt>
add    $0x2,%ebp
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <text+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @text(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i32, i32* %6
%12 = mul i32 %11, 40
%13 = load i32, i32* %5
%14 = add i32 %12, %13
%15 = mul i32 %14, 2
store i32 %15, i32* %9
br label %16
16: ; preds = %20, %4
%17 = load i8*, i8** %7
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = load i32, i32* %8
%22 = shl i32 %21, 8
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %7
%25 = load i8, i8* %23
%26 = sext i8 %25 to i32
%27 = or i32 %22, %26
store i32 %27, i32* %10
%28 = load i32, i32* %9
%29 = load i32, i32* %10
%30 = call i32 @poke(i32 47104, i32 %28, i32 %29)
%31 = load i32, i32* %9
%32 = add i32 %31, 2
store i32 %32, i32* %9
br label %16
33: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @text(i32 %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %23, label %7
7: ; preds = %4
%8 = mul i32 %1, 40
%9 = add i32 %8, %0
%10 = shl i32 %9, 1
%11 = shl i32 %3, 8
br label %12
12: ; preds = %7, %12
%13 = phi i8 [ %5, %7 ], [ %21, %12 ]
%14 = phi i8* [ %2, %7 ], [ %16, %12 ]
%15 = phi i32 [ %10, %7 ], [ %20, %12 ]
%16 = getelementptr inbounds i8, i8* %14, i64 1
%17 = sext i8 %13 to i32
%18 = or i32 %11, %17
%19 = tail call i32 @poke(i32 47104, i32 %15, i32 %18)
%20 = add i32 %15, 2
%21 = load i8, i8* %16
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %12
23: ; preds = %12, %4
ret void
}