#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 */
short strlen(char *);
scalar_t__ strncmp(char *, char *, short);
int translate_back_escape_chars(char *input, char *output) {
  char *p, *p2;
  short e_len, s_len;
  e_len = strlen("EsCaPe");
  s_len = strlen("CoMmA");
  p = input;
  p2 = output;
  while (*p) {
    if (strncmp(p, "CoMmA", s_len) == 0) {
      *p2++ = ',';
      p += s_len;
      continue;
    }
    if (strncmp(p, "EsCaPe", e_len) == 0) {
      *p2++ = '\\';
      p += e_len;
      continue;
    }
    *p2++ = *p++;
  }
  *p2 = '\0';
  return (0);
}


x86 assembly (clang, -O0):
<translate_back_escape_chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec9(%rip),%rdi
call   1040 <strlen@plt>
mov    %ax,-0x22(%rbp)
lea    0xec0(%rip),%rdi
call   1040 <strlen@plt>
mov    %ax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1222 <translate_back_escape_chars+0x102>
mov    -0x18(%rbp),%rdi
lea    0xe8f(%rip),%rsi
movswl -0x24(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11b4 <translate_back_escape_chars+0x94>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2c,(%rax)
movswl -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1160 <translate_back_escape_chars+0x40>
mov    -0x18(%rbp),%rdi
lea    0xe41(%rip),%rsi
movswl -0x22(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11fb <translate_back_escape_chars+0xdb>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x5c,(%rax)
movswl -0x22(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1160 <translate_back_escape_chars+0x40>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    1160 <translate_back_escape_chars+0x40>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<translate_back_escape_chars>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xec8(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0xec1(%rip),%rdi
call   1040 <strlen@plt>
cmpb   $0x0,(%r14)
je     11c9 <translate_back_escape_chars+0xa9>
movswq %bp,%rcx
movswq %ax,%r13
movswl %r13w,%ebp
lea    0xea3(%rip),%r15
mov    %rcx,(%rsp)
movswl %cx,%r12d
jmp    1180 <translate_back_escape_chars+0x60>
xchg   %ax,%ax
movb   $0x2c,(%rbx)
add    %r13,%r14
add    $0x1,%rbx
cmpb   $0x0,(%r14)
je     11c9 <translate_back_escape_chars+0xa9>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1170 <translate_back_escape_chars+0x50>
mov    %r14,%rdi
lea    0xe64(%rip),%rsi
mov    %r12d,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11c0 <translate_back_escape_chars+0xa0>
movzbl (%r14),%eax
add    $0x1,%r14
mov    %al,(%rbx)
jmp    1176 <translate_back_escape_chars+0x56>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x5c,(%rbx)
add    (%rsp),%r14
jmp    1176 <translate_back_escape_chars+0x56>
movb   $0x0,(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"EsCaPe\00"
@.str.1 = [6 x i8] c"CoMmA\00"
define i32 @translate_back_escape_chars(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i16
%8 = alloca i16
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = call signext i16 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i16 %9, i16* %7
%10 = call signext i16 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i16 %10, i16* %8
%11 = load i8*, i8** %3
store i8* %11, i8** %5
%12 = load i8*, i8** %4
store i8* %12, i8** %6
br label %13
13: ; preds = %43, %35, %22, %2
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %49
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = load i16, i16* %8
%20 = call i64 @strncmp(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i16 signext %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %17
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %6
store i8 44, i8* %23
%25 = load i16, i16* %8
%26 = sext i16 %25 to i32
%27 = load i8*, i8** %5
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8* %29, i8** %5
br label %13
30: ; preds = %17
%31 = load i8*, i8** %5
%32 = load i16, i16* %7
%33 = call i64 @strncmp(i8* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i16 signext %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %43
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %6
store i8 92, i8* %36
%38 = load i16, i16* %7
%39 = sext i16 %38 to i32
%40 = load i8*, i8** %5
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i8, i8* %40, i64 %41
store i8* %42, i8** %5
br label %13
43: ; preds = %30
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %5
%46 = load i8, i8* %44
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %6
store i8 %46, i8* %47
br label %13
49: ; preds = %13
%50 = load i8*, i8** %6
store i8 0, i8* %50
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"EsCaPe\00"
@.str.1 = [6 x i8] c"CoMmA\00"
define i32 @translate_back_escape_chars(i8* %0, i8* nocapture writeonly %1) {
%3 = tail call signext i16 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = tail call signext i16 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %30, label %7
7: ; preds = %2
%8 = sext i16 %3 to i64
%9 = sext i16 %4 to i64
br label %10
10: ; preds = %7, %17
%11 = phi i8* [ %0, %7 ], [ %18, %17 ]
%12 = phi i8* [ %1, %7 ], [ %19, %17 ]
%13 = tail call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i16 signext %4)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %10
store i8 44, i8* %12
%16 = getelementptr inbounds i8, i8* %11, i64 %9
br label %17
17: ; preds = %15, %25, %27
%18 = phi i8* [ %16, %15 ], [ %26, %25 ], [ %28, %27 ]
%19 = getelementptr inbounds i8, i8* %12, i64 1
%20 = load i8, i8* %18
%21 = icmp eq i8 %20, 0
br i1 %21, label %30, label %10
22: ; preds = %10
%23 = tail call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i16 signext %3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
store i8 92, i8* %12
%26 = getelementptr inbounds i8, i8* %11, i64 %8
br label %17
27: ; preds = %22
%28 = getelementptr inbounds i8, i8* %11, i64 1
%29 = load i8, i8* %11
store i8 %29, i8* %12
br label %17
30: ; preds = %17, %2
%31 = phi i8* [ %1, %2 ], [ %19, %17 ]
store i8 0, i8* %31
ret i32 0
}