#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*/ free(char *);
char *x_strdup(char const *);
char *_ircprot_ctcpdequote(const char *msg) {
  char *new, *out, *in, *ret;
  int quote = 0;
  in = out = new = x_strdup(msg);
  while (*in) {
    if (quote) {
      if (*in == 'a') {
        *(out++) = '\\';
      } else {
        *(out++) = *in;
      }
      quote = 0;
    } else {
      if (*in == '\\') {
        quote = 1;
      } else {
        *(out++) = *in;
      }
    }
    in++;
  }
  *out = 0;
  ret = x_strdup(new);
  free(new);
  return ret;
}


x86 assembly (clang, -O0):
<_ircprot_ctcpdequote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <x_strdup@plt>
mov    %rax,-0x10(%rbp)
mov    %rax,-0x18(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f2 <_ircprot_ctcpdequote+0xd2>
cmpl   $0x0,-0x2c(%rbp)
je     11a9 <_ircprot_ctcpdequote+0x89>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x61,%eax
jne    1186 <_ircprot_ctcpdequote+0x66>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x5c,(%rax)
jmp    119d <_ircprot_ctcpdequote+0x7d>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
movl   $0x0,-0x2c(%rbp)
jmp    11e1 <_ircprot_ctcpdequote+0xc1>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11c5 <_ircprot_ctcpdequote+0xa5>
movl   $0x1,-0x2c(%rbp)
jmp    11dc <_ircprot_ctcpdequote+0xbc>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    11e1 <_ircprot_ctcpdequote+0xc1>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1148 <_ircprot_ctcpdequote+0x28>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <x_strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ircprot_ctcpdequote>:
push   %r14
push   %rbx
push   %rax
call   1040 <x_strdup@plt>
mov    %rax,%r14
mov    (%rax),%sil
mov    %rax,%rcx
test   %sil,%sil
je     1181 <_ircprot_ctcpdequote+0x61>
mov    %r14,%rax
add    $0x1,%rax
xor    %edi,%edi
mov    $0x5c,%edx
mov    %r14,%rcx
jmp    1170 <_ircprot_ctcpdequote+0x50>
nopw   0x0(%rax,%rax,1)
cmp    $0x61,%sil
movzbl %sil,%esi
cmove  %edx,%esi
mov    %sil,(%rcx)
add    $0x1,%rcx
xor    %edi,%edi
movzbl (%rax),%esi
add    $0x1,%rax
test   %sil,%sil
je     1181 <_ircprot_ctcpdequote+0x61>
test   %edi,%edi
jne    1150 <_ircprot_ctcpdequote+0x30>
mov    $0x1,%edi
cmp    $0x5c,%sil
jne    115b <_ircprot_ctcpdequote+0x3b>
jmp    1164 <_ircprot_ctcpdequote+0x44>
movb   $0x0,(%rcx)
mov    %r14,%rdi
call   1040 <x_strdup@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @_ircprot_ctcpdequote(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %7
%8 = load i8*, i8** %2
%9 = call i8* @x_strdup(i8* %8)
store i8* %9, i8** %3
store i8* %9, i8** %4
store i8* %9, i8** %5
br label %10
10: ; preds = %43, %1
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %46
14: ; preds = %10
%15 = load i32, i32* %7
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 97
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
store i8 92, i8* %23
br label %30
25: ; preds = %17
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
store i8 %27, i8* %28
br label %30
30: ; preds = %25, %22
store i32 0, i32* %7
br label %43
31: ; preds = %14
%32 = load i8*, i8** %5
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 92
br i1 %35, label %36, label %37
36: ; preds = %31
store i32 1, i32* %7
br label %42
37: ; preds = %31
%38 = load i8*, i8** %5
%39 = load i8, i8* %38
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %4
store i8 %39, i8* %40
br label %42
42: ; preds = %37, %36
br label %43
43: ; preds = %42, %30
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %5
br label %10
46: ; preds = %10
%47 = load i8*, i8** %4
store i8 0, i8* %47
%48 = load i8*, i8** %3
%49 = call i8* @x_strdup(i8* %48)
store i8* %49, i8** %6
%50 = load i8*, i8** %3
%51 = call i32 @free(i8* %50)
%52 = load i8*, i8** %6
ret i8* %52
}

LLVM IR (-O2):
define i8* @_ircprot_ctcpdequote(i8* %0) {
%2 = tail call i8* @x_strdup(i8* %0)
%3 = load i8, i8* %2
%4 = icmp eq i8 %3, 0
br i1 %4, label %25, label %5
5: ; preds = %1, %19
%6 = phi i8 [ %23, %19 ], [ %3, %1 ]
%7 = phi i32 [ %21, %19 ], [ 0, %1 ]
%8 = phi i8* [ %20, %19 ], [ %2, %1 ]
%9 = phi i8* [ %22, %19 ], [ %2, %1 ]
%10 = icmp eq i32 %7, 0
br i1 %10, label %14, label %11
11: ; preds = %5
%12 = icmp eq i8 %6, 97
%13 = select i1 %12, i8 92, i8 %6
br label %16
14: ; preds = %5
%15 = icmp eq i8 %6, 92
br i1 %15, label %19, label %16
16: ; preds = %14, %11
%17 = phi i8 [ %13, %11 ], [ %6, %14 ]
%18 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %17, i8* %8
br label %19
19: ; preds = %16, %14
%20 = phi i8* [ %8, %14 ], [ %18, %16 ]
%21 = phi i32 [ 1, %14 ], [ 0, %16 ]
%22 = getelementptr inbounds i8, i8* %9, i64 1
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %5
25: ; preds = %19, %1
%26 = phi i8* [ %2, %1 ], [ %20, %19 ]
store i8 0, i8* %26
%27 = tail call i8* @x_strdup(i8* %2)
%28 = tail call i32 @free(i8* %2)
ret i8* %27
}