#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*/ free(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char const *, char);
char *zmalloc(int);
char *zstrdup(char const *);
void zquotedcpy(char **dest, const char *source) {
  const char *start, *end;
  if (*dest != NULL)
    free(*dest);
  *dest = NULL;
  start = source;
  if (*start == '"') {
    start = source + 1;
    end = strrchr(start, '"');
    if (!end)
      return;
    *dest = zmalloc(end - start + 1);
    strncpy(*dest, start, end - start);
    (*dest)[end - start] = '\0';
  } else {
    *dest = zstrdup(source);
  }
}


x86 assembly (clang, -O0):
<zquotedcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     117a <zquotedcpy+0x2a>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    1223 <zquotedcpy+0xd3>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x22,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cb <zquotedcpy+0x7b>
jmp    1236 <zquotedcpy+0xe6>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1060 <zmalloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1236 <zquotedcpy+0xe6>
mov    -0x10(%rbp),%rdi
call   1070 <zstrdup@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zquotedcpy>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1168 <zquotedcpy+0x18>
call   1030 <free@plt>
movq   $0x0,(%r14)
cmpb   $0x22,(%rbx)
jne    11b4 <zquotedcpy+0x64>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x22,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11bf <zquotedcpy+0x6f>
mov    %rax,%r15
sub    %rbx,%r15
lea    0x1(%r15),%edi
call   1060 <zmalloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1040 <strncpy@plt>
mov    (%r14),%rax
movb   $0x0,(%rax,%r15,1)
jmp    11bf <zquotedcpy+0x6f>
mov    %rbx,%rdi
call   1070 <zstrdup@plt>
mov    %rax,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @zquotedcpy(i8** nocapture %0, i8* %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @free(i8* %3)
br label %7
7: ; preds = %5, %2
store i8* null, i8** %0
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 34
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %1, i64 1
%12 = tail call i8* @strrchr(i8* %11, i8 signext 34)
%13 = icmp eq i8* %12, null
br i1 %13, label %26, label %14
14: ; preds = %10
%15 = ptrtoint i8* %12 to i64
%16 = ptrtoint i8* %11 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = add i32 %18, 1
%20 = tail call i8* @zmalloc(i32 %19)
store i8* %20, i8** %0
%21 = tail call i32 @strncpy(i8* %20, i8* %11, i32 %18)
%22 = load i8*, i8** %0
%23 = getelementptr inbounds i8, i8* %22, i64 %17
store i8 0, i8* %23
br label %26
24: ; preds = %7
%25 = tail call i8* @zstrdup(i8* %1)
store i8* %25, i8** %0
br label %26
26: ; preds = %14, %24, %10
ret void
}