#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 */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *strchr(char const *, char);
char *strdup(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void strip_quotes(char **strptr, bool needsfree) {
  const char *quotes = "\"'";
  char *newstr;
  char *end;
  char *str = *strptr;
  bool inquotes = false;
  int len = 0;
  end = str;
  while (*(end + 1) != 0) {
    len++;
    end++;
  }
  inquotes = *str == *end && strchr(quotes, *str) != NULL;
  if (inquotes) {
    newstr = calloc(len + 1, sizeof(char));
    strncpy(newstr, str + 1, len - 1);
    *strptr = newstr;
  } else {
    *strptr = strdup(str);
  }
  if (needsfree) {
    free(str);
  }
}


x86 assembly (clang, -O0):
<strip_quotes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     11b6 <strip_quotes+0x66>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    118b <strip_quotes+0x3b>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
mov    -0x28(%rbp),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x39(%rbp)
jne    11eb <strip_quotes+0x9b>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
movsbl (%rax),%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     123b <strip_quotes+0xeb>
mov    -0x38(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
add    $0x1,%rsi
mov    -0x38(%rbp),%edx
sub    $0x1,%edx
call   1040 <strncpy@plt>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    124e <strip_quotes+0xfe>
mov    -0x30(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
cmpl   $0x0,-0xc(%rbp)
je     1261 <strip_quotes+0x111>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_quotes>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
mov    (%rdi),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0x0,0x1(%rbx,%rbp,1)
lea    0x1(%rbp),%rbp
jne    1170 <strip_quotes+0x20>
mov    (%rbx),%al
cmp    -0x1(%rbx,%rbp,1),%al
jne    11b9 <strip_quotes+0x69>
movsbl %al,%esi
lea    0xe73(%rip),%rdi
call   1050 <strchr@plt>
test   %rax,%rax
je     11b9 <strip_quotes+0x69>
mov    %ebp,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r12
lea    0x1(%rbx),%rsi
add    $0xfffffffe,%ebp
mov    %rax,%rdi
mov    %ebp,%edx
call   1040 <strncpy@plt>
jmp    11c4 <strip_quotes+0x74>
mov    %rbx,%rdi
call   1070 <strdup@plt>
mov    %rax,%r12
mov    %r12,(%r15)
test   %r14d,%r14d
je     11dc <strip_quotes+0x8c>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\22'\00"
define void @strip_quotes(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %5
%11 = load i8**, i8*** %3
%12 = load i8*, i8** %11
store i8* %12, i8** %8
store i32 0, i32* %9
store i32 0, i32* %10
%13 = load i8*, i8** %8
store i8* %13, i8** %7
br label %14
14: ; preds = %20, %2
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load i32, i32* %10
%22 = add nsw i32 %21, 1
store i32 %22, i32* %10
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %7
br label %14
25: ; preds = %14
%26 = load i8*, i8** %8
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = load i8*, i8** %7
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %28, %31
br i1 %32, label %33, label %39
33: ; preds = %25
%34 = load i8*, i8** %5
%35 = load i8*, i8** %8
%36 = load i8, i8* %35
%37 = call i32* @strchr(i8* %34, i8 signext %36)
%38 = icmp ne i32* %37, null
br label %39
39: ; preds = %33, %25
%40 = phi i1 [ false, %25 ], [ %38, %33 ]
%41 = zext i1 %40 to i32
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %56
44: ; preds = %39
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
%47 = call i8* @calloc(i32 %46, i32 1)
store i8* %47, i8** %6
%48 = load i8*, i8** %6
%49 = load i8*, i8** %8
%50 = getelementptr inbounds i8, i8* %49, i64 1
%51 = load i32, i32* %10
%52 = sub nsw i32 %51, 1
%53 = call i32 @strncpy(i8* %48, i8* %50, i32 %52)
%54 = load i8*, i8** %6
%55 = load i8**, i8*** %3
store i8* %54, i8** %55
br label %60
56: ; preds = %39
%57 = load i8*, i8** %8
%58 = call i8* @strdup(i8* %57)
%59 = load i8**, i8*** %3
store i8* %58, i8** %59
br label %60
60: ; preds = %56, %44
%61 = load i32, i32* %4
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = load i8*, i8** %8
%65 = call i32 @free(i8* %64)
br label %66
66: ; preds = %63, %60
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\22'\00"
define void @strip_quotes(i8** nocapture %0, i32 %1) {
%3 = load i8*, i8** %0
br label %4
4: ; preds = %4, %2
%5 = phi i8* [ %3, %2 ], [ %7, %4 ]
%6 = phi i32 [ 0, %2 ], [ %10, %4 ]
%7 = getelementptr inbounds i8, i8* %5, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
%10 = add nuw nsw i32 %6, 1
br i1 %9, label %11, label %4
11: ; preds = %4
%12 = load i8, i8* %3
%13 = load i8, i8* %5
%14 = icmp eq i8 %12, %13
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = tail call i32* @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%17 = icmp eq i32* %16, null
br i1 %17, label %23, label %18
18: ; preds = %15
%19 = tail call i8* @calloc(i32 %10, i32 1)
%20 = getelementptr inbounds i8, i8* %3, i64 1
%21 = add nsw i32 %6, -1
%22 = tail call i32 @strncpy(i8* %19, i8* %20, i32 %21)
br label %25
23: ; preds = %11, %15
%24 = tail call i8* @strdup(i8* %3)
br label %25
25: ; preds = %23, %18
%26 = phi i8* [ %24, %23 ], [ %19, %18 ]
store i8* %26, i8** %0
%27 = icmp eq i32 %1, 0
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = tail call i32 @free(i8* %3)
br label %30
30: ; preds = %28, %25
ret void
}