#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 Q_GrabCharFromColorString(char const **, char *, int *);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
void CG_ColorStrLastColor(int *lastcolor, const char *s, int byteofs) {
  char c;
  int colorindex;
  const char *end = s + byteofs;
  while (s < end) {
    int gc = Q_GrabCharFromColorString(&s, &c, &colorindex);
    if (gc == 1)
      ;
    else if (gc == 2)
      *lastcolor = colorindex;
    else if (gc == 0)
      break;
    else
      assert(0);
  }
}


x86 assembly (clang, -O0):
<CG_ColorStrLastColor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11b0 <CG_ColorStrLastColor+0x90>
lea    -0x10(%rbp),%rdi
lea    -0x15(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <Q_GrabCharFromColorString@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jne    1173 <CG_ColorStrLastColor+0x53>
jmp    11ab <CG_ColorStrLastColor+0x8b>
cmpl   $0x2,-0x2c(%rbp)
jne    118b <CG_ColorStrLastColor+0x6b>
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    11a6 <CG_ColorStrLastColor+0x86>
cmpl   $0x0,-0x2c(%rbp)
jne    119a <CG_ColorStrLastColor+0x7a>
jmp    11b0 <CG_ColorStrLastColor+0x90>
xor    %edi,%edi
call   1040 <assert@plt>
jmp    11a6 <CG_ColorStrLastColor+0x86>
jmp    11ab <CG_ColorStrLastColor+0x8b>
jmp    1142 <CG_ColorStrLastColor+0x22>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CG_ColorStrLastColor>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,0x8(%rsp)
test   %edx,%edx
jle    1193 <CG_ColorStrLastColor+0x73>
mov    %rsi,%rbx
mov    %rdi,%r14
movslq %edx,%rax
add    %rax,%rbx
lea    0x8(%rsp),%r15
lea    0x3(%rsp),%r12
lea    0x4(%rsp),%r13
jmp    116e <CG_ColorStrLastColor+0x4e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x4(%rsp),%eax
mov    %eax,(%r14)
cmp    %rbx,0x8(%rsp)
jae    1193 <CG_ColorStrLastColor+0x73>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1030 <Q_GrabCharFromColorString@plt>
cmp    $0x1,%eax
je     1167 <CG_ColorStrLastColor+0x47>
cmp    $0x2,%eax
je     1160 <CG_ColorStrLastColor+0x40>
test   %eax,%eax
je     1193 <CG_ColorStrLastColor+0x73>
xor    %edi,%edi
call   1040 <assert@plt>
jmp    1167 <CG_ColorStrLastColor+0x47>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @CG_ColorStrLastColor(i32* nocapture writeonly %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
store i8* %1, i8** %4
%7 = bitcast i32* %6 to i8*
%8 = sext i32 %2 to i64
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %20
11: ; preds = %3, %17
%12 = call i32 @Q_GrabCharFromColorString(i8** %4, i8* %5, i32* %6)
switch i32 %12, label %15 [
i32 1, label %17
i32 2, label %13
i32 0, label %20
]
13: ; preds = %11
%14 = load i32, i32* %6
store i32 %14, i32* %0
br label %17
15: ; preds = %11
%16 = call i32 @assert(i32 0)
br label %17
17: ; preds = %15, %13, %11
%18 = load i8*, i8** %4
%19 = icmp ult i8* %18, %9
br i1 %19, label %11, label %20
20: ; preds = %11, %17, %3
ret void
}