#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*/ draw_char(char, int, int, char, char, char, int);
int strlen(char *);
void draw_string(char *word, int x, int y, char r, char g, char b, int screen) {
  int tmp_x = x;
  int i;
  int line = 0;
  int width;
  switch (screen) {
  case 2:
    width = 320;
    break;
  default:
    width = 400;
    break;
  }
  for (i = 0; i < strlen(word); i++) {
    if (tmp_x + 8 > width) {
      line++;
      tmp_x = x;
    }
    draw_char(word[i], tmp_x, y + (line * 8), r, g, b, screen);
    tmp_x = tmp_x + 8;
  }
}


x86 assembly (clang, -O0):
<draw_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8d,-0x34(%rbp)
mov    %ecx,%eax
mov    -0x34(%rbp),%ecx
mov    %eax,-0x30(%rbp)
mov    %edx,%eax
mov    -0x30(%rbp),%edx
mov    %eax,-0x2c(%rbp)
mov    %esi,%eax
mov    -0x2c(%rbp),%esi
mov    %eax,-0x28(%rbp)
mov    %rdi,%r8
mov    -0x28(%rbp),%edi
mov    %r9b,%al
mov    0x10(%rbp),%r9d
mov    %r8,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %dl,-0x11(%rbp)
mov    %cl,-0x12(%rbp)
mov    %al,-0x13(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x10(%rbp),%eax
sub    $0x2,%eax
jne    118e <draw_string+0x6e>
jmp    1182 <draw_string+0x62>
movl   $0x140,-0x24(%rbp)
jmp    1195 <draw_string+0x75>
movl   $0x190,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jge    122c <draw_string+0x10c>
mov    -0x18(%rbp),%eax
add    $0x8,%eax
cmp    -0x24(%rbp),%eax
jle    11d6 <draw_string+0xb6>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dil
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x20(%rbp),%eax
shl    $0x3,%eax
add    %eax,%edx
mov    -0x11(%rbp),%cl
mov    -0x12(%rbp),%r8b
mov    -0x13(%rbp),%r9b
mov    0x10(%rbp),%eax
movsbl %dil,%edi
movsbl %cl,%ecx
movsbl %r8b,%r8d
movsbl %r9b,%r9d
mov    %eax,(%rsp)
call   1040 <draw_char@plt>
mov    -0x18(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119c <draw_string+0x7c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r14d
mov    %r8d,%r13d
mov    %ecx,%ebp
mov    %rdx,0x20(%rsp)
mov    %esi,0x14(%rsp)
mov    %rdi,%rbx
cmpl   $0x2,0x60(%rsp)
mov    $0x140,%eax
mov    $0x190,%ecx
cmove  %eax,%ecx
mov    %ecx,0x1c(%rsp)
call   1030 <strlen@plt>
test   %eax,%eax
jle    11d4 <draw_string+0xb4>
xor    %r15d,%r15d
movsbl %bpl,%eax
mov    %eax,0x18(%rsp)
movsbl %r13b,%r13d
movsbl %r14b,%ebp
xor    %r12d,%r12d
mov    0x14(%rsp),%eax
mov    %eax,%r14d
xchg   %ax,%ax
lea    0x8(%r14),%eax
xor    %ecx,%ecx
cmp    0x1c(%rsp),%eax
cmovg  0x14(%rsp),%r14d
setg   %cl
add    %ecx,%r12d
movsbl (%rbx,%r15,1),%edi
mov    0x20(%rsp),%rax
lea    (%rax,%r12,8),%edx
mov    0x60(%rsp),%eax
mov    %eax,(%rsp)
mov    %r14d,%esi
mov    0x18(%rsp),%ecx
mov    %r13d,%r8d
mov    %ebp,%r9d
call   1040 <draw_char@plt>
add    $0x8,%r14d
add    $0x1,%r15
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%r15
jl     1180 <draw_string+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @draw_string(i8* %0, i32 %1, i32 %2, i8 signext %3, i8 signext %4, i8 signext %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i8
%13 = alloca i8
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i8 %3, i8* %11
store i8 %4, i8* %12
store i8 %5, i8* %13
store i32 %6, i32* %14
%19 = load i32, i32* %9
store i32 %19, i32* %15
store i32 0, i32* %17
%20 = load i32, i32* %14
switch i32 %20, label %22 [
i32 2, label %21
]
21: ; preds = %7
store i32 320, i32* %18
br label %23
22: ; preds = %7
store i32 400, i32* %18
br label %23
23: ; preds = %22, %21
store i32 0, i32* %16
br label %24
24: ; preds = %56, %23
%25 = load i32, i32* %16
%26 = load i8*, i8** %8
%27 = call i32 @strlen(i8* %26)
%28 = icmp slt i32 %25, %27
br i1 %28, label %29, label %59
29: ; preds = %24
%30 = load i32, i32* %15
%31 = add nsw i32 %30, 8
%32 = load i32, i32* %18
%33 = icmp sgt i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* %17
%36 = add nsw i32 %35, 1
store i32 %36, i32* %17
%37 = load i32, i32* %9
store i32 %37, i32* %15
br label %38
38: ; preds = %34, %29
%39 = load i8*, i8** %8
%40 = load i32, i32* %16
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = load i32, i32* %15
%45 = load i32, i32* %10
%46 = load i32, i32* %17
%47 = mul nsw i32 %46, 8
%48 = add nsw i32 %45, %47
%49 = load i8, i8* %11
%50 = load i8, i8* %12
%51 = load i8, i8* %13
%52 = load i32, i32* %14
%53 = call i32 @draw_char(i8 signext %43, i32 %44, i32 %48, i8 signext %49, i8 signext %50, i8 signext %51, i32 %52)
%54 = load i32, i32* %15
%55 = add nsw i32 %54, 8
store i32 %55, i32* %15
br label %56
56: ; preds = %38
%57 = load i32, i32* %16
%58 = add nsw i32 %57, 1
store i32 %58, i32* %16
br label %24
59: ; preds = %24
ret void
}

LLVM IR (-O2):
define void @draw_string(i8* %0, i32 %1, i32 %2, i8 signext %3, i8 signext %4, i8 signext %5, i32 %6) {
%8 = icmp eq i32 %6, 2
%9 = select i1 %8, i32 320, i32 400
%10 = tail call i32 @strlen(i8* %0)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %7, %12
%13 = phi i64 [ %27, %12 ], [ 0, %7 ]
%14 = phi i32 [ %20, %12 ], [ 0, %7 ]
%15 = phi i32 [ %26, %12 ], [ %1, %7 ]
%16 = add nsw i32 %15, 8
%17 = icmp sgt i32 %16, %9
%18 = select i1 %17, i32 %1, i32 %15
%19 = zext i1 %17 to i32
%20 = add nuw nsw i32 %14, %19
%21 = getelementptr inbounds i8, i8* %0, i64 %13
%22 = load i8, i8* %21
%23 = shl nsw i32 %20, 3
%24 = add nsw i32 %23, %2
%25 = tail call i32 @draw_char(i8 signext %22, i32 %18, i32 %24, i8 signext %3, i8 signext %4, i8 signext %5, i32 %6)
%26 = add nsw i32 %18, 8
%27 = add nuw nsw i64 %13, 1
%28 = tail call i32 @strlen(i8* %0)
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %12, label %31
31: ; preds = %12, %7
ret void
}