#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 */
typedef scalar_t__ uint32_t;
typedef int uint16_t;
typedef int /*<<< orphan*/ int16_t;

/* Variables and functions */
int /*<<< orphan*/ ST7735_DrawCharS(int, int, char, int /*<<< orphan*/,
                                    int /*<<< orphan*/, int);
uint32_t ST7735_DrawString(uint16_t x, uint16_t y, char *pt, int16_t textColor,
                           int16_t bgColor) {
  uint32_t count = 0;
  if (y > 15)
    return 0;
  while (*pt) {
    ST7735_DrawCharS(x * 6, y * 10, *pt, textColor, bgColor, 1);
    pt++;
    x = x + 1;
    if (x > 20)
      return count;
    count++;
  }
  return count;
}


x86 assembly (clang, -O0):
<ST7735_DrawString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0xf,-0x10(%rbp)
jle    1148 <ST7735_DrawString+0x38>
movq   $0x0,-0x8(%rbp)
jmp    11c2 <ST7735_DrawString+0xb2>
jmp    114d <ST7735_DrawString+0x3d>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ba <ST7735_DrawString+0xaa>
imul   $0x6,-0xc(%rbp),%edi
imul   $0xa,-0x10(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    $0x1,%r9d
movsbl %al,%edx
call   1030 <ST7735_DrawCharS@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x14,-0xc(%rbp)
jle    11a9 <ST7735_DrawString+0x99>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c2 <ST7735_DrawString+0xb2>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    114d <ST7735_DrawString+0x3d>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ST7735_DrawString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,0x4(%rsp)
cmp    $0xf,%esi
jg     1183 <ST7735_DrawString+0x73>
mov    %rdx,%r13
mov    (%rdx),%al
test   %al,%al
je     1183 <ST7735_DrawString+0x73>
mov    %ecx,%r15d
add    %esi,%esi
lea    (%rsi,%rsi,4),%r12d
cmp    $0x15,%edi
mov    $0x14,%r14d
cmovge %edi,%r14d
sub    %edi,%r14d
add    %edi,%edi
lea    (%rdi,%rdi,2),%ebx
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl %al,%edx
mov    %ebx,%edi
mov    %r12d,%esi
mov    %r15d,%ecx
mov    0x4(%rsp),%r8d
mov    $0x1,%r9d
call   1030 <ST7735_DrawCharS@plt>
cmp    %rbp,%r14
je     1187 <ST7735_DrawString+0x77>
movzbl 0x1(%r13,%rbp,1),%eax
add    $0x1,%rbp
add    $0x6,%ebx
test   %al,%al
jne    1150 <ST7735_DrawString+0x40>
jmp    118a <ST7735_DrawString+0x7a>
xor    %ebp,%ebp
jmp    118a <ST7735_DrawString+0x7a>
mov    %r14,%rbp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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