#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 */
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
char *xmalloc(int);
char *quote_path(const char *path) {
  size_t len = strlen(path);
  char *result;
  result = xmalloc((1 + len + 1 + 1) * sizeof(char));
  if (result == NULL)
    return NULL;
  result[0] = '"';
  memcpy(&result[1], path, len);
  result[1 + len] = '"';
  result[1 + len + 1] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<quote_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
add    $0x1,%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1180 <quote_path+0x50>
movq   $0x0,-0x8(%rbp)
jmp    11c5 <quote_path+0x95>
mov    -0x20(%rbp),%rax
movb   $0x22,(%rax)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
movb   $0x22,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
movb   $0x0,0x1(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quote_path>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%r15
lea    0x3(%rax),%edi
call   1040 <xmalloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     116d <quote_path+0x3d>
movb   $0x22,(%rbx)
mov    %rbx,%rdi
add    $0x1,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
movw   $0x22,0x1(%r15,%rbx,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @quote_path(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = add i32 %3, 3
%5 = tail call i8* @xmalloc(i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = add i64 %2, 2
%9 = add i64 %2, 1
store i8 34, i8* %5
%10 = getelementptr inbounds i8, i8* %5, i64 1
%11 = tail call i32 @memcpy(i8* %10, i8* %0, i64 %2)
%12 = getelementptr inbounds i8, i8* %5, i64 %9
store i8 34, i8* %12
%13 = getelementptr inbounds i8, i8* %5, i64 %8
store i8 0, i8* %13
br label %14
14: ; preds = %1, %7
ret i8* %5
}