#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*/ irccmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtoken(char **, char *, char *);
char *canonize(char *buffer) {
  static char cbuf[512];
  char *s, *t, *cp = cbuf;
  int l = 0;
  char *p = 0, *p2;
  *cp = '\0';
  for (s = strtoken(&p, buffer, ","); s; s = strtoken(&p, 0, ",")) {
    if (l) {
      for (p2 = 0, t = strtoken(&p2, cbuf, ","); t; t = strtoken(&p2, 0, ","))
        if (!irccmp(s, t))
          break;
        else if (p2)
          p2[-1] = ',';
    } else
      t = 0;
    if (!t) {
      if (l)
        *(cp - 1) = ',';
      else
        l = 1;
      (void)strcpy(cp, s);
      if (p)
        cp += (p - s);
    } else if (p2)
      p2[-1] = ',';
  }
  return cbuf;
}


x86 assembly (clang, -O0):
<canonize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2f0d(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rsi
lea    -0x30(%rbp),%rdi
lea    0xe94(%rip),%rdx
call   1040 <strtoken@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     12ad <canonize+0x17d>
cmpl   $0x0,-0x24(%rbp)
je     1212 <canonize+0xe2>
movq   $0x0,-0x38(%rbp)
lea    -0x38(%rbp),%rdi
lea    0x2eb3(%rip),%rsi
lea    0xe5c(%rip),%rdx
call   1040 <strtoken@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     120d <canonize+0xdd>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <irccmp@plt>
cmp    $0x0,%eax
jne    11d3 <canonize+0xa3>
jmp    120d <canonize+0xdd>
cmpq   $0x0,-0x38(%rbp)
je     11e6 <canonize+0xb6>
mov    -0x38(%rbp),%rax
movb   $0x2c,-0x1(%rax)
jmp    11eb <canonize+0xbb>
jmp    11f0 <canonize+0xc0>
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    0xe01(%rip),%rdx
call   1040 <strtoken@plt>
mov    %rax,-0x18(%rbp)
jmp    11ad <canonize+0x7d>
jmp    121a <canonize+0xea>
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1273 <canonize+0x143>
cmpl   $0x0,-0x24(%rbp)
je     123c <canonize+0x10c>
mov    -0x20(%rbp),%rax
movb   $0x2c,-0x1(%rax)
jmp    1243 <canonize+0x113>
movl   $0x1,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
cmpq   $0x0,-0x30(%rbp)
je     126e <canonize+0x13e>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    128b <canonize+0x15b>
cmpq   $0x0,-0x38(%rbp)
je     1286 <canonize+0x156>
mov    -0x38(%rbp),%rax
movb   $0x2c,-0x1(%rax)
jmp    128b <canonize+0x15b>
jmp    1290 <canonize+0x160>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    0xd61(%rip),%rdx
call   1040 <strtoken@plt>
mov    %rax,-0x10(%rbp)
jmp    1175 <canonize+0x45>
lea    0x2d9c(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canonize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rsi
movq   $0x0,0x8(%rsp)
movb   $0x0,0x2eff(%rip)
lea    0xea8(%rip),%rdx
lea    0x8(%rsp),%rdi
call   1040 <strtoken@plt>
test   %rax,%rax
je     1252 <canonize+0x122>
mov    %rax,%rbp
lea    0x2edb(%rip),%r13
xor    %r14d,%r14d
lea    0xe81(%rip),%rbx
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
jmp    11a9 <canonize+0x79>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <strtoken@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1252 <canonize+0x122>
test   %r14d,%r14d
je     1215 <canonize+0xe5>
movq   $0x0,0x10(%rsp)
mov    %r12,%rdi
lea    0x2e8f(%rip),%rsi
jmp    11d5 <canonize+0xa5>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <strtoken@plt>
test   %rax,%rax
je     1210 <canonize+0xe0>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1050 <irccmp@plt>
mov    0x10(%rsp),%rcx
test   %eax,%eax
je     1240 <canonize+0x110>
test   %rcx,%rcx
je     11d0 <canonize+0xa0>
movb   $0x2c,-0x1(%rcx)
jmp    11d0 <canonize+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x2c,-0x1(%r13)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    0x8(%rsp),%rax
mov    $0x1,%r14d
test   %rax,%rax
je     1190 <canonize+0x60>
sub    %rbp,%rax
add    %rax,%r13
jmp    1190 <canonize+0x60>
nop
test   %rcx,%rcx
je     1190 <canonize+0x60>
movb   $0x2c,-0x1(%rcx)
jmp    1190 <canonize+0x60>
lea    0x2df7(%rip),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@canonize.cbuf = internal global [512 x i8] zeroinitializer
@.str = [2 x i8] c",\00"
define i8* @canonize(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @canonize.cbuf, i64 0, i64 0), i8** %5
store i32 0, i32* %6
store i8* null, i8** %7
%9 = load i8*, i8** %5
store i8 0, i8* %9
%10 = load i8*, i8** %2
%11 = call i8* @strtoken(i8** %7, i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %3
br label %12
12: ; preds = %74, %1
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %76
15: ; preds = %12
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %40
18: ; preds = %15
store i8* null, i8** %8
%19 = call i8* @strtoken(i8** %8, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @canonize.cbuf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %4
br label %20
20: ; preds = %37, %18
%21 = load i8*, i8** %4
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %39
23: ; preds = %20
%24 = load i8*, i8** %3
%25 = load i8*, i8** %4
%26 = call i32 @irccmp(i8* %24, i8* %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %23
br label %39
29: ; preds = %23
%30 = load i8*, i8** %8
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i8*, i8** %8
%34 = getelementptr inbounds i8, i8* %33, i64 -1
store i8 44, i8* %34
br label %35
35: ; preds = %32, %29
br label %36
36: ; preds = %35
br label %37
37: ; preds = %36
%38 = call i8* @strtoken(i8** %8, i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %38, i8** %4
br label %20
39: ; preds = %28, %20
br label %41
40: ; preds = %15
store i8* null, i8** %4
br label %41
41: ; preds = %40, %39
%42 = load i8*, i8** %4
%43 = icmp ne i8* %42, null
br i1 %43, label %66, label %44
44: ; preds = %41
%45 = load i32, i32* %6
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 -1
store i8 44, i8* %49
br label %51
50: ; preds = %44
store i32 1, i32* %6
br label %51
51: ; preds = %50, %47
%52 = load i8*, i8** %5
%53 = load i8*, i8** %3
%54 = call i32 @strcpy(i8* %52, i8* %53)
%55 = load i8*, i8** %7
%56 = icmp ne i8* %55, null
br i1 %56, label %57, label %65
57: ; preds = %51
%58 = load i8*, i8** %7
%59 = load i8*, i8** %3
%60 = ptrtoint i8* %58 to i64
%61 = ptrtoint i8* %59 to i64
%62 = sub i64 %60, %61
%63 = load i8*, i8** %5
%64 = getelementptr inbounds i8, i8* %63, i64 %62
store i8* %64, i8** %5
br label %65
65: ; preds = %57, %51
br label %73
66: ; preds = %41
%67 = load i8*, i8** %8
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load i8*, i8** %8
%71 = getelementptr inbounds i8, i8* %70, i64 -1
store i8 44, i8* %71
br label %72
72: ; preds = %69, %66
br label %73
73: ; preds = %72, %65
br label %74
74: ; preds = %73
%75 = call i8* @strtoken(i8** %7, i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %75, i8** %3
br label %12
76: ; preds = %12
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @canonize.cbuf, i64 0, i64 0)
}

LLVM IR (-O2):
@canonize.cbuf = internal global [512 x i8] zeroinitializer
@.str = [2 x i8] c",\00"
define i8* @canonize(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i8** %3 to i8*
store i8 0, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @canonize.cbuf, i64 0, i64 0)
%6 = call i8* @strtoken(i8** %2, i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %47, label %8
8: ; preds = %1, %42
%9 = phi i32 [ %44, %42 ], [ 0, %1 ]
%10 = phi i8* [ %43, %42 ], [ getelementptr inbounds ([512 x i8], [512 x i8]* @canonize.cbuf, i64 0, i64 0), %1 ]
%11 = phi i8* [ %45, %42 ], [ %6, %1 ]
%12 = icmp eq i32 %9, 0
br i1 %12, label %30, label %13
13: ; preds = %8
store i8* null, i8** %3
%14 = call i8* @strtoken(i8** %3, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @canonize.cbuf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %28, label %16
16: ; preds = %13, %25
%17 = phi i8* [ %26, %25 ], [ %14, %13 ]
%18 = call i32 @irccmp(i8* %11, i8* %17)
%19 = icmp eq i32 %18, 0
%20 = load i8*, i8** %3
%21 = icmp eq i8* %20, null
br i1 %19, label %39, label %22
22: ; preds = %16
br i1 %21, label %25, label %23
23: ; preds = %22
%24 = getelementptr inbounds i8, i8* %20, i64 -1
store i8 44, i8* %24
br label %25
25: ; preds = %23, %22
%26 = call i8* @strtoken(i8** %3, i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %16
28: ; preds = %25, %13
%29 = getelementptr inbounds i8, i8* %10, i64 -1
store i8 44, i8* %29
br label %30
30: ; preds = %8, %28
%31 = call i32 @strcpy(i8* %10, i8* %11)
%32 = load i8*, i8** %2
%33 = icmp eq i8* %32, null
br i1 %33, label %42, label %34
34: ; preds = %30
%35 = ptrtoint i8* %32 to i64
%36 = ptrtoint i8* %11 to i64
%37 = sub i64 %35, %36
%38 = getelementptr inbounds i8, i8* %10, i64 %37
br label %42
39: ; preds = %16
br i1 %21, label %42, label %40
40: ; preds = %39
%41 = getelementptr inbounds i8, i8* %20, i64 -1
store i8 44, i8* %41
br label %42
42: ; preds = %34, %30, %40, %39
%43 = phi i8* [ %10, %40 ], [ %10, %39 ], [ %38, %34 ], [ %10, %30 ]
%44 = phi i32 [ %9, %40 ], [ %9, %39 ], [ 1, %34 ], [ 1, %30 ]
%45 = call i8* @strtoken(i8** %2, i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %8
47: ; preds = %42, %1
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @canonize.cbuf, i64 0, i64 0)
}