#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__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *addslashes(char *s) {
  char p[strlen(s) * 4];
  char *t = &p[0];
  int len = 0;
  while (*s) {
    if (*s == '\"' || *s == '\'')
      *t = '\\', t++, len++;
    *t = *s;
    t++, s++;
    len++;
  }
  *t = 0;
  char *real_t = (char *)malloc(len + 1);
  strcpy(real_t, p);
  return real_t;
}


x86 assembly (clang, -O0):
<addslashes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
shl    $0x2,%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x10(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x38(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x18(%rbp)
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f3 <addslashes+0xc3>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
je     11a5 <addslashes+0x75>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
jne    11c1 <addslashes+0x91>
mov    -0x20(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1178 <addslashes+0x48>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    -0x38(%rbp),%rsi
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addslashes>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
shl    $0x2,%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
xor    %edi,%edi
mov    %r14,%rax
jmp    117a <addslashes+0x4a>
nopw   0x0(%rax,%rax,1)
movb   $0x5c,(%rax)
add    $0x1,%rax
add    $0x1,%edi
movzbl (%rbx),%ecx
mov    %cl,(%rax)
add    $0x1,%rax
add    $0x1,%rbx
add    $0x1,%edi
movzbl (%rbx),%ecx
cmp    $0x22,%cl
je     1160 <addslashes+0x30>
cmp    $0x27,%cl
je     1160 <addslashes+0x30>
test   %cl,%cl
jne    116d <addslashes+0x3d>
movb   $0x0,(%rax)
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @addslashes(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl nsw i32 %2, 2
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
br label %6
6: ; preds = %15, %1
%7 = phi i8* [ %5, %1 ], [ %19, %15 ]
%8 = phi i32 [ 0, %1 ], [ %21, %15 ]
%9 = phi i8* [ %0, %1 ], [ %20, %15 ]
%10 = load i8, i8* %9
switch i8 %10, label %15 [
i8 0, label %22
i8 34, label %11
i8 39, label %11
]
11: ; preds = %6, %6
store i8 92, i8* %7
%12 = getelementptr inbounds i8, i8* %7, i64 1
%13 = add nsw i32 %8, 1
%14 = load i8, i8* %9
br label %15
15: ; preds = %6, %11
%16 = phi i8 [ %14, %11 ], [ %10, %6 ]
%17 = phi i8* [ %12, %11 ], [ %7, %6 ]
%18 = phi i32 [ %13, %11 ], [ %8, %6 ]
store i8 %16, i8* %17
%19 = getelementptr inbounds i8, i8* %17, i64 1
%20 = getelementptr inbounds i8, i8* %9, i64 1
%21 = add nsw i32 %18, 1
br label %6
22: ; preds = %6
store i8 0, i8* %7
%23 = add nsw i32 %8, 1
%24 = tail call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = call i32 @strcpy(i8* %25, i8* %5)
ret i8* %25
}