#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*/ assert(char *);
int /*<<< orphan*/ free(char *);
char *realloc(char *, scalar_t__);
int /*<<< orphan*/ snprintf(char *, scalar_t__, char *, char *);
char *strdup(char *);
scalar_t__ strlen(char *);
char *quote_string(char *str) {
  char *s;
  assert(str);
  s = strdup(str);
  assert(s);
  str = realloc(str, strlen(str) + 3);
  assert(str);
  snprintf(str, strlen(str) + 3, "\"%s\"", s);
  free(s);
  return str;
}


x86 assembly (clang, -O0):
<quote_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %rax,%rsi
add    $0x3,%rsi
call   1070 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x18(%rbp),%rdi
mov    %rax,%rsi
add    $0x3,%rsi
mov    -0x10(%rbp),%rcx
lea    0xe20(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quote_string>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1080 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x3(%rax),%rsi
mov    %rbx,%rdi
call   1070 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x3(%rax),%rsi
lea    0xe4f(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rcx
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\22%s\22\00"
define i8* @quote_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @assert(i8* %4)
%6 = load i8*, i8** %2
%7 = call i8* @strdup(i8* %6)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @assert(i8* %8)
%10 = load i8*, i8** %2
%11 = load i8*, i8** %2
%12 = call i64 @strlen(i8* %11)
%13 = add nsw i64 %12, 3
%14 = call i8* @realloc(i8* %10, i64 %13)
store i8* %14, i8** %2
%15 = load i8*, i8** %2
%16 = call i32 @assert(i8* %15)
%17 = load i8*, i8** %2
%18 = load i8*, i8** %2
%19 = call i64 @strlen(i8* %18)
%20 = add nsw i64 %19, 3
%21 = load i8*, i8** %3
%22 = call i32 @snprintf(i8* %17, i64 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@.str = [5 x i8] c"\22%s\22\00"
define i8* @quote_string(i8* %0) {
%2 = tail call i32 @assert(i8* %0)
%3 = tail call i8* @strdup(i8* %0)
%4 = tail call i32 @assert(i8* %3)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = add nsw i64 %5, 3
%7 = tail call i8* @realloc(i8* %0, i64 %6)
%8 = tail call i32 @assert(i8* %7)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %7)
%10 = add nsw i64 %9, 3
%11 = tail call i32 @snprintf(i8* %7, i64 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3)
%12 = tail call i32 @free(i8* %3)
ret i8* %7
}