#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_letter(char *, char, int, int, int, int, int);
int strlen(char *);
void draw_string(char *pixbuf, char input_string[], int xposn, int yposn,
                 int textflags, int image_width, int image_height) {
  int i, string_length, string_left_hand, letter_width = 7;
  switch (textflags) {
  case 1:
    letter_width = 5;
    break;
  case 2:
    letter_width = 9;
    break;
  default:
    letter_width = 7;
    break;
  }
  string_length = strlen(input_string);
  string_left_hand = xposn - ((letter_width * string_length) / 2);
  for (i = 0; i < string_length; i++) {
    draw_letter(pixbuf, input_string[i], string_left_hand + (i * letter_width),
                yposn, textflags, image_width, image_height);
  }
}


x86 assembly (clang, -O0):
<draw_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
movl   $0x7,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x1,%eax
je     116d <draw_string+0x4d>
jmp    115c <draw_string+0x3c>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
je     1179 <draw_string+0x59>
jmp    1185 <draw_string+0x65>
movl   $0x5,-0x30(%rbp)
jmp    118c <draw_string+0x6c>
movl   $0x9,-0x30(%rbp)
jmp    118c <draw_string+0x6c>
movl   $0x7,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%eax
imul   -0x28(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    120e <draw_string+0xee>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%sil
mov    -0x2c(%rbp),%edx
mov    -0x24(%rbp),%eax
imul   -0x30(%rbp),%eax
add    %eax,%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    0x10(%rbp),%eax
movsbl %sil,%esi
mov    %eax,(%rsp)
call   1030 <draw_letter@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11be <draw_string+0x9e>
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    $0x18,%rsp
mov    %r9d,0xc(%rsp)
mov    %r8d,%ebp
mov    %ecx,0x8(%rsp)
mov    %edx,%ebx
mov    %rsi,%r12
mov    %rdi,0x10(%rsp)
xor    %eax,%eax
cmp    $0x2,%r8d
sete   %al
add    %eax,%eax
add    $0x7,%eax
cmp    $0x1,%r8d
mov    $0x5,%r14d
cmovne %eax,%r14d
mov    %rsi,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11c0 <draw_string+0xa0>
mov    %eax,%r15d
imul   %r14d,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
sub    %ecx,%ebx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%r12,%r13,1),%esi
mov    0x50(%rsp),%eax
mov    %eax,(%rsp)
mov    0x10(%rsp),%rdi
mov    %ebx,%edx
mov    0x8(%rsp),%ecx
mov    %ebp,%r8d
mov    0xc(%rsp),%r9d
call   1030 <draw_letter@plt>
add    $0x1,%r13
add    %r14d,%ebx
cmp    %r13,%r15
jne    1190 <draw_string+0x70>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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