#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*/ text_draw_character(char, unsigned int, unsigned int,
                                       unsigned int);
void text_draw_string(char *string, unsigned int x, unsigned int y,
                      unsigned int colour) {
  unsigned int temp_x = x;
  while (*string) {
    switch (*string) {
    case '\n':
      y += 16;
      break;
    case '\r':
      x = temp_x;
      break;
    default:
      text_draw_character(*string, x, y, colour);
      x += 8;
    }
    string++;
  }
}


x86 assembly (clang, -O0):
<text_draw_string>:
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    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ab <text_draw_string+0x9b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0xa,%eax
je     1161 <text_draw_string+0x51>
jmp    1150 <text_draw_string+0x40>
mov    -0x1c(%rbp),%eax
sub    $0xd,%eax
je     116f <text_draw_string+0x5f>
jmp    117a <text_draw_string+0x6a>
mov    -0x10(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x10(%rbp)
jmp    119a <text_draw_string+0x8a>
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    119a <text_draw_string+0x8a>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
movsbl %al,%edi
call   1030 <text_draw_character@plt>
mov    -0xc(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112b <text_draw_string+0x1b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_draw_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1175 <text_draw_string+0x65>
mov    %ecx,%r14d
mov    %edx,%r12d
mov    %esi,%r15d
mov    %rdi,%rbx
add    $0x1,%rbx
mov    %esi,%ebp
jmp    115b <text_draw_string+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%esi
mov    %r12d,%edx
mov    %r14d,%ecx
call   1030 <text_draw_character@plt>
add    $0x8,%ebp
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1175 <text_draw_string+0x65>
movsbl %al,%edi
cmp    $0xd,%edi
je     1170 <text_draw_string+0x60>
cmp    $0xa,%edi
jne    1140 <text_draw_string+0x30>
add    $0x10,%r12d
jmp    1150 <text_draw_string+0x40>
xchg   %ax,%ax
mov    %r15d,%ebp
jmp    1150 <text_draw_string+0x40>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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