#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 */
struct buf {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ buf_append(struct buf *, char);
int /*<<< orphan*/ buf_append_byte(struct buf *, char);
int /*<<< orphan*/ buf_concat(struct buf *, char *);
int /*<<< orphan*/ *strchr(char *, char);
void add_name(struct buf *b, char *name) {
  if (strchr(name, '\'') == NULL) {
    buf_append(b, ' ');
    buf_append(b, '\'');
    buf_concat(b, name);
    buf_append(b, '\'');
  } else {
    buf_append(b, ' ');
    buf_append(b, '"');
    while (*name) {
      if (strchr("\"$`\\", *name))
        buf_append(b, '\\');
      buf_append_byte(b, *name);
      name += 1;
    }
    buf_append(b, '"');
  }
}


x86 assembly (clang, -O0):
<add_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x27,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    11a4 <add_name+0x64>
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
call   1050 <buf_append@plt>
mov    -0x8(%rbp),%rdi
mov    $0x27,%esi
call   1050 <buf_append@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <buf_concat@plt>
mov    -0x8(%rbp),%rdi
mov    $0x27,%esi
call   1050 <buf_append@plt>
jmp    1227 <add_name+0xe7>
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
call   1050 <buf_append@plt>
mov    -0x8(%rbp),%rdi
mov    $0x22,%esi
call   1050 <buf_append@plt>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1219 <add_name+0xd9>
mov    -0x10(%rbp),%rax
lea    0xe28(%rip),%rdi
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11f8 <add_name+0xb8>
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1050 <buf_append@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%esi
call   1030 <buf_append_byte@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11c0 <add_name+0x80>
mov    -0x8(%rbp),%rdi
mov    $0x22,%esi
call   1050 <buf_append@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x27,%esi
call   1040 <strchr@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    $0x20,%esi
call   1050 <buf_append@plt>
mov    %r14,%rdi
test   %r15,%r15
je     11d6 <add_name+0x96>
mov    $0x22,%esi
call   1050 <buf_append@plt>
mov    (%rbx),%al
mov    $0x22,%bpl
test   %al,%al
je     11ee <add_name+0xae>
add    $0x1,%rbx
lea    0xe70(%rip),%r15
jmp    11b7 <add_name+0x77>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl -0x1(%rbx),%esi
mov    %r14,%rdi
call   1030 <buf_append_byte@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11ee <add_name+0xae>
movsbl %al,%esi
mov    %r15,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a0 <add_name+0x60>
mov    %r14,%rdi
mov    $0x5c,%esi
call   1050 <buf_append@plt>
jmp    11a0 <add_name+0x60>
mov    $0x27,%esi
call   1050 <buf_append@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <buf_concat@plt>
mov    $0x27,%bpl
movzbl %bpl,%esi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <buf_append@plt>

LLVM IR (-O0):
%struct.buf = type { i32 }
@.str = [5 x i8] c"\22$`\\\00"
define void @add_name(%struct.buf* %0, i8* %1) {
%3 = alloca %struct.buf*
%4 = alloca i8*
store %struct.buf* %0, %struct.buf** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = call i32* @strchr(i8* %5, i8 signext 39)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = load %struct.buf*, %struct.buf** %3
%10 = call i32 @buf_append(%struct.buf* %9, i8 signext 32)
%11 = load %struct.buf*, %struct.buf** %3
%12 = call i32 @buf_append(%struct.buf* %11, i8 signext 39)
%13 = load %struct.buf*, %struct.buf** %3
%14 = load i8*, i8** %4
%15 = call i32 @buf_concat(%struct.buf* %13, i8* %14)
%16 = load %struct.buf*, %struct.buf** %3
%17 = call i32 @buf_append(%struct.buf* %16, i8 signext 39)
br label %45
18: ; preds = %2
%19 = load %struct.buf*, %struct.buf** %3
%20 = call i32 @buf_append(%struct.buf* %19, i8 signext 32)
%21 = load %struct.buf*, %struct.buf** %3
%22 = call i32 @buf_append(%struct.buf* %21, i8 signext 34)
br label %23
23: ; preds = %35, %18
%24 = load i8*, i8** %4
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %27, label %42
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = call i32* @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %29)
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load %struct.buf*, %struct.buf** %3
%34 = call i32 @buf_append(%struct.buf* %33, i8 signext 92)
br label %35
35: ; preds = %32, %27
%36 = load %struct.buf*, %struct.buf** %3
%37 = load i8*, i8** %4
%38 = load i8, i8* %37
%39 = call i32 @buf_append_byte(%struct.buf* %36, i8 signext %38)
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 1
store i8* %41, i8** %4
br label %23
42: ; preds = %23
%43 = load %struct.buf*, %struct.buf** %3
%44 = call i32 @buf_append(%struct.buf* %43, i8 signext 34)
br label %45
45: ; preds = %42, %8
ret void
}

LLVM IR (-O2):
%struct.buf = type { i32 }
@.str = [5 x i8] c"\22$`\\\00"
define void @add_name(%struct.buf* %0, i8* %1) {
%3 = tail call i32* @strchr(i8* %1, i8 signext 39)
%4 = icmp eq i32* %3, null
%5 = tail call i32 @buf_append(%struct.buf* %0, i8 signext 32)
br i1 %4, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @buf_append(%struct.buf* %0, i8 signext 39)
%8 = tail call i32 @buf_concat(%struct.buf* %0, i8* %1)
br label %26
9: ; preds = %2
%10 = tail call i32 @buf_append(%struct.buf* %0, i8 signext 34)
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 0
br i1 %12, label %26, label %13
13: ; preds = %9, %20
%14 = phi i8 [ %24, %20 ], [ %11, %9 ]
%15 = phi i8* [ %23, %20 ], [ %1, %9 ]
%16 = tail call i32* @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %14)
%17 = icmp eq i32* %16, null
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = tail call i32 @buf_append(%struct.buf* %0, i8 signext 92)
br label %20
20: ; preds = %18, %13
%21 = load i8, i8* %15
%22 = tail call i32 @buf_append_byte(%struct.buf* %0, i8 signext %21)
%23 = getelementptr inbounds i8, i8* %15, i64 1
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %13
26: ; preds = %20, %9, %6
%27 = phi i8 [ 39, %6 ], [ 34, %9 ], [ 34, %20 ]
%28 = tail call i32 @buf_append(%struct.buf* %0, i8 signext %27)
ret void
}