char *quoted(name)
register const char *name;
{
  register char *result;
  register char *cp;
  register int c;
  if (name == ((void *)0))
    name = "";
  result = imalloc(4 * strlen(name) + 3);
  if (result == ((void *)0))
    return ((void *)0);
  cp = result;
  *cp++ = '\'';
  while ((c = *name++) != '\0')
    if (c == '\'') {
      *cp++ = c;
      *cp++ = '\\';
      *cp++ = c;
      *cp++ = c;
    } else
      *cp++ = c;
  *cp++ = '\'';
  *cp = '\0';
  return result;
}


x86 assembly (clang, -O0):
<quoted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1142 <quoted+0x22>
lea    0xec2(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
shl    $0x2,%rdi
add    $0x3,%rdi
mov    $0x0,%al
call   1040 <imalloc@plt>
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117b <quoted+0x5b>
movq   $0x0,-0x8(%rbp)
jmp    1252 <quoted+0x132>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x27,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     1231 <quoted+0x111>
cmpl   $0x27,-0x24(%rbp)
jne    1216 <quoted+0xf6>
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x5c,(%rax)
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    122c <quoted+0x10c>
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    1195 <quoted+0x75>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x27,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quoted>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
lea    0xed2(%rip),%rbx
cmovne %rdi,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x3(,%rax,4),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <imalloc@plt>
test   %eax,%eax
je     1187 <quoted+0x67>
movslq %eax,%r14
lea    0x1(%r14),%rax
movb   $0x27,(%r14)
jmp    116a <quoted+0x4a>
nopl   (%rax)
movl   $0x27275c27,(%rax)
add    $0x4,%rax
movzbl (%rbx),%ecx
add    $0x1,%rbx
cmp    $0x27,%cl
je     1160 <quoted+0x40>
test   %cl,%cl
je     1182 <quoted+0x62>
mov    %cl,(%rax)
add    $0x1,%rax
jmp    116a <quoted+0x4a>
movw   $0x27,(%rax)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @quoted(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %10
10: ; preds = %9, %1
%11 = load i8*, i8** %3
%12 = call i64 @strlen(i8* %11)
%13 = mul i64 4, %12
%14 = add i64 %13, 3
%15 = call i32 (i64, ...) bitcast (i32 (...)* @imalloc to i32 (i64, ...)*)(i64 %14)
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %10
store i8* null, i8** %2
br label %60
21: ; preds = %10
%22 = load i8*, i8** %4
store i8* %22, i8** %5
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %5
store i8 39, i8* %23
br label %25
25: ; preds = %54, %21
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
%28 = load i8, i8* %26
%29 = sext i8 %28 to i32
store i32 %29, i32* %6
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %55
31: ; preds = %25
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, 39
br i1 %33, label %34, label %49
34: ; preds = %31
%35 = load i32, i32* %6
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %5
store i8 %36, i8* %37
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %5
store i8 92, i8* %39
%41 = load i32, i32* %6
%42 = trunc i32 %41 to i8
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %5
store i8 %42, i8* %43
%45 = load i32, i32* %6
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** %5
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %5
store i8 %46, i8* %47
br label %54
49: ; preds = %31
%50 = load i32, i32* %6
%51 = trunc i32 %50 to i8
%52 = load i8*, i8** %5
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %5
store i8 %51, i8* %52
br label %54
54: ; preds = %49, %34
br label %25
55: ; preds = %25
%56 = load i8*, i8** %5
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %5
store i8 39, i8* %56
%58 = load i8*, i8** %5
store i8 0, i8* %58
%59 = load i8*, i8** %4
store i8* %59, i8** %2
br label %60
60: ; preds = %55, %20
%61 = load i8*, i8** %2
ret i8* %61
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @quoted(i8* %0) {
%2 = icmp eq i8* %0, null
%3 = select i1 %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = shl i64 %4, 2
%6 = or i64 %5, 3
%7 = tail call i32 (i64, ...) bitcast (i32 (...)* @imalloc to i32 (i64, ...)*)(i64 %6)
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i32 %7, 0
br i1 %10, label %29, label %11
11: ; preds = %1
%12 = getelementptr inbounds i8, i8* %9, i64 1
store i8 39, i8* %9
br label %13
13: ; preds = %25, %11
%14 = phi i8* [ %3, %11 ], [ %16, %25 ]
%15 = phi i8* [ %12, %11 ], [ %26, %25 ]
%16 = getelementptr inbounds i8, i8* %14, i64 1
%17 = load i8, i8* %14
switch i8 %17, label %23 [
i8 0, label %27
i8 39, label %18
]
18: ; preds = %13
%19 = getelementptr inbounds i8, i8* %15, i64 1
store i8 39, i8* %15
%20 = getelementptr inbounds i8, i8* %15, i64 2
store i8 92, i8* %19
%21 = getelementptr inbounds i8, i8* %15, i64 3
store i8 39, i8* %20
%22 = getelementptr inbounds i8, i8* %15, i64 4
store i8 39, i8* %21
br label %25
23: ; preds = %13
%24 = getelementptr inbounds i8, i8* %15, i64 1
store i8 %17, i8* %15
br label %25
25: ; preds = %23, %18
%26 = phi i8* [ %24, %23 ], [ %22, %18 ]
br label %13
27: ; preds = %13
%28 = getelementptr inbounds i8, i8* %15, i64 1
store i8 39, i8* %15
store i8 0, i8* %28
br label %29
29: ; preds = %1, %27
%30 = phi i8* [ %9, %27 ], [ null, %1 ]
ret i8* %30
}