#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 */
scalar_t__ av_malloc(int);
scalar_t__ rsh_isspecial(unsigned char);
int strlen(char const *);
char *rsh_code_name(const char *name) {
  char *newname = (char *)av_malloc(strlen(name) * 2 + 1);
  const char *s;
  char *d;
  for (s = name, d = newname; *s != '\0'; s++, d++) {
    if (rsh_isspecial((unsigned char)*s))
      *d++ = '\\';
    *d = *s;
  }
  *d = '\0';
  return newname;
}


x86 assembly (clang, -O0):
<rsh_code_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
add    $0x1,%edi
call   1030 <av_malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c7 <rsh_code_name+0x97>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1050 <rsh_isspecial@plt>
cmp    $0x0,%rax
je     119e <rsh_code_name+0x6e>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1166 <rsh_code_name+0x36>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsh_code_name>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1040 <strlen@plt>
lea    (%rax,%rax,1),%edi
add    $0x1,%edi
call   1030 <av_malloc@plt>
mov    %rax,%r14
mov    (%r15),%al
test   %al,%al
je     118d <rsh_code_name+0x5d>
add    $0x1,%r15
mov    %r14,%rbx
jmp    1177 <rsh_code_name+0x47>
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%r15),%eax
mov    %al,(%rbx)
add    $0x1,%rbx
movzbl (%r15),%eax
add    $0x1,%r15
test   %al,%al
je     1190 <rsh_code_name+0x60>
movzbl %al,%edi
call   1050 <rsh_isspecial@plt>
test   %rax,%rax
je     1160 <rsh_code_name+0x30>
movb   $0x5c,(%rbx)
add    $0x1,%rbx
jmp    1160 <rsh_code_name+0x30>
mov    %r14,%rbx
movb   $0x0,(%rbx)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @rsh_code_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = mul nsw i32 %7, 2
%9 = add nsw i32 %8, 1
%10 = call i64 @av_malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %3
%12 = load i8*, i8** %2
store i8* %12, i8** %4
%13 = load i8*, i8** %3
store i8* %13, i8** %5
br label %14
14: ; preds = %31, %1
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %36
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = call i64 @rsh_isspecial(i8 zeroext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %5
store i8 92, i8* %25
br label %27
27: ; preds = %24, %19
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = load i8*, i8** %5
store i8 %29, i8* %30
br label %31
31: ; preds = %27
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %4
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
br label %14
36: ; preds = %14
%37 = load i8*, i8** %5
store i8 0, i8* %37
%38 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
define i8* @rsh_code_name(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl nsw i32 %2, 1
%4 = or i32 %3, 1
%5 = tail call i64 @av_malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %24, label %9
9: ; preds = %1, %17
%10 = phi i8 [ %22, %17 ], [ %7, %1 ]
%11 = phi i8* [ %21, %17 ], [ %6, %1 ]
%12 = phi i8* [ %20, %17 ], [ %0, %1 ]
%13 = tail call i64 @rsh_isspecial(i8 zeroext %10)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %9
%16 = getelementptr inbounds i8, i8* %11, i64 1
store i8 92, i8* %11
br label %17
17: ; preds = %15, %9
%18 = phi i8* [ %16, %15 ], [ %11, %9 ]
%19 = load i8, i8* %12
store i8 %19, i8* %18
%20 = getelementptr inbounds i8, i8* %12, i64 1
%21 = getelementptr inbounds i8, i8* %18, i64 1
%22 = load i8, i8* %20
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %9
24: ; preds = %17, %1
%25 = phi i8* [ %6, %1 ], [ %21, %17 ]
store i8 0, i8* %25
ret i8* %6
}