#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 */
struct raster {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ drawchar(struct raster *, int, int, int /*<<< orphan*/, int,
                            int, int, int);
int /*<<< orphan*/ tolower(char);
void drawtext(struct raster *ra, int x, int y, char *s, int size, int r, int g,
              int b) {
  while (*s) {
    drawchar(ra, x, y, tolower(*s), size, r, g, b);
    s++;
    x += ((size == 1 ? 2 : 1) * size) + 2 * size;
  }
}


x86 assembly (clang, -O0):
<drawtext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11cf <drawtext+0xaf>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    0x10(%rbp),%r10d
mov    0x18(%rbp),%eax
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1030 <drawchar@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%edx
mov    $0x1,%eax
mov    $0x2,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
imul   -0x1c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1144 <drawtext+0x24>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drawtext>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,0x4(%rsp)
mov    (%rcx),%al
test   %al,%al
je     119b <drawtext+0x7b>
mov    %r8d,%r12d
mov    %rcx,%rbx
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r13
xor    %r14d,%r14d
cmp    $0x1,%r8d
sete   %r14b
add    $0x3,%r14d
imul   %r8d,%r14d
add    $0x1,%rbx
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1040 <tolower@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %eax,%ecx
mov    %r12d,%r8d
mov    0x4(%rsp),%r9d
mov    0x48(%rsp),%eax
push   %rax
mov    0x48(%rsp),%eax
push   %rax
call   1030 <drawchar@plt>
add    $0x10,%rsp
add    %r14d,%ebp
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <drawtext+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.raster = type { i32 }
define void @drawtext(%struct.raster* %0, i32 %1, i32 %2, i8* nocapture %3, i32 %4, i32 %5, i32 %6, i32 %7) {
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 0
br i1 %10, label %25, label %11
11: ; preds = %8
%12 = icmp eq i32 %4, 1
%13 = select i1 %12, i32 4, i32 3
%14 = mul i32 %13, %4
br label %15
15: ; preds = %11, %15
%16 = phi i8 [ %9, %11 ], [ %23, %15 ]
%17 = phi i32 [ %1, %11 ], [ %22, %15 ]
%18 = phi i8* [ %3, %11 ], [ %21, %15 ]
%19 = tail call i32 @tolower(i8 signext %16)
%20 = tail call i32 @drawchar(%struct.raster* %0, i32 %17, i32 %2, i32 %19, i32 %4, i32 %5, i32 %6, i32 %7)
%21 = getelementptr inbounds i8, i8* %18, i64 1
%22 = add nsw i32 %17, %14
%23 = load i8, i8* %21
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %15
25: ; preds = %15, %8
ret void
}