#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__ calloc(size_t, int);
scalar_t__ strchr(char *, char);
size_t strlen(char const *);
char *globit_escape(const char *istr) {
  char c, *cp, *ostr;
  size_t i;
  if (!(cp = ostr = (char *)calloc((i = strlen(istr)) + 1, 2)))
    return (NULL);
  while (i--) {
    if (strchr("\t\n \"#$&'()*:;<=>?[\\`{|}", (c = *istr++)))
      *cp++ = '\\';
    *cp++ = c;
  }
  *cp = '\0';
  return (ostr);
}


x86 assembly (clang, -O0):
<globit_escape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
mov    %rdi,-0x30(%rbp)
add    $0x1,%rdi
mov    $0x2,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1179 <globit_escape+0x49>
movq   $0x0,-0x8(%rbp)
jmp    11fe <globit_escape+0xce>
jmp    117e <globit_escape+0x4e>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x30(%rbp)
cmp    $0x0,%rax
je     11ef <globit_escape+0xbf>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
lea    0xe4e(%rip),%rdi
movsbl %al,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11d6 <globit_escape+0xa6>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x5c,(%rax)
mov    -0x11(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    117e <globit_escape+0x4e>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<globit_escape>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%r13
lea    0x1(%rax),%rdi
mov    $0x2,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     119f <globit_escape+0x6f>
test   %r13,%r13
mov    %rax,(%rsp)
je     11a3 <globit_escape+0x73>
xor    %ebp,%ebp
lea    0xe95(%rip),%r12
mov    %rax,%rbx
jmp    1180 <globit_escape+0x50>
mov    %r14b,(%rbx)
add    $0x1,%rbx
add    $0x1,%rbp
cmp    %rbp,%r13
je     11a6 <globit_escape+0x76>
movzbl (%r15,%rbp,1),%r14d
movsbl %r14b,%esi
mov    %r12,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     1170 <globit_escape+0x40>
movb   $0x5c,(%rbx)
add    $0x1,%rbx
jmp    1170 <globit_escape+0x40>
xor    %eax,%eax
jmp    11ad <globit_escape+0x7d>
mov    %rax,%rbx
movb   $0x0,(%rbx)
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"\09\0A \22#$&'()*:;<=>?[\\`{|}\00"
define i8* @globit_escape(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %7
%10 = add i64 %9, 1
%11 = call i64 @calloc(i64 %10, i32 2)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %6
store i8* %12, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %1
store i8* null, i8** %2
br label %36
15: ; preds = %1
br label %16
16: ; preds = %29, %15
%17 = load i64, i64* %7
%18 = add i64 %17, -1
store i64 %18, i64* %7
%19 = icmp ne i64 %17, 0
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
%23 = load i8, i8* %21
store i8 %23, i8* %4
%24 = call i64 @strchr(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8 signext %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
store i8 92, i8* %27
br label %29
29: ; preds = %26, %20
%30 = load i8, i8* %4
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
store i8 %30, i8* %31
br label %16
33: ; preds = %16
%34 = load i8*, i8** %5
store i8 0, i8* %34
%35 = load i8*, i8** %6
store i8* %35, i8** %2
br label %36
36: ; preds = %33, %14
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
@.str = [24 x i8] c"\09\0A \22#$&'()*:;<=>?[\\`{|}\00"
define i8* @globit_escape(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, 1
%4 = tail call i64 @calloc(i64 %3, i32 2)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %26, label %7
7: ; preds = %1
%8 = icmp eq i64 %2, 0
br i1 %8, label %24, label %9
9: ; preds = %7, %20
%10 = phi i64 [ %13, %20 ], [ %2, %7 ]
%11 = phi i8* [ %22, %20 ], [ %5, %7 ]
%12 = phi i8* [ %14, %20 ], [ %0, %7 ]
%13 = add i64 %10, -1
%14 = getelementptr inbounds i8, i8* %12, i64 1
%15 = load i8, i8* %12
%16 = tail call i64 @strchr(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8 signext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %9
%19 = getelementptr inbounds i8, i8* %11, i64 1
store i8 92, i8* %11
br label %20
20: ; preds = %18, %9
%21 = phi i8* [ %19, %18 ], [ %11, %9 ]
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8 %15, i8* %21
%23 = icmp eq i64 %13, 0
br i1 %23, label %24, label %9
24: ; preds = %20, %7
%25 = phi i8* [ %5, %7 ], [ %22, %20 ]
store i8 0, i8* %25
br label %26
26: ; preds = %1, %24
%27 = phi i8* [ %5, %24 ], [ null, %1 ]
ret i8* %27
}