#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 *);
void exm_str_append_with_quotes(char *buf, const char *str) {
  if (!str)
    return;
  if (!*buf) {
    size_t l;
    l = strlen(str);
    buf[0] = '\"';
    memcpy(buf + 1, str, l);
    buf[l + 1] = '\"';
    buf[l + 2] = '\0';
  } else {
    size_t l1;
    size_t l2;
    l1 = strlen(buf);
    l2 = strlen(str);
    buf[l1] = ' ';
    buf[l1 + 1] = '\"';
    memcpy(buf + l1 + 2, str, l2);
    buf[l1 + l2 + 2] = '\"';
    buf[l1 + l2 + 3] = '\0';
  }
}


x86 assembly (clang, -O0):
<exm_str_append_with_quotes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1140 <exm_str_append_with_quotes+0x20>
jmp    1203 <exm_str_append_with_quotes+0xe3>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1195 <exm_str_append_with_quotes+0x75>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x22,(%rax)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x22,0x1(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,0x2(%rax,%rcx,1)
jmp    1203 <exm_str_append_with_quotes+0xe3>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x22,0x1(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
add    -0x20(%rbp),%rdi
add    $0x2,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x28(%rbp),%rcx
movb   $0x22,0x2(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x28(%rbp),%rcx
movb   $0x0,0x3(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exm_str_append_with_quotes>:
test   %rsi,%rsi
je     11b5 <exm_str_append_with_quotes+0x95>
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     117e <exm_str_append_with_quotes+0x5e>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
movw   $0x2220,(%rbx,%r15,1)
lea    (%rbx,%r15,1),%rdi
add    $0x2,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <memcpy@plt>
lea    (%r12,%r15,1),%rax
movb   $0x22,0x2(%rbx,%rax,1)
add    %r12,%r15
add    $0x3,%r15
jmp    11a5 <exm_str_append_with_quotes+0x85>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
movb   $0x22,(%rbx)
lea    0x1(%rbx),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <memcpy@plt>
movb   $0x22,0x1(%r15,%rbx,1)
add    $0x2,%r15
movb   $0x0,(%rbx,%r15,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @exm_str_append_with_quotes(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %29, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = tail call i64 @strlen(i8* %1)
store i8 34, i8* %0
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = tail call i32 @memcpy(i8* %9, i8* %1, i64 %8)
%11 = add i64 %8, 1
%12 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 34, i8* %12
%13 = add i64 %8, 2
br label %26
14: ; preds = %4
%15 = tail call i64 @strlen(i8* %0)
%16 = tail call i64 @strlen(i8* %1)
%17 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 32, i8* %17
%18 = add i64 %15, 1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 34, i8* %19
%20 = getelementptr inbounds i8, i8* %17, i64 2
%21 = tail call i32 @memcpy(i8* %20, i8* %1, i64 %16)
%22 = add i64 %16, %15
%23 = add i64 %22, 2
%24 = getelementptr inbounds i8, i8* %0, i64 %23
store i8 34, i8* %24
%25 = add i64 %22, 3
br label %26
26: ; preds = %7, %14
%27 = phi i64 [ %25, %14 ], [ %13, %7 ]
%28 = getelementptr inbounds i8, i8* %0, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %26, %2
ret void
}