#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*/ font_get_bitmap(char);
int /*<<< orphan*/ gfx_draw_bitmap_transparent(int /*<<< orphan*/, long, long,
                                               int, int, long);
void font_draw_string(char *string, long x, long y, long color) {
  long current_x = x;
  long l = 0;
  while (1) {
    if (string[l] == '\n') {
      current_x = x;
      y += 16;
    } else if (string[l] == '\0') {
      return;
    } else {
      gfx_draw_bitmap_transparent(font_get_bitmap(string[l]), current_x, y, 7,
                                  14, color);
      current_x += 8;
    }
    l++;
  }
}


x86 assembly (clang, -O0):
<font_draw_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1176 <font_draw_string+0x56>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x18(%rbp)
jmp    11d1 <font_draw_string+0xb1>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1191 <font_draw_string+0x71>
add    $0x30,%rsp
pop    %rbp
ret
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <font_get_bitmap@plt>
mov    %eax,%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%r9
mov    $0x7,%ecx
mov    $0xe,%r8d
call   1030 <gfx_draw_bitmap_transparent@plt>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    11d1 <font_draw_string+0xb1>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1148 <font_draw_string+0x28>

x86 assembly (clang, -O2):
<font_draw_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%r13
jmp    114b <font_draw_string+0x2b>
nopw   0x0(%rax,%rax,1)
add    $0x10,%r12
add    $0x1,%rbx
mov    %r15,%r13
movzbl (%rbx),%eax
cmp    $0xa,%al
je     1140 <font_draw_string+0x20>
test   %al,%al
je     1183 <font_draw_string+0x63>
movsbl %al,%edi
call   1040 <font_get_bitmap@plt>
mov    %eax,%edi
mov    %r13,%rsi
mov    %r12,%rdx
mov    $0x7,%ecx
mov    $0xe,%r8d
mov    %r14,%r9
call   1030 <gfx_draw_bitmap_transparent@plt>
add    $0x8,%r13
add    $0x1,%rbx
jmp    114b <font_draw_string+0x2b>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @font_draw_string(i8* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%11 = load i64, i64* %6
store i64 %11, i64* %9
store i64 0, i64* %10
br label %12
12: ; preds = %4, %44
%13 = load i8*, i8** %5
%14 = load i64, i64* %10
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %23
19: ; preds = %12
%20 = load i64, i64* %6
store i64 %20, i64* %9
%21 = load i64, i64* %7
%22 = add nsw i64 %21, 16
store i64 %22, i64* %7
br label %44
23: ; preds = %12
%24 = load i8*, i8** %5
%25 = load i64, i64* %10
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %23
ret void
31: ; preds = %23
%32 = load i8*, i8** %5
%33 = load i64, i64* %10
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @font_get_bitmap(i8 signext %35)
%37 = load i64, i64* %9
%38 = load i64, i64* %7
%39 = load i64, i64* %8
%40 = call i32 @gfx_draw_bitmap_transparent(i32 %36, i64 %37, i64 %38, i32 7, i32 14, i64 %39)
%41 = load i64, i64* %9
%42 = add nsw i64 %41, 8
store i64 %42, i64* %9
br label %43
43: ; preds = %31
br label %44
44: ; preds = %43, %19
%45 = load i64, i64* %10
%46 = add nsw i64 %45, 1
store i64 %46, i64* %10
br label %12
}

LLVM IR (-O2):
define void @font_draw_string(i8* nocapture %0, i64 %1, i64 %2, i64 %3) {
br label %5
5: ; preds = %18, %4
%6 = phi i64 [ %2, %4 ], [ %19, %18 ]
%7 = phi i64 [ %1, %4 ], [ %20, %18 ]
%8 = phi i64 [ 0, %4 ], [ %21, %18 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
switch i8 %10, label %14 [
i8 10, label %11
i8 0, label %13
]
11: ; preds = %5
%12 = add nsw i64 %6, 16
br label %18
13: ; preds = %5
ret void
14: ; preds = %5
%15 = tail call i32 @font_get_bitmap(i8 signext %10)
%16 = tail call i32 @gfx_draw_bitmap_transparent(i32 %15, i64 %7, i64 %6, i32 7, i32 14, i64 %3)
%17 = add nsw i64 %7, 8
br label %18
18: ; preds = %14, %11
%19 = phi i64 [ %12, %11 ], [ %6, %14 ]
%20 = phi i64 [ %1, %11 ], [ %17, %14 ]
%21 = add nuw nsw i64 %8, 1
br label %5
}