#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*/ isdigit(char const);
int /*<<< orphan*/ libirc_colorparser_applycolor(unsigned int *, char **,
                                                 unsigned int *, int, int);
int /*<<< orphan*/ libirc_colorparser_applymask(unsigned int *, char **,
                                                unsigned int *, int, char *,
                                                char *);
int /*<<< orphan*/ libirc_colorparser_closetags(unsigned int *, char **,
                                                unsigned int *);
char *malloc(unsigned int);
char *libirc_colorparser_irc2code(const char *source, int strip) {
  unsigned int mask = 0, destlen = 0;
  char *destline = 0, *d = 0;
  const char *p;
  int current_color = 1, current_bg = 0;
  while (destline == 0) {
    if (destlen > 0) {
      if ((destline = malloc(destlen)) == 0)
        return 0;
      d = destline;
    }
    for (p = source; *p; p++) {
      switch (*p) {
      case 0x02:
        if (strip)
          continue;
        libirc_colorparser_applymask(&mask, &d, &destlen, (1 << 1), "[B]",
                                     "[/B]");
        break;
      case 0x1F:
        if (strip)
          continue;
        libirc_colorparser_applymask(&mask, &d, &destlen, (1 << 2), "[U]",
                                     "[/U]");
        break;
      case 0x16:
        if (strip)
          continue;
        libirc_colorparser_applymask(&mask, &d, &destlen, (1 << 3), "[I]",
                                     "[/I]");
        break;
      case 0x0F:
        if (strip)
          continue;
        libirc_colorparser_closetags(&mask, &d, &destlen);
        break;
      case 0x03:
        if (isdigit(p[1])) {
          int bgcolor = -1, color = p[1] - 0x30;
          p++;
          if (isdigit(p[1])) {
            color = color * 10 + (p[1] - 0x30);
            p++;
          }
          if (p[1] == ',' && isdigit(p[2])) {
            bgcolor = p[2] - 0x30;
            p += 2;
            if (isdigit(p[1])) {
              bgcolor = bgcolor * 10 + (p[1] - 0x30);
              p++;
            }
          }
          if (color <= 15 && bgcolor <= 15) {
            if (strip)
              continue;
            current_color = color;
            if (bgcolor != -1)
              current_bg = bgcolor;
            libirc_colorparser_applycolor(&mask, &d, &destlen, color,
                                          current_bg);
          }
        }
        break;
      default:
        if (destline)
          *d++ = *p;
        else
          destlen++;
        break;
      }
    }
    libirc_colorparser_closetags(&mask, &d, &destlen);
    destlen++;
  }
  *d = '\0';
  return destline;
}


x86 assembly (clang, -O0):
<libirc_colorparser_irc2code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x1,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1488 <libirc_colorparser_irc2code+0x338>
cmpl   $0x0,-0x1c(%rbp)
jbe    11cb <libirc_colorparser_irc2code+0x7b>
mov    -0x1c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11c3 <libirc_colorparser_irc2code+0x73>
movq   $0x0,-0x8(%rbp)
jmp    1497 <libirc_colorparser_irc2code+0x347>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     1469 <libirc_colorparser_irc2code+0x319>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
add    $0xfffffffe,%eax
mov    %eax,%ecx
mov    %rcx,-0x50(%rbp)
sub    $0x1d,%eax
ja     141e <libirc_colorparser_irc2code+0x2ce>
mov    -0x50(%rbp),%rax
lea    0xdfc(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x0,-0x14(%rbp)
je     121c <libirc_colorparser_irc2code+0xcc>
jmp    1458 <libirc_colorparser_irc2code+0x308>
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x2,%ecx
lea    0xe44(%rip),%r8
lea    0xe41(%rip),%r9
call   1040 <libirc_colorparser_applymask@plt>
jmp    1453 <libirc_colorparser_irc2code+0x303>
cmpl   $0x0,-0x14(%rbp)
je     1254 <libirc_colorparser_irc2code+0x104>
jmp    1458 <libirc_colorparser_irc2code+0x308>
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x4,%ecx
lea    0xe15(%rip),%r8
lea    0xe12(%rip),%r9
call   1040 <libirc_colorparser_applymask@plt>
jmp    1453 <libirc_colorparser_irc2code+0x303>
cmpl   $0x0,-0x14(%rbp)
je     128c <libirc_colorparser_irc2code+0x13c>
jmp    1458 <libirc_colorparser_irc2code+0x308>
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x8,%ecx
lea    0xde6(%rip),%r8
lea    0xde3(%rip),%r9
call   1040 <libirc_colorparser_applymask@plt>
jmp    1453 <libirc_colorparser_irc2code+0x303>
cmpl   $0x0,-0x14(%rbp)
je     12c4 <libirc_colorparser_irc2code+0x174>
jmp    1458 <libirc_colorparser_irc2code+0x308>
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1070 <libirc_colorparser_closetags@plt>
jmp    1453 <libirc_colorparser_irc2code+0x303>
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     1419 <libirc_colorparser_irc2code+0x2c9>
movl   $0xffffffff,-0x44(%rbp)
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     1347 <libirc_colorparser_irc2code+0x1f7>
imul   $0xa,-0x48(%rbp),%eax
mov    -0x38(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2c,%eax
jne    13c3 <libirc_colorparser_irc2code+0x273>
mov    -0x38(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     13c3 <libirc_colorparser_irc2code+0x273>
mov    -0x38(%rbp),%rax
movsbl 0x2(%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     13be <libirc_colorparser_irc2code+0x26e>
imul   $0xa,-0x44(%rbp),%eax
mov    -0x38(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    13c3 <libirc_colorparser_irc2code+0x273>
cmpl   $0xf,-0x48(%rbp)
jg     1414 <libirc_colorparser_irc2code+0x2c4>
cmpl   $0xf,-0x44(%rbp)
jg     1414 <libirc_colorparser_irc2code+0x2c4>
cmpl   $0x0,-0x14(%rbp)
je     13e6 <libirc_colorparser_irc2code+0x296>
jmp    1458 <libirc_colorparser_irc2code+0x308>
mov    -0x48(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
je     13fc <libirc_colorparser_irc2code+0x2ac>
mov    -0x44(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x48(%rbp),%ecx
mov    -0x40(%rbp),%r8d
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <libirc_colorparser_applycolor@plt>
jmp    1419 <libirc_colorparser_irc2code+0x2c9>
jmp    1453 <libirc_colorparser_irc2code+0x303>
cmpq   $0x0,-0x28(%rbp)
je     1445 <libirc_colorparser_irc2code+0x2f5>
mov    -0x38(%rbp),%rax
mov    (%rax),%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
jmp    144e <libirc_colorparser_irc2code+0x2fe>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1453 <libirc_colorparser_irc2code+0x303>
jmp    1458 <libirc_colorparser_irc2code+0x308>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11d3 <libirc_colorparser_irc2code+0x83>
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1070 <libirc_colorparser_closetags@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118b <libirc_colorparser_irc2code+0x3b>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libirc_colorparser_irc2code>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %rdi,%r12
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xc(%rsp),%r13
lea    0xe78(%rip),%r15
xor    %edi,%edi
movl   $0x0,0x1c(%rsp)
mov    %r12,0x20(%rsp)
jmp    11cb <libirc_colorparser_irc2code+0x7b>
nopl   0x0(%rax)
mov    %r13,%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1070 <libirc_colorparser_closetags@plt>
mov    0x8(%rsp),%edi
add    $0x1,%edi
mov    %edi,0x8(%rsp)
test   %r14,%r14
mov    0x20(%rsp),%r12
jne    13d2 <libirc_colorparser_irc2code+0x282>
test   %edi,%edi
je     11f0 <libirc_colorparser_irc2code+0xa0>
call   1060 <malloc@plt>
test   %rax,%rax
je     13dc <libirc_colorparser_irc2code+0x28c>
mov    %rax,%r14
mov    %rax,0x10(%rsp)
jmp    11f3 <libirc_colorparser_irc2code+0xa3>
nopw   0x0(%rax,%rax,1)
xor    %r14d,%r14d
mov    (%r12),%al
jmp    120a <libirc_colorparser_irc2code+0xba>
addl   $0x1,0x8(%rsp)
xchg   %ax,%ax
movzbl 0x1(%r12),%eax
add    $0x1,%r12
test   %al,%al
je     11a0 <libirc_colorparser_irc2code+0x50>
movsbl %al,%ecx
add    $0xfffffffe,%ecx
cmp    $0x1d,%ecx
ja     1290 <libirc_colorparser_irc2code+0x140>
movslq (%r15,%rcx,4),%rcx
add    %r15,%rcx
jmp    *%rcx
test   %ebx,%ebx
jne    1200 <libirc_colorparser_irc2code+0xb0>
mov    %r13,%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    $0x2,%ecx
lea    0xe39(%rip),%r8
lea    0xe36(%rip),%r9
call   1040 <libirc_colorparser_applymask@plt>
jmp    1200 <libirc_colorparser_irc2code+0xb0>
movsbl 0x1(%r12),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1200 <libirc_colorparser_irc2code+0xb0>
movsbl 0x1(%r12),%ebp
add    $0xffffffd0,%ebp
movsbl 0x2(%r12),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1331 <libirc_colorparser_irc2code+0x1e1>
add    $0x2,%r12
lea    0x0(%rbp,%rbp,4),%eax
movsbl (%r12),%ecx
lea    (%rcx,%rax,2),%ebp
add    $0xffffffd0,%ebp
jmp    1335 <libirc_colorparser_irc2code+0x1e5>
test   %r14,%r14
je     11f9 <libirc_colorparser_irc2code+0xa9>
mov    0x10(%rsp),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,0x10(%rsp)
mov    %al,(%rcx)
jmp    1200 <libirc_colorparser_irc2code+0xb0>
test   %ebx,%ebx
jne    1200 <libirc_colorparser_irc2code+0xb0>
mov    %r13,%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1070 <libirc_colorparser_closetags@plt>
jmp    1200 <libirc_colorparser_irc2code+0xb0>
test   %ebx,%ebx
jne    1200 <libirc_colorparser_irc2code+0xb0>
mov    %r13,%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    $0x8,%ecx
lea    0xd9c(%rip),%r8
lea    0xd99(%rip),%r9
call   1040 <libirc_colorparser_applymask@plt>
jmp    1200 <libirc_colorparser_irc2code+0xb0>
test   %ebx,%ebx
jne    1200 <libirc_colorparser_irc2code+0xb0>
mov    %r13,%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    $0x4,%ecx
lea    0xd61(%rip),%r8
lea    0xd5e(%rip),%r9
call   1040 <libirc_colorparser_applymask@plt>
jmp    1200 <libirc_colorparser_irc2code+0xb0>
add    $0x1,%r12
mov    $0xffffffff,%r13d
cmpb   $0x2c,0x1(%r12)
jne    1381 <libirc_colorparser_irc2code+0x231>
movsbl 0x2(%r12),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1381 <libirc_colorparser_irc2code+0x231>
movsbl 0x2(%r12),%r13d
add    $0xffffffd0,%r13d
movsbl 0x3(%r12),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     13c0 <libirc_colorparser_irc2code+0x270>
add    $0x3,%r12
lea    0x0(%r13,%r13,4),%eax
movsbl (%r12),%ecx
lea    (%rcx,%rax,2),%r13d
add    $0xffffffd0,%r13d
test   %ebx,%ebx
jne    13c8 <libirc_colorparser_irc2code+0x278>
cmp    $0xf,%ebp
jg     13c8 <libirc_colorparser_irc2code+0x278>
cmp    $0xf,%r13d
jg     13c8 <libirc_colorparser_irc2code+0x278>
cmp    $0xffffffff,%r13d
mov    0x1c(%rsp),%r8d
cmovne %r13d,%r8d
lea    0xc(%rsp),%r13
mov    %r13,%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebp,%ecx
mov    %r8d,0x1c(%rsp)
call   1050 <libirc_colorparser_applycolor@plt>
jmp    1200 <libirc_colorparser_irc2code+0xb0>
add    $0x2,%r12
test   %ebx,%ebx
je     1385 <libirc_colorparser_irc2code+0x235>
lea    0xc(%rsp),%r13
jmp    1200 <libirc_colorparser_irc2code+0xb0>
mov    0x10(%rsp),%rax
movb   $0x0,(%rax)
jmp    13df <libirc_colorparser_irc2code+0x28f>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"[B]\00"
@.str.1 = [5 x i8] c"[/B]\00"
@.str.2 = [4 x i8] c"[U]\00"
@.str.3 = [5 x i8] c"[/U]\00"
@.str.4 = [4 x i8] c"[I]\00"
@.str.5 = [5 x i8] c"[/I]\00"
define i8* @libirc_colorparser_irc2code(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i8* null, i8** %8
store i8* null, i8** %9
store i32 1, i32* %11
store i32 0, i32* %12
br label %15
15: ; preds = %167, %2
%16 = load i8*, i8** %8
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %171
18: ; preds = %15
%19 = load i32, i32* %7
%20 = icmp ugt i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* %7
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %8
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %21
store i8* null, i8** %3
br label %174
26: ; preds = %21
%27 = load i8*, i8** %8
store i8* %27, i8** %9
br label %28
28: ; preds = %26, %18
%29 = load i8*, i8** %4
store i8* %29, i8** %10
br label %30
30: ; preds = %164, %28
%31 = load i8*, i8** %10
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
br i1 %33, label %34, label %167
34: ; preds = %30
%35 = load i8*, i8** %10
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
switch i32 %37, label %151 [
i32 2, label %38
i32 31, label %44
i32 22, label %50
i32 15, label %56
i32 3, label %62
]
38: ; preds = %34
%39 = load i32, i32* %5
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %38
br label %164
42: ; preds = %38
%43 = call i32 @libirc_colorparser_applymask(i32* %6, i8** %9, i32* %7, i32 2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %163
44: ; preds = %34
%45 = load i32, i32* %5
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %44
br label %164
48: ; preds = %44
%49 = call i32 @libirc_colorparser_applymask(i32* %6, i8** %9, i32* %7, i32 4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %163
50: ; preds = %34
%51 = load i32, i32* %5
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %50
br label %164
54: ; preds = %50
%55 = call i32 @libirc_colorparser_applymask(i32* %6, i8** %9, i32* %7, i32 8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %163
56: ; preds = %34
%57 = load i32, i32* %5
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %56
br label %164
60: ; preds = %56
%61 = call i32 @libirc_colorparser_closetags(i32* %6, i8** %9, i32* %7)
br label %163
62: ; preds = %34
%63 = load i8*, i8** %10
%64 = getelementptr inbounds i8, i8* %63, i64 1
%65 = load i8, i8* %64
%66 = call i32 @isdigit(i8 signext %65)
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %150
68: ; preds = %62
store i32 -1, i32* %13
%69 = load i8*, i8** %10
%70 = getelementptr inbounds i8, i8* %69, i64 1
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = sub nsw i32 %72, 48
store i32 %73, i32* %14
%74 = load i8*, i8** %10
%75 = getelementptr inbounds i8, i8* %74, i32 1
store i8* %75, i8** %10
%76 = load i8*, i8** %10
%77 = getelementptr inbounds i8, i8* %76, i64 1
%78 = load i8, i8* %77
%79 = call i32 @isdigit(i8 signext %78)
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %92
81: ; preds = %68
%82 = load i32, i32* %14
%83 = mul nsw i32 %82, 10
%84 = load i8*, i8** %10
%85 = getelementptr inbounds i8, i8* %84, i64 1
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = sub nsw i32 %87, 48
%89 = add nsw i32 %83, %88
store i32 %89, i32* %14
%90 = load i8*, i8** %10
%91 = getelementptr inbounds i8, i8* %90, i32 1
store i8* %91, i8** %10
br label %92
92: ; preds = %81, %68
%93 = load i8*, i8** %10
%94 = getelementptr inbounds i8, i8* %93, i64 1
%95 = load i8, i8* %94
%96 = sext i8 %95 to i32
%97 = icmp eq i32 %96, 44
br i1 %97, label %98, label %129
98: ; preds = %92
%99 = load i8*, i8** %10
%100 = getelementptr inbounds i8, i8* %99, i64 2
%101 = load i8, i8* %100
%102 = call i32 @isdigit(i8 signext %101)
%103 = icmp ne i32 %102, 0
br i1 %103, label %104, label %129
104: ; preds = %98
%105 = load i8*, i8** %10
%106 = getelementptr inbounds i8, i8* %105, i64 2
%107 = load i8, i8* %106
%108 = sext i8 %107 to i32
%109 = sub nsw i32 %108, 48
store i32 %109, i32* %13
%110 = load i8*, i8** %10
%111 = getelementptr inbounds i8, i8* %110, i64 2
store i8* %111, i8** %10
%112 = load i8*, i8** %10
%113 = getelementptr inbounds i8, i8* %112, i64 1
%114 = load i8, i8* %113
%115 = call i32 @isdigit(i8 signext %114)
%116 = icmp ne i32 %115, 0
br i1 %116, label %117, label %128
117: ; preds = %104
%118 = load i32, i32* %13
%119 = mul nsw i32 %118, 10
%120 = load i8*, i8** %10
%121 = getelementptr inbounds i8, i8* %120, i64 1
%122 = load i8, i8* %121
%123 = sext i8 %122 to i32
%124 = sub nsw i32 %123, 48
%125 = add nsw i32 %119, %124
store i32 %125, i32* %13
%126 = load i8*, i8** %10
%127 = getelementptr inbounds i8, i8* %126, i32 1
store i8* %127, i8** %10
br label %128
128: ; preds = %117, %104
br label %129
129: ; preds = %128, %98, %92
%130 = load i32, i32* %14
%131 = icmp sle i32 %130, 15
br i1 %131, label %132, label %149
132: ; preds = %129
%133 = load i32, i32* %13
%134 = icmp sle i32 %133, 15
br i1 %134, label %135, label %149
135: ; preds = %132
%136 = load i32, i32* %5
%137 = icmp ne i32 %136, 0
br i1 %137, label %138, label %139
138: ; preds = %135
br label %164
139: ; preds = %135
%140 = load i32, i32* %14
store i32 %140, i32* %11
%141 = load i32, i32* %13
%142 = icmp ne i32 %141, -1
br i1 %142, label %143, label %145
143: ; preds = %139
%144 = load i32, i32* %13
store i32 %144, i32* %12
br label %145
145: ; preds = %143, %139
%146 = load i32, i32* %14
%147 = load i32, i32* %12
%148 = call i32 @libirc_colorparser_applycolor(i32* %6, i8** %9, i32* %7, i32 %146, i32 %147)
br label %149
149: ; preds = %145, %132, %129
br label %150
150: ; preds = %149, %62
br label %163
151: ; preds = %34
%152 = load i8*, i8** %8
%153 = icmp ne i8* %152, null
br i1 %153, label %154, label %159
154: ; preds = %151
%155 = load i8*, i8** %10
%156 = load i8, i8* %155
%157 = load i8*, i8** %9
%158 = getelementptr inbounds i8, i8* %157, i32 1
store i8* %158, i8** %9
store i8 %156, i8* %157
br label %162
159: ; preds = %151
%160 = load i32, i32* %7
%161 = add i32 %160, 1
store i32 %161, i32* %7
br label %162
162: ; preds = %159, %154
br label %163
163: ; preds = %162, %150, %60, %54, %48, %42
br label %164
164: ; preds = %163, %138, %59, %53, %47, %41
%165 = load i8*, i8** %10
%166 = getelementptr inbounds i8, i8* %165, i32 1
store i8* %166, i8** %10
br label %30
167: ; preds = %30
%168 = call i32 @libirc_colorparser_closetags(i32* %6, i8** %9, i32* %7)
%169 = load i32, i32* %7
%170 = add i32 %169, 1
store i32 %170, i32* %7
br label %15
171: ; preds = %15
%172 = load i8*, i8** %9
store i8 0, i8* %172
%173 = load i8*, i8** %8
store i8* %173, i8** %3
br label %174
174: ; preds = %171, %25
%175 = load i8*, i8** %3
ret i8* %175
}

LLVM IR (-O2):
@.str = [4 x i8] c"[B]\00"
@.str.1 = [5 x i8] c"[/B]\00"
@.str.2 = [4 x i8] c"[U]\00"
@.str.3 = [5 x i8] c"[/U]\00"
@.str.4 = [4 x i8] c"[I]\00"
@.str.5 = [5 x i8] c"[/I]\00"
define i8* @libirc_colorparser_irc2code(i8* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%8 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%9 = icmp eq i32 %1, 0
br label %10
10: ; preds = %2, %109
%11 = phi i32 [ 0, %2 ], [ %113, %109 ]
%12 = phi i32 [ 0, %2 ], [ %110, %109 ]
%13 = icmp eq i32 %11, 0
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = call i8* @malloc(i32 %11)
%16 = icmp eq i8* %15, null
br i1 %16, label %117, label %17
17: ; preds = %14
store i8* %15, i8** %5
br label %18
18: ; preds = %17, %10
%19 = phi i8* [ %15, %17 ], [ null, %10 ]
%20 = load i8, i8* %0
%21 = icmp eq i8 %20, 0
br i1 %21, label %109, label %22
22: ; preds = %18
%23 = icmp eq i8* %19, null
br label %24
24: ; preds = %22, %103
%25 = phi i8 [ %20, %22 ], [ %107, %103 ]
%26 = phi i32 [ %12, %22 ], [ %105, %103 ]
%27 = phi i8* [ %0, %22 ], [ %106, %103 ]
%28 = sext i8 %25 to i32
switch i32 %28, label %96 [
i32 2, label %29
i32 31, label %32
i32 22, label %35
i32 15, label %38
i32 3, label %41
]
29: ; preds = %24
br i1 %9, label %30, label %103
30: ; preds = %29
%31 = call i32 @libirc_colorparser_applymask(i32* %3, i8** %5, i32* %4, i32 2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %103
32: ; preds = %24
br i1 %9, label %33, label %103
33: ; preds = %32
%34 = call i32 @libirc_colorparser_applymask(i32* %3, i8** %5, i32* %4, i32 4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %103
35: ; preds = %24
br i1 %9, label %36, label %103
36: ; preds = %35
%37 = call i32 @libirc_colorparser_applymask(i32* %3, i8** %5, i32* %4, i32 8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %103
38: ; preds = %24
br i1 %9, label %39, label %103
39: ; preds = %38
%40 = call i32 @libirc_colorparser_closetags(i32* %3, i8** %5, i32* %4)
br label %103
41: ; preds = %24
%42 = getelementptr inbounds i8, i8* %27, i64 1
%43 = load i8, i8* %42
%44 = call i32 @isdigit(i8 signext %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %103, label %46
46: ; preds = %41
%47 = load i8, i8* %42
%48 = sext i8 %47 to i32
%49 = add nsw i32 %48, -48
%50 = getelementptr inbounds i8, i8* %27, i64 2
%51 = load i8, i8* %50
%52 = call i32 @isdigit(i8 signext %51)
%53 = icmp eq i32 %52, 0
br i1 %53, label %60, label %54
54: ; preds = %46
%55 = mul nsw i32 %49, 10
%56 = load i8, i8* %50
%57 = sext i8 %56 to i32
%58 = add nsw i32 %55, -48
%59 = add nsw i32 %58, %57
br label %60
60: ; preds = %54, %46
%61 = phi i8* [ %50, %54 ], [ %42, %46 ]
%62 = phi i32 [ %59, %54 ], [ %49, %46 ]
%63 = getelementptr inbounds i8, i8* %61, i64 1
%64 = load i8, i8* %63
%65 = icmp eq i8 %64, 44
br i1 %65, label %66, label %85
66: ; preds = %60
%67 = getelementptr inbounds i8, i8* %61, i64 2
%68 = load i8, i8* %67
%69 = call i32 @isdigit(i8 signext %68)
%70 = icmp eq i32 %69, 0
br i1 %70, label %85, label %71
71: ; preds = %66
%72 = load i8, i8* %67
%73 = sext i8 %72 to i32
%74 = add nsw i32 %73, -48
%75 = getelementptr inbounds i8, i8* %61, i64 3
%76 = load i8, i8* %75
%77 = call i32 @isdigit(i8 signext %76)
%78 = icmp eq i32 %77, 0
br i1 %78, label %85, label %79
79: ; preds = %71
%80 = mul nsw i32 %74, 10
%81 = load i8, i8* %75
%82 = sext i8 %81 to i32
%83 = add nsw i32 %80, -48
%84 = add nsw i32 %83, %82
br label %85
85: ; preds = %71, %79, %66, %60
%86 = phi i8* [ %75, %79 ], [ %67, %71 ], [ %61, %66 ], [ %61, %60 ]
%87 = phi i32 [ %84, %79 ], [ %74, %71 ], [ -1, %66 ], [ -1, %60 ]
%88 = icmp slt i32 %62, 16
%89 = icmp slt i32 %87, 16
%90 = select i1 %88, i1 %89, i1 false
%91 = and i1 %9, %90
br i1 %91, label %92, label %103
92: ; preds = %85
%93 = icmp eq i32 %87, -1
%94 = select i1 %93, i32 %26, i32 %87
%95 = call i32 @libirc_colorparser_applycolor(i32* %3, i8** %5, i32* %4, i32 %62, i32 %94)
br label %103
96: ; preds = %24
br i1 %23, label %100, label %97
97: ; preds = %96
%98 = load i8*, i8** %5
%99 = getelementptr inbounds i8, i8* %98, i64 1
store i8* %99, i8** %5
store i8 %25, i8* %98
br label %103
100: ; preds = %96
%101 = load i32, i32* %4
%102 = add i32 %101, 1
store i32 %102, i32* %4
br label %103
103: ; preds = %92, %85, %30, %33, %36, %39, %41, %100, %97, %38, %35, %32, %29
%104 = phi i8* [ %27, %97 ], [ %27, %100 ], [ %27, %41 ], [ %27, %38 ], [ %27, %39 ], [ %27, %35 ], [ %27, %36 ], [ %27, %32 ], [ %27, %33 ], [ %27, %29 ], [ %27, %30 ], [ %86, %85 ], [ %86, %92 ]
%105 = phi i32 [ %26, %97 ], [ %26, %100 ], [ %26, %41 ], [ %26, %38 ], [ %26, %39 ], [ %26, %35 ], [ %26, %36 ], [ %26, %32 ], [ %26, %33 ], [ %26, %29 ], [ %26, %30 ], [ %26, %85 ], [ %94, %92 ]
%106 = getelementptr inbounds i8, i8* %104, i64 1
%107 = load i8, i8* %106
%108 = icmp eq i8 %107, 0
br i1 %108, label %109, label %24
109: ; preds = %103, %18
%110 = phi i32 [ %12, %18 ], [ %105, %103 ]
%111 = call i32 @libirc_colorparser_closetags(i32* %3, i8** %5, i32* %4)
%112 = load i32, i32* %4
%113 = add i32 %112, 1
store i32 %113, i32* %4
%114 = icmp eq i8* %19, null
br i1 %114, label %10, label %115
115: ; preds = %109
%116 = load i8*, i8** %5
store i8 0, i8* %116
br label %117
117: ; preds = %14, %115
%118 = phi i8* [ %19, %115 ], [ null, %14 ]
ret i8* %118
}