#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 */
scalar_t__ tga_draw_glyph(unsigned int, unsigned int, char const, int);
unsigned tga_draw_string(unsigned x, unsigned y, const char *s, int is_hints,
                         unsigned max_dx) {
  unsigned dx = 0;
  while (*s != '\0') {
    dx += tga_draw_glyph(x + dx, y, *s, is_hints);
    if (max_dx > 0)
      if (dx > max_dx)
        break;
    s++;
  }
  return dx;
}


x86 assembly (clang, -O0):
<tga_draw_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1197 <tga_draw_string+0x87>
mov    -0x4(%rbp),%edi
add    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x14(%rbp),%ecx
movsbl %al,%edx
call   1030 <tga_draw_glyph@plt>
mov    %rax,%rcx
mov    -0x1c(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
jbe    1186 <tga_draw_string+0x76>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jbe    1181 <tga_draw_string+0x71>
jmp    1197 <tga_draw_string+0x87>
jmp    1186 <tga_draw_string+0x76>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1130 <tga_draw_string+0x20>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tga_draw_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    (%rdx),%cl
test   %cl,%cl
je     116e <tga_draw_string+0x5e>
mov    %r8d,%r13d
mov    %rdx,%rbp
mov    %esi,%r15d
mov    %edi,%r12d
add    $0x1,%rbp
xor    %eax,%eax
jmp    114c <tga_draw_string+0x3c>
nopl   0x0(%rax,%rax,1)
movzbl 0x0(%rbp),%ecx
add    $0x1,%rbp
test   %cl,%cl
je     1170 <tga_draw_string+0x60>
mov    %eax,%ebx
lea    (%rbx,%r12,1),%edi
movsbl %cl,%edx
mov    %r15d,%esi
mov    %r14d,%ecx
call   1030 <tga_draw_glyph@plt>
add    %ebx,%eax
test   %r13d,%r13d
je     1140 <tga_draw_string+0x30>
cmp    %r13d,%eax
jbe    1140 <tga_draw_string+0x30>
jmp    1170 <tga_draw_string+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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