#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*/ libirc_colorparser_addorcat(char **, unsigned int *,
                                               char const *);
int libirc_colorparser_colorlookup(char *);
char *malloc(unsigned int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ sprintf(char *, char *, int, ...);
void *strchr(char const *, char);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char const *);
char *strstr(char *, char *);
char *irc_color_convert_to_mirc(const char *source) {
  unsigned int destlen = 0;
  char *destline = 0, *d = 0;
  const char *p1, *p2, *cur;
  while (destline == 0) {
    if (destlen > 0) {
      if ((destline = malloc(destlen)) == 0)
        return 0;
      d = destline;
    }
    cur = source;
    while ((p1 = strchr(cur, '[')) != 0) {
      const char *replacedval = 0;
      p2 = 0;
      if (p1[1] != '\0' && (p2 = strchr(p1, ']')) != 0 && (p2 - p1) > 1 &&
          (p2 - p1) < 31) {
        char tagbuf[32];
        int taglen = p2 - p1 - 1;
        memcpy(tagbuf, p1 + 1, taglen);
        tagbuf[taglen] = '\0';
        if (!strcmp(tagbuf, "/COLOR"))
          replacedval = "\x0F";
        else if (strstr(tagbuf, "COLOR=") == tagbuf) {
          int color, bgcolor = -2;
          char *bcol;
          bcol = strchr(tagbuf + 6, '/');
          if (bcol) {
            *bcol++ = '\0';
            bgcolor = libirc_colorparser_colorlookup(bcol);
          }
          color = libirc_colorparser_colorlookup(tagbuf + 6);
          if (color != -1 && bgcolor == -2) {
            sprintf(tagbuf, "\x03%02d", color);
            replacedval = tagbuf;
          } else if (color != -1 && bgcolor >= 0) {
            sprintf(tagbuf, "\x03%02d,%02d", color, bgcolor);
            replacedval = tagbuf;
          }
        } else if (!strcmp(tagbuf, "B") || !strcmp(tagbuf, "/B"))
          replacedval = "\x02";
        else if (!strcmp(tagbuf, "U") || !strcmp(tagbuf, "/U"))
          replacedval = "\x1F";
        else if (!strcmp(tagbuf, "I") || !strcmp(tagbuf, "/I"))
          replacedval = "\x16";
      }
      if (replacedval) {
        int partlen = p1 - cur;
        if (destline) {
          memcpy(d, cur, partlen);
          d += partlen;
        } else
          destlen += partlen;
        libirc_colorparser_addorcat(&d, &destlen, replacedval);
        cur = p2 + 1;
      } else {
        int partlen;
        if (!p2)
          p2 = cur + strlen(cur);
        partlen = p2 - cur + 1;
        if (destline) {
          memcpy(d, cur, partlen);
          d += partlen;
        } else
          destlen += partlen;
        cur = p2 + 1;
      }
    }
    libirc_colorparser_addorcat(&d, &destlen, cur);
    destlen++;
  }
  *d = '\0';
  return destline;
}


x86 assembly (clang, -O0):
<irc_color_convert_to_mirc>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    15e4 <irc_color_convert_to_mirc+0x454>
cmpl   $0x0,-0x14(%rbp)
jbe    11f6 <irc_color_convert_to_mirc+0x66>
mov    -0x14(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11ee <irc_color_convert_to_mirc+0x5e>
movq   $0x0,-0x8(%rbp)
jmp    15f3 <irc_color_convert_to_mirc+0x463>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0x5b,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     15c5 <irc_color_convert_to_mirc+0x435>
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     14a9 <irc_color_convert_to_mirc+0x319>
mov    -0x30(%rbp),%rdi
mov    $0x5d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     14a9 <irc_color_convert_to_mirc+0x319>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x1,%rax
jle    14a9 <irc_color_convert_to_mirc+0x319>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x1f,%rax
jge    14a9 <irc_color_convert_to_mirc+0x319>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,-0x74(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x30(%rbp),%rsi
add    $0x1,%rsi
mov    -0x74(%rbp),%edx
call   1080 <memcpy@plt>
movslq -0x74(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rdi
lea    0xd45(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12d9 <irc_color_convert_to_mirc+0x149>
lea    0xd37(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    14a4 <irc_color_convert_to_mirc+0x314>
lea    -0x70(%rbp),%rdi
lea    0xd25(%rip),%rsi
call   10b0 <strstr@plt>
lea    -0x70(%rbp),%rcx
cmp    %rcx,%rax
jne    13cf <irc_color_convert_to_mirc+0x23f>
movl   $0xfffffffe,-0x7c(%rbp)
lea    -0x70(%rbp),%rdi
add    $0x6,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     134b <irc_color_convert_to_mirc+0x1bb>
mov    -0x88(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x88(%rbp)
movb   $0x0,(%rax)
mov    -0x88(%rbp),%rdi
call   1030 <libirc_colorparser_colorlookup@plt>
mov    %eax,-0x7c(%rbp)
lea    -0x70(%rbp),%rdi
add    $0x6,%rdi
call   1030 <libirc_colorparser_colorlookup@plt>
mov    %eax,-0x78(%rbp)
cmpl   $0xffffffff,-0x78(%rbp)
je     1391 <irc_color_convert_to_mirc+0x201>
cmpl   $0xfffffffe,-0x7c(%rbp)
jne    1391 <irc_color_convert_to_mirc+0x201>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%edx
lea    0xc93(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    13ca <irc_color_convert_to_mirc+0x23a>
cmpl   $0xffffffff,-0x78(%rbp)
je     13c5 <irc_color_convert_to_mirc+0x235>
cmpl   $0x0,-0x7c(%rbp)
jl     13c5 <irc_color_convert_to_mirc+0x235>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%edx
mov    -0x7c(%rbp),%ecx
lea    0xc60(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    13ca <irc_color_convert_to_mirc+0x23a>
jmp    149f <irc_color_convert_to_mirc+0x30f>
lea    -0x70(%rbp),%rdi
lea    0xc48(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     1401 <irc_color_convert_to_mirc+0x271>
lea    -0x70(%rbp),%rdi
lea    0xc2e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1411 <irc_color_convert_to_mirc+0x281>
lea    0xc1c(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    149a <irc_color_convert_to_mirc+0x30a>
lea    -0x70(%rbp),%rdi
lea    0xc0b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     1443 <irc_color_convert_to_mirc+0x2b3>
lea    -0x70(%rbp),%rdi
lea    0xbf1(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1453 <irc_color_convert_to_mirc+0x2c3>
lea    0xbdf(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    1495 <irc_color_convert_to_mirc+0x305>
lea    -0x70(%rbp),%rdi
lea    0xbce(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     1485 <irc_color_convert_to_mirc+0x2f5>
lea    -0x70(%rbp),%rdi
lea    0xbb4(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1490 <irc_color_convert_to_mirc+0x300>
lea    0xba2(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    1495 <irc_color_convert_to_mirc+0x305>
jmp    149a <irc_color_convert_to_mirc+0x30a>
jmp    149f <irc_color_convert_to_mirc+0x30f>
jmp    14a4 <irc_color_convert_to_mirc+0x314>
jmp    14a9 <irc_color_convert_to_mirc+0x319>
cmpq   $0x0,-0x48(%rbp)
je     152a <irc_color_convert_to_mirc+0x39a>
mov    -0x30(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x8c(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     14fc <irc_color_convert_to_mirc+0x36c>
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x8c(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x8c(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1508 <irc_color_convert_to_mirc+0x378>
mov    -0x8c(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x48(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <libirc_colorparser_addorcat@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    15c0 <irc_color_convert_to_mirc+0x430>
cmpq   $0x0,-0x38(%rbp)
jne    155c <irc_color_convert_to_mirc+0x3cc>
mov    -0x40(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x98(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x90(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     15a8 <irc_color_convert_to_mirc+0x418>
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x90(%rbp),%edx
call   1080 <memcpy@plt>
mov    -0x90(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    15b4 <irc_color_convert_to_mirc+0x424>
mov    -0x90(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11fe <irc_color_convert_to_mirc+0x6e>
mov    -0x40(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <libirc_colorparser_addorcat@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b6 <irc_color_convert_to_mirc+0x26>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irc_color_convert_to_mirc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,0x30(%rsp)
movl   $0x0,0x4(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%r12
xor    %edi,%edi
jmp    11d6 <irc_color_convert_to_mirc+0x56>
nopl   (%rax)
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
mov    %r13,%rdx
call   1070 <libirc_colorparser_addorcat@plt>
mov    0x4(%rsp),%edi
add    $0x1,%edi
mov    %edi,0x4(%rsp)
test   %r14,%r14
jne    1486 <irc_color_convert_to_mirc+0x306>
test   %edi,%edi
je     1200 <irc_color_convert_to_mirc+0x80>
call   1090 <malloc@plt>
test   %rax,%rax
je     1490 <irc_color_convert_to_mirc+0x310>
mov    %rax,%r14
mov    %rax,0x8(%rsp)
jmp    1203 <irc_color_convert_to_mirc+0x83>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %r14d,%r14d
mov    0x30(%rsp),%r13
mov    %r13,%rdi
mov    $0x5b,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11b0 <irc_color_convert_to_mirc+0x30>
mov    %rax,%rbp
mov    0x30(%rsp),%r15
jmp    1254 <irc_color_convert_to_mirc+0xd4>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    %ebx,0x4(%rsp)
add    $0x1,%r13
mov    %r13,%rdi
mov    $0x5b,%esi
call   1060 <strchr@plt>
mov    %rax,%rbp
mov    %r13,%r15
test   %rax,%rax
je     11b0 <irc_color_convert_to_mirc+0x30>
cmpb   $0x0,0x1(%rbp)
je     1390 <irc_color_convert_to_mirc+0x210>
mov    %rbp,%rdi
mov    $0x5d,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1390 <irc_color_convert_to_mirc+0x210>
mov    %rax,%r13
mov    %rax,%rbx
sub    %rbp,%rbx
lea    -0x2(%rbx),%rax
cmp    $0x1c,%rax
ja     139e <irc_color_convert_to_mirc+0x21e>
lea    0x1(%rbp),%rsi
add    $0xffffffff,%ebx
mov    %r12,%rdi
mov    %ebx,%edx
call   1080 <memcpy@plt>
movb   $0x0,0x10(%rsp,%rbx,1)
mov    0x10(%rsp),%eax
mov    $0x4c4f432f,%ecx
xor    %ecx,%eax
mov    0x13(%rsp),%ecx
mov    $0x524f4c,%edx
xor    %edx,%ecx
or     %eax,%ecx
lea    0xd47(%rip),%rbx
je     144a <irc_color_convert_to_mirc+0x2ca>
lea    0xd3c(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
test   %eax,%eax
je     13cc <irc_color_convert_to_mirc+0x24c>
movzwl 0x10(%rsp),%eax
lea    0xd2d(%rip),%rbx
cmp    $0x42,%ax
je     144a <irc_color_convert_to_mirc+0x2ca>
mov    0x10(%rsp),%ecx
mov    $0x422f,%edx
xor    %edx,%ecx
movzbl 0x12(%rsp),%edx
or     %cx,%dx
lea    0xd09(%rip),%rbx
je     144a <irc_color_convert_to_mirc+0x2ca>
lea    0xd01(%rip),%rbx
cmp    $0x55,%ax
je     144a <irc_color_convert_to_mirc+0x2ca>
mov    0x10(%rsp),%ecx
mov    $0x552f,%edx
xor    %edx,%ecx
movzbl 0x12(%rsp),%edx
or     %cx,%dx
lea    0xcdd(%rip),%rbx
je     144a <irc_color_convert_to_mirc+0x2ca>
lea    0xcd5(%rip),%rbx
cmp    $0x49,%ax
je     144a <irc_color_convert_to_mirc+0x2ca>
mov    0x10(%rsp),%eax
mov    $0x492f,%ecx
xor    %ecx,%eax
movzbl 0x12(%rsp),%ecx
or     %ax,%cx
lea    0xcb1(%rip),%rbx
jne    139e <irc_color_convert_to_mirc+0x21e>
jmp    144a <irc_color_convert_to_mirc+0x2ca>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
call   1050 <strlen@plt>
movslq %eax,%r13
add    %r15,%r13
mov    %r13d,%ebx
sub    %r15d,%ebx
add    $0x1,%ebx
test   %r14,%r14
je     1230 <irc_color_convert_to_mirc+0xb0>
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1080 <memcpy@plt>
movslq %ebx,%rax
add    %rax,0x8(%rsp)
jmp    1234 <irc_color_convert_to_mirc+0xb4>
lea    0x16(%rsp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     13f3 <irc_color_convert_to_mirc+0x273>
mov    %rax,%rdi
add    $0x1,%rdi
movb   $0x0,(%rax)
call   1040 <libirc_colorparser_colorlookup@plt>
mov    %eax,%ebx
jmp    13f8 <irc_color_convert_to_mirc+0x278>
mov    $0xfffffffe,%ebx
lea    0x16(%rsp),%rdi
call   1040 <libirc_colorparser_colorlookup@plt>
cmp    $0xffffffff,%eax
je     1421 <irc_color_convert_to_mirc+0x2a1>
cmp    $0xfffffffe,%ebx
jne    1421 <irc_color_convert_to_mirc+0x2a1>
mov    %r12,%rdi
lea    0xbfa(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <sprintf@plt>
jmp    1447 <irc_color_convert_to_mirc+0x2c7>
cmp    $0xffffffff,%eax
je     139e <irc_color_convert_to_mirc+0x21e>
test   %ebx,%ebx
js     139e <irc_color_convert_to_mirc+0x21e>
mov    %r12,%rdi
lea    0xbda(%rip),%rsi
mov    %eax,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %r12,%rbx
sub    %r15,%rbp
test   %r14,%r14
je     146b <irc_color_convert_to_mirc+0x2eb>
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1080 <memcpy@plt>
movslq %ebp,%rax
add    %rax,0x8(%rsp)
jmp    146f <irc_color_convert_to_mirc+0x2ef>
add    %ebp,0x4(%rsp)
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
mov    %rbx,%rdx
call   1070 <libirc_colorparser_addorcat@plt>
jmp    1234 <irc_color_convert_to_mirc+0xb4>
mov    0x8(%rsp),%rax
movb   $0x0,(%rax)
jmp    1493 <irc_color_convert_to_mirc+0x313>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"/COLOR\00"
@.str.1 = [2 x i8] c"\0F\00"
@.str.2 = [7 x i8] c"COLOR=\00"
@.str.3 = [6 x i8] c"\03%02d\00"
@.str.4 = [11 x i8] c"\03%02d,%02d\00"
@.str.5 = [2 x i8] c"B\00"
@.str.6 = [3 x i8] c"/B\00"
@.str.7 = [2 x i8] c"\02\00"
@.str.8 = [2 x i8] c"U\00"
@.str.9 = [3 x i8] c"/U\00"
@.str.10 = [2 x i8] c"\1F\00"
@.str.11 = [2 x i8] c"I\00"
@.str.12 = [3 x i8] c"/I\00"
@.str.13 = [2 x i8] c"\16\00"
define i8* @irc_color_convert_to_mirc(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [32 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
store i8* null, i8** %5
store i8* null, i8** %6
br label %18
18: ; preds = %223, %1
%19 = load i8*, i8** %5
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %228
21: ; preds = %18
%22 = load i32, i32* %4
%23 = icmp ugt i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i32, i32* %4
%26 = call i8* @malloc(i32 %25)
store i8* %26, i8** %5
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %24
store i8* null, i8** %2
br label %231
29: ; preds = %24
%30 = load i8*, i8** %5
store i8* %30, i8** %6
br label %31
31: ; preds = %29, %21
%32 = load i8*, i8** %3
store i8* %32, i8** %9
br label %33
33: ; preds = %222, %31
%34 = load i8*, i8** %9
%35 = call i8* @strchr(i8* %34, i8 signext 91)
store i8* %35, i8** %7
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %223
37: ; preds = %33
store i8* null, i8** %10
store i8* null, i8** %8
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %157
43: ; preds = %37
%44 = load i8*, i8** %7
%45 = call i8* @strchr(i8* %44, i8 signext 93)
store i8* %45, i8** %8
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %157
47: ; preds = %43
%48 = load i8*, i8** %8
%49 = load i8*, i8** %7
%50 = ptrtoint i8* %48 to i64
%51 = ptrtoint i8* %49 to i64
%52 = sub i64 %50, %51
%53 = icmp sgt i64 %52, 1
br i1 %53, label %54, label %157
54: ; preds = %47
%55 = load i8*, i8** %8
%56 = load i8*, i8** %7
%57 = ptrtoint i8* %55 to i64
%58 = ptrtoint i8* %56 to i64
%59 = sub i64 %57, %58
%60 = icmp slt i64 %59, 31
br i1 %60, label %61, label %157
61: ; preds = %54
%62 = load i8*, i8** %8
%63 = load i8*, i8** %7
%64 = ptrtoint i8* %62 to i64
%65 = ptrtoint i8* %63 to i64
%66 = sub i64 %64, %65
%67 = sub nsw i64 %66, 1
%68 = trunc i64 %67 to i32
store i32 %68, i32* %12
%69 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%70 = load i8*, i8** %7
%71 = getelementptr inbounds i8, i8* %70, i64 1
%72 = load i32, i32* %12
%73 = call i32 @memcpy(i8* %69, i8* %71, i32 %72)
%74 = load i32, i32* %12
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 %75
store i8 0, i8* %76
%77 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%78 = call i32 @strcmp(i8* %77, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%79 = icmp ne i32 %78, 0
br i1 %79, label %81, label %80
80: ; preds = %61
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %10
br label %156
81: ; preds = %61
%82 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%83 = call i8* @strstr(i8* %82, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%84 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%85 = icmp eq i8* %83, %84
br i1 %85, label %86, label %125
86: ; preds = %81
store i32 -2, i32* %14
%87 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%88 = getelementptr inbounds i8, i8* %87, i64 6
%89 = call i8* @strchr(i8* %88, i8 signext 47)
store i8* %89, i8** %15
%90 = load i8*, i8** %15
%91 = icmp ne i8* %90, null
br i1 %91, label %92, label %97
92: ; preds = %86
%93 = load i8*, i8** %15
%94 = getelementptr inbounds i8, i8* %93, i32 1
store i8* %94, i8** %15
store i8 0, i8* %93
%95 = load i8*, i8** %15
%96 = call i32 @libirc_colorparser_colorlookup(i8* %95)
store i32 %96, i32* %14
br label %97
97: ; preds = %92, %86
%98 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%99 = getelementptr inbounds i8, i8* %98, i64 6
%100 = call i32 @libirc_colorparser_colorlookup(i8* %99)
store i32 %100, i32* %13
%101 = load i32, i32* %13
%102 = icmp ne i32 %101, -1
br i1 %102, label %103, label %111
103: ; preds = %97
%104 = load i32, i32* %14
%105 = icmp eq i32 %104, -2
br i1 %105, label %106, label %111
106: ; preds = %103
%107 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%108 = load i32, i32* %13
%109 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %107, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %108)
%110 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
store i8* %110, i8** %10
br label %124
111: ; preds = %103, %97
%112 = load i32, i32* %13
%113 = icmp ne i32 %112, -1
br i1 %113, label %114, label %123
114: ; preds = %111
%115 = load i32, i32* %14
%116 = icmp sge i32 %115, 0
br i1 %116, label %117, label %123
117: ; preds = %114
%118 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%119 = load i32, i32* %13
%120 = load i32, i32* %14
%121 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %118, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %119, i32 %120)
%122 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
store i8* %122, i8** %10
br label %123
123: ; preds = %117, %114, %111
br label %124
124: ; preds = %123, %106
br label %155
125: ; preds = %81
%126 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%127 = call i32 @strcmp(i8* %126, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%128 = icmp ne i32 %127, 0
br i1 %128, label %129, label %133
129: ; preds = %125
%130 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%131 = call i32 @strcmp(i8* %130, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%132 = icmp ne i32 %131, 0
br i1 %132, label %134, label %133
133: ; preds = %129, %125
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i8** %10
br label %154
134: ; preds = %129
%135 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%136 = call i32 @strcmp(i8* %135, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%137 = icmp ne i32 %136, 0
br i1 %137, label %138, label %142
138: ; preds = %134
%139 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%140 = call i32 @strcmp(i8* %139, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%141 = icmp ne i32 %140, 0
br i1 %141, label %143, label %142
142: ; preds = %138, %134
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i8** %10
br label %153
143: ; preds = %138
%144 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%145 = call i32 @strcmp(i8* %144, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%146 = icmp ne i32 %145, 0
br i1 %146, label %147, label %151
147: ; preds = %143
%148 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%149 = call i32 @strcmp(i8* %148, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%150 = icmp ne i32 %149, 0
br i1 %150, label %152, label %151
151: ; preds = %147, %143
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0), i8** %10
br label %152
152: ; preds = %151, %147
br label %153
153: ; preds = %152, %142
br label %154
154: ; preds = %153, %133
br label %155
155: ; preds = %154, %124
br label %156
156: ; preds = %155, %80
br label %157
157: ; preds = %156, %54, %47, %43, %37
%158 = load i8*, i8** %10
%159 = icmp ne i8* %158, null
br i1 %159, label %160, label %187
160: ; preds = %157
%161 = load i8*, i8** %7
%162 = load i8*, i8** %9
%163 = ptrtoint i8* %161 to i64
%164 = ptrtoint i8* %162 to i64
%165 = sub i64 %163, %164
%166 = trunc i64 %165 to i32
store i32 %166, i32* %16
%167 = load i8*, i8** %5
%168 = icmp ne i8* %167, null
br i1 %168, label %169, label %178
169: ; preds = %160
%170 = load i8*, i8** %6
%171 = load i8*, i8** %9
%172 = load i32, i32* %16
%173 = call i32 @memcpy(i8* %170, i8* %171, i32 %172)
%174 = load i32, i32* %16
%175 = load i8*, i8** %6
%176 = sext i32 %174 to i64
%177 = getelementptr inbounds i8, i8* %175, i64 %176
store i8* %177, i8** %6
br label %182
178: ; preds = %160
%179 = load i32, i32* %16
%180 = load i32, i32* %4
%181 = add i32 %180, %179
store i32 %181, i32* %4
br label %182
182: ; preds = %178, %169
%183 = load i8*, i8** %10
%184 = call i32 @libirc_colorparser_addorcat(i8** %6, i32* %4, i8* %183)
%185 = load i8*, i8** %8
%186 = getelementptr inbounds i8, i8* %185, i64 1
store i8* %186, i8** %9
br label %222
187: ; preds = %157
%188 = load i8*, i8** %8
%189 = icmp ne i8* %188, null
br i1 %189, label %196, label %190
190: ; preds = %187
%191 = load i8*, i8** %9
%192 = load i8*, i8** %9
%193 = call i32 @strlen(i8* %192)
%194 = sext i32 %193 to i64
%195 = getelementptr inbounds i8, i8* %191, i64 %194
store i8* %195, i8** %8
br label %196
196: ; preds = %190, %187
%197 = load i8*, i8** %8
%198 = load i8*, i8** %9
%199 = ptrtoint i8* %197 to i64
%200 = ptrtoint i8* %198 to i64
%201 = sub i64 %199, %200
%202 = add nsw i64 %201, 1
%203 = trunc i64 %202 to i32
store i32 %203, i32* %17
%204 = load i8*, i8** %5
%205 = icmp ne i8* %204, null
br i1 %205, label %206, label %215
206: ; preds = %196
%207 = load i8*, i8** %6
%208 = load i8*, i8** %9
%209 = load i32, i32* %17
%210 = call i32 @memcpy(i8* %207, i8* %208, i32 %209)
%211 = load i32, i32* %17
%212 = load i8*, i8** %6
%213 = sext i32 %211 to i64
%214 = getelementptr inbounds i8, i8* %212, i64 %213
store i8* %214, i8** %6
br label %219
215: ; preds = %196
%216 = load i32, i32* %17
%217 = load i32, i32* %4
%218 = add i32 %217, %216
store i32 %218, i32* %4
br label %219
219: ; preds = %215, %206
%220 = load i8*, i8** %8
%221 = getelementptr inbounds i8, i8* %220, i64 1
store i8* %221, i8** %9
br label %222
222: ; preds = %219, %182
br label %33
223: ; preds = %33
%224 = load i8*, i8** %9
%225 = call i32 @libirc_colorparser_addorcat(i8** %6, i32* %4, i8* %224)
%226 = load i32, i32* %4
%227 = add i32 %226, 1
store i32 %227, i32* %4
br label %18
228: ; preds = %18
%229 = load i8*, i8** %6
store i8 0, i8* %229
%230 = load i8*, i8** %5
store i8* %230, i8** %2
br label %231
231: ; preds = %228, %28
%232 = load i8*, i8** %2
ret i8* %232
}

LLVM IR (-O2):
@.str = [7 x i8] c"/COLOR\00"
@.str.1 = [2 x i8] c"\0F\00"
@.str.2 = [7 x i8] c"COLOR=\00"
@.str.3 = [6 x i8] c"\03%02d\00"
@.str.4 = [11 x i8] c"\03%02d,%02d\00"
@.str.6 = [3 x i8] c"/B\00"
@.str.7 = [2 x i8] c"\02\00"
@.str.9 = [3 x i8] c"/U\00"
@.str.10 = [2 x i8] c"\1F\00"
@.str.12 = [3 x i8] c"/I\00"
@.str.13 = [2 x i8] c"\16\00"
define i8* @irc_color_convert_to_mirc(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [32 x i8]
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%8 = bitcast [32 x i8]* %4 to i16*
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 6
br label %10
10: ; preds = %1, %129
%11 = phi i32 [ 0, %1 ], [ %133, %129 ]
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = call i8* @malloc(i32 %11)
%15 = icmp eq i8* %14, null
br i1 %15, label %137, label %16
16: ; preds = %13
store i8* %14, i8** %3
br label %17
17: ; preds = %16, %10
%18 = phi i8* [ %14, %16 ], [ null, %10 ]
%19 = call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 91)
%20 = icmp eq i8* %19, null
br i1 %20, label %129, label %21
21: ; preds = %17
%22 = icmp eq i8* %18, null
br label %23
23: ; preds = %21, %124
%24 = phi i8* [ %19, %21 ], [ %127, %124 ]
%25 = phi i8* [ %0, %21 ], [ %126, %124 ]
%26 = getelementptr inbounds i8, i8* %24, i64 1
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %103, label %29
29: ; preds = %23
%30 = call i8* @strchr(i8* %24, i8 signext 93)
%31 = icmp eq i8* %30, null
br i1 %31, label %103, label %32
32: ; preds = %29
%33 = ptrtoint i8* %30 to i64
%34 = ptrtoint i8* %24 to i64
%35 = sub i64 %33, %34
%36 = add i64 %35, -2
%37 = icmp ult i64 %36, 29
br i1 %37, label %38, label %108
38: ; preds = %32
%39 = trunc i64 %35 to i32
%40 = add nsw i32 %39, -1
%41 = call i32 @memcpy(i8* %7, i8* %26, i32 %40)
%42 = zext i32 %40 to i64
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %42
store i8 0, i8* %43
%44 = call i32 @bcmp(i8* dereferenceable(7) %7, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 7)
%45 = icmp eq i32 %44, 0
br i1 %45, label %86, label %46
46: ; preds = %38
%47 = call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%48 = call i32 @strncmp(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 %47)
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %69
50: ; preds = %46
%51 = call i8* @strchr(i8* %9, i8 signext 47)
%52 = icmp eq i8* %51, null
br i1 %52, label %56, label %53
53: ; preds = %50
%54 = getelementptr inbounds i8, i8* %51, i64 1
store i8 0, i8* %51
%55 = call i32 @libirc_colorparser_colorlookup(i8* %54)
br label %56
56: ; preds = %53, %50
%57 = phi i32 [ %55, %53 ], [ -2, %50 ]
%58 = call i32 @libirc_colorparser_colorlookup(i8* %9)
%59 = icmp ne i32 %58, -1
%60 = icmp eq i32 %57, -2
%61 = select i1 %59, i1 %60, i1 false
br i1 %61, label %62, label %64
62: ; preds = %56
%63 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %58)
br label %86
64: ; preds = %56
%65 = icmp sgt i32 %57, -1
%66 = select i1 %59, i1 %65, i1 false
br i1 %66, label %67, label %85
67: ; preds = %64
%68 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %58, i32 %57)
br label %86
69: ; preds = %46
%70 = load i16, i16* %8
%71 = icmp eq i16 %70, 66
br i1 %71, label %86, label %72
72: ; preds = %69
%73 = call i32 @bcmp(i8* dereferenceable(3) %7, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i64 3)
%74 = icmp eq i32 %73, 0
br i1 %74, label %86, label %75
75: ; preds = %72
%76 = icmp eq i16 %70, 85
br i1 %76, label %86, label %77
77: ; preds = %75
%78 = call i32 @bcmp(i8* dereferenceable(3) %7, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i64 3)
%79 = icmp eq i32 %78, 0
br i1 %79, label %86, label %80
80: ; preds = %77
%81 = icmp eq i16 %70, 73
br i1 %81, label %86, label %82
82: ; preds = %80
%83 = call i32 @bcmp(i8* dereferenceable(3) %7, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i64 3)
%84 = icmp eq i32 %83, 0
br i1 %84, label %86, label %85
85: ; preds = %64, %82
br label %108
86: ; preds = %80, %82, %38, %62, %67, %72, %69, %77, %75
%87 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), %75 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), %77 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), %69 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), %72 ], [ %7, %67 ], [ %7, %62 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %38 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0), %82 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0), %80 ]
%88 = ptrtoint i8* %25 to i64
%89 = sub i64 %34, %88
%90 = trunc i64 %89 to i32
br i1 %22, label %98, label %91
91: ; preds = %86
%92 = load i8*, i8** %3
%93 = call i32 @memcpy(i8* %92, i8* %25, i32 %90)
%94 = load i8*, i8** %3
%95 = shl i64 %89, 32
%96 = ashr exact i64 %95, 32
%97 = getelementptr inbounds i8, i8* %94, i64 %96
store i8* %97, i8** %3
br label %101
98: ; preds = %86
%99 = load i32, i32* %2
%100 = add i32 %99, %90
store i32 %100, i32* %2
br label %101
101: ; preds = %98, %91
%102 = call i32 @libirc_colorparser_addorcat(i8** %3, i32* %2, i8* %87)
br label %124
103: ; preds = %23, %29
%104 = call i32 @strlen(i8* %25)
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i8, i8* %25, i64 %105
%107 = ptrtoint i8* %106 to i64
br label %108
108: ; preds = %32, %85, %103
%109 = phi i64 [ %33, %32 ], [ %33, %85 ], [ %107, %103 ]
%110 = phi i8* [ %30, %32 ], [ %30, %85 ], [ %106, %103 ]
%111 = ptrtoint i8* %25 to i64
%112 = sub i64 %109, %111
%113 = trunc i64 %112 to i32
%114 = add i32 %113, 1
br i1 %22, label %121, label %115
115: ; preds = %108
%116 = load i8*, i8** %3
%117 = call i32 @memcpy(i8* %116, i8* %25, i32 %114)
%118 = load i8*, i8** %3
%119 = sext i32 %114 to i64
%120 = getelementptr inbounds i8, i8* %118, i64 %119
store i8* %120, i8** %3
br label %124
121: ; preds = %108
%122 = load i32, i32* %2
%123 = add i32 %122, %114
store i32 %123, i32* %2
br label %124
124: ; preds = %115, %121, %101
%125 = phi i8* [ %30, %101 ], [ %110, %121 ], [ %110, %115 ]
%126 = getelementptr inbounds i8, i8* %125, i64 1
%127 = call i8* @strchr(i8* dereferenceable(1) %126, i8 signext 91)
%128 = icmp eq i8* %127, null
br i1 %128, label %129, label %23
129: ; preds = %124, %17
%130 = phi i8* [ %0, %17 ], [ %126, %124 ]
%131 = call i32 @libirc_colorparser_addorcat(i8** %3, i32* %2, i8* %130)
%132 = load i32, i32* %2
%133 = add i32 %132, 1
store i32 %133, i32* %2
%134 = icmp eq i8* %18, null
br i1 %134, label %10, label %135
135: ; preds = %129
%136 = load i8*, i8** %3
store i8 0, i8* %136
br label %137
137: ; preds = %13, %135
%138 = phi i8* [ %18, %135 ], [ null, %13 ]
ret i8* %138
}