#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_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;
            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   $0x0,-0x3c(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    147b <libirc_colorparser_irc2code+0x32b>
cmpl   $0x0,-0x1c(%rbp)
jbe    11c4 <libirc_colorparser_irc2code+0x74>
mov    -0x1c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11bc <libirc_colorparser_irc2code+0x6c>
movq   $0x0,-0x8(%rbp)
jmp    148a <libirc_colorparser_irc2code+0x33a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     145c <libirc_colorparser_irc2code+0x30c>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
add    $0xfffffffe,%eax
mov    %eax,%ecx
mov    %rcx,-0x50(%rbp)
sub    $0x1d,%eax
ja     1411 <libirc_colorparser_irc2code+0x2c1>
mov    -0x50(%rbp),%rax
lea    0xe03(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x0,-0x14(%rbp)
je     1215 <libirc_colorparser_irc2code+0xc5>
jmp    144b <libirc_colorparser_irc2code+0x2fb>
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x2,%ecx
lea    0xe4b(%rip),%r8
lea    0xe48(%rip),%r9
call   1040 <libirc_colorparser_applymask@plt>
jmp    1446 <libirc_colorparser_irc2code+0x2f6>
cmpl   $0x0,-0x14(%rbp)
je     124d <libirc_colorparser_irc2code+0xfd>
jmp    144b <libirc_colorparser_irc2code+0x2fb>
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x4,%ecx
lea    0xe1c(%rip),%r8
lea    0xe19(%rip),%r9
call   1040 <libirc_colorparser_applymask@plt>
jmp    1446 <libirc_colorparser_irc2code+0x2f6>
cmpl   $0x0,-0x14(%rbp)
je     1285 <libirc_colorparser_irc2code+0x135>
jmp    144b <libirc_colorparser_irc2code+0x2fb>
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x8,%ecx
lea    0xded(%rip),%r8
lea    0xdea(%rip),%r9
call   1040 <libirc_colorparser_applymask@plt>
jmp    1446 <libirc_colorparser_irc2code+0x2f6>
cmpl   $0x0,-0x14(%rbp)
je     12bd <libirc_colorparser_irc2code+0x16d>
jmp    144b <libirc_colorparser_irc2code+0x2fb>
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1070 <libirc_colorparser_closetags@plt>
jmp    1446 <libirc_colorparser_irc2code+0x2f6>
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     140c <libirc_colorparser_irc2code+0x2bc>
movl   $0xffffffff,-0x40(%rbp)
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x44(%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     1340 <libirc_colorparser_irc2code+0x1f0>
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)
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2c,%eax
jne    13bc <libirc_colorparser_irc2code+0x26c>
mov    -0x38(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     13bc <libirc_colorparser_irc2code+0x26c>
mov    -0x38(%rbp),%rax
movsbl 0x2(%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x40(%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     13b7 <libirc_colorparser_irc2code+0x267>
imul   $0xa,-0x40(%rbp),%eax
mov    -0x38(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    13bc <libirc_colorparser_irc2code+0x26c>
cmpl   $0xf,-0x44(%rbp)
jg     1407 <libirc_colorparser_irc2code+0x2b7>
cmpl   $0xf,-0x40(%rbp)
jg     1407 <libirc_colorparser_irc2code+0x2b7>
cmpl   $0x0,-0x14(%rbp)
je     13df <libirc_colorparser_irc2code+0x28f>
jmp    144b <libirc_colorparser_irc2code+0x2fb>
cmpl   $0xffffffff,-0x40(%rbp)
je     13ef <libirc_colorparser_irc2code+0x29f>
mov    -0x40(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x44(%rbp),%ecx
mov    -0x3c(%rbp),%r8d
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <libirc_colorparser_applycolor@plt>
jmp    140c <libirc_colorparser_irc2code+0x2bc>
jmp    1446 <libirc_colorparser_irc2code+0x2f6>
cmpq   $0x0,-0x28(%rbp)
je     1438 <libirc_colorparser_irc2code+0x2e8>
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    1441 <libirc_colorparser_irc2code+0x2f1>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1446 <libirc_colorparser_irc2code+0x2f6>
jmp    144b <libirc_colorparser_irc2code+0x2fb>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11cc <libirc_colorparser_irc2code+0x7c>
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    1184 <libirc_colorparser_irc2code+0x34>
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
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 0, i32* %11
br label %14
14: ; preds = %165, %2
%15 = load i8*, i8** %8
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %169
17: ; preds = %14
%18 = load i32, i32* %7
%19 = icmp ugt i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* %7
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %8
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %20
store i8* null, i8** %3
br label %172
25: ; preds = %20
%26 = load i8*, i8** %8
store i8* %26, i8** %9
br label %27
27: ; preds = %25, %17
%28 = load i8*, i8** %4
store i8* %28, i8** %10
br label %29
29: ; preds = %162, %27
%30 = load i8*, i8** %10
%31 = load i8, i8* %30
%32 = icmp ne i8 %31, 0
br i1 %32, label %33, label %165
33: ; preds = %29
%34 = load i8*, i8** %10
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
switch i32 %36, label %149 [
i32 2, label %37
i32 31, label %43
i32 22, label %49
i32 15, label %55
i32 3, label %61
]
37: ; preds = %33
%38 = load i32, i32* %5
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %37
br label %162
41: ; preds = %37
%42 = 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 %161
43: ; preds = %33
%44 = load i32, i32* %5
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %43
br label %162
47: ; preds = %43
%48 = 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 %161
49: ; preds = %33
%50 = load i32, i32* %5
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %49
br label %162
53: ; preds = %49
%54 = 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 %161
55: ; preds = %33
%56 = load i32, i32* %5
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %55
br label %162
59: ; preds = %55
%60 = call i32 @libirc_colorparser_closetags(i32* %6, i8** %9, i32* %7)
br label %161
61: ; preds = %33
%62 = load i8*, i8** %10
%63 = getelementptr inbounds i8, i8* %62, i64 1
%64 = load i8, i8* %63
%65 = call i32 @isdigit(i8 signext %64)
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %148
67: ; preds = %61
store i32 -1, i32* %12
%68 = load i8*, i8** %10
%69 = getelementptr inbounds i8, i8* %68, i64 1
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = sub nsw i32 %71, 48
store i32 %72, i32* %13
%73 = load i8*, i8** %10
%74 = getelementptr inbounds i8, i8* %73, i32 1
store i8* %74, i8** %10
%75 = load i8*, i8** %10
%76 = getelementptr inbounds i8, i8* %75, i64 1
%77 = load i8, i8* %76
%78 = call i32 @isdigit(i8 signext %77)
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %91
80: ; preds = %67
%81 = load i32, i32* %13
%82 = mul nsw i32 %81, 10
%83 = load i8*, i8** %10
%84 = getelementptr inbounds i8, i8* %83, i64 1
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = sub nsw i32 %86, 48
%88 = add nsw i32 %82, %87
store i32 %88, i32* %13
%89 = load i8*, i8** %10
%90 = getelementptr inbounds i8, i8* %89, i32 1
store i8* %90, i8** %10
br label %91
91: ; preds = %80, %67
%92 = load i8*, i8** %10
%93 = getelementptr inbounds i8, i8* %92, i64 1
%94 = load i8, i8* %93
%95 = sext i8 %94 to i32
%96 = icmp eq i32 %95, 44
br i1 %96, label %97, label %128
97: ; preds = %91
%98 = load i8*, i8** %10
%99 = getelementptr inbounds i8, i8* %98, i64 2
%100 = load i8, i8* %99
%101 = call i32 @isdigit(i8 signext %100)
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %128
103: ; preds = %97
%104 = load i8*, i8** %10
%105 = getelementptr inbounds i8, i8* %104, i64 2
%106 = load i8, i8* %105
%107 = sext i8 %106 to i32
%108 = sub nsw i32 %107, 48
store i32 %108, i32* %12
%109 = load i8*, i8** %10
%110 = getelementptr inbounds i8, i8* %109, i64 2
store i8* %110, i8** %10
%111 = load i8*, i8** %10
%112 = getelementptr inbounds i8, i8* %111, i64 1
%113 = load i8, i8* %112
%114 = call i32 @isdigit(i8 signext %113)
%115 = icmp ne i32 %114, 0
br i1 %115, label %116, label %127
116: ; preds = %103
%117 = load i32, i32* %12
%118 = mul nsw i32 %117, 10
%119 = load i8*, i8** %10
%120 = getelementptr inbounds i8, i8* %119, i64 1
%121 = load i8, i8* %120
%122 = sext i8 %121 to i32
%123 = sub nsw i32 %122, 48
%124 = add nsw i32 %118, %123
store i32 %124, i32* %12
%125 = load i8*, i8** %10
%126 = getelementptr inbounds i8, i8* %125, i32 1
store i8* %126, i8** %10
br label %127
127: ; preds = %116, %103
br label %128
128: ; preds = %127, %97, %91
%129 = load i32, i32* %13
%130 = icmp sle i32 %129, 15
br i1 %130, label %131, label %147
131: ; preds = %128
%132 = load i32, i32* %12
%133 = icmp sle i32 %132, 15
br i1 %133, label %134, label %147
134: ; preds = %131
%135 = load i32, i32* %5
%136 = icmp ne i32 %135, 0
br i1 %136, label %137, label %138
137: ; preds = %134
br label %162
138: ; preds = %134
%139 = load i32, i32* %12
%140 = icmp ne i32 %139, -1
br i1 %140, label %141, label %143
141: ; preds = %138
%142 = load i32, i32* %12
store i32 %142, i32* %11
br label %143
143: ; preds = %141, %138
%144 = load i32, i32* %13
%145 = load i32, i32* %11
%146 = call i32 @libirc_colorparser_applycolor(i32* %6, i8** %9, i32* %7, i32 %144, i32 %145)
br label %147
147: ; preds = %143, %131, %128
br label %148
148: ; preds = %147, %61
br label %161
149: ; preds = %33
%150 = load i8*, i8** %8
%151 = icmp ne i8* %150, null
br i1 %151, label %152, label %157
152: ; preds = %149
%153 = load i8*, i8** %10
%154 = load i8, i8* %153
%155 = load i8*, i8** %9
%156 = getelementptr inbounds i8, i8* %155, i32 1
store i8* %156, i8** %9
store i8 %154, i8* %155
br label %160
157: ; preds = %149
%158 = load i32, i32* %7
%159 = add i32 %158, 1
store i32 %159, i32* %7
br label %160
160: ; preds = %157, %152
br label %161
161: ; preds = %160, %148, %59, %53, %47, %41
br label %162
162: ; preds = %161, %137, %58, %52, %46, %40
%163 = load i8*, i8** %10
%164 = getelementptr inbounds i8, i8* %163, i32 1
store i8* %164, i8** %10
br label %29
165: ; preds = %29
%166 = call i32 @libirc_colorparser_closetags(i32* %6, i8** %9, i32* %7)
%167 = load i32, i32* %7
%168 = add i32 %167, 1
store i32 %168, i32* %7
br label %14
169: ; preds = %14
%170 = load i8*, i8** %9
store i8 0, i8* %170
%171 = load i8*, i8** %8
store i8* %171, i8** %3
br label %172
172: ; preds = %169, %24
%173 = load i8*, i8** %3
ret i8* %173
}

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
}