#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 const *);
scalar_t__ strchr(char const *, char const);
char *strdup(char const *);
size_t strlen(char const *);
char *strndup(char const *, size_t);
char *strdup_unquote(const char *str, const char *quotes) {
  size_t l;
  assert(str);
  l = strlen(str);
  if (l < 2)
    return strdup(str);
  if (strchr(quotes, str[0]) && str[0] == str[l - 1])
    return strndup(str + 1, l - 2);
  return strdup(str);
}


x86 assembly (clang, -O0):
<strdup_unquote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x2,-0x20(%rbp)
jae    1193 <strdup_unquote+0x43>
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11f7 <strdup_unquote+0xa7>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11ea <strdup_unquote+0x9a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11ea <strdup_unquote+0x9a>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
sub    $0x2,%rsi
call   1050 <strndup@plt>
mov    %rax,-0x8(%rbp)
jmp    11f7 <strdup_unquote+0xa7>
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strdup_unquote>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x1,%rax
jbe    11a2 <strdup_unquote+0x52>
mov    %rax,%r14
movsbl (%rbx),%esi
mov    %r15,%rdi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a2 <strdup_unquote+0x52>
mov    (%rbx),%al
cmp    -0x1(%r14,%rbx,1),%al
jne    11a2 <strdup_unquote+0x52>
add    $0x1,%rbx
add    $0xfffffffffffffffe,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <strndup@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <strdup@plt>

LLVM IR (-O0):
define i8* @strdup_unquote(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i32 @assert(i8* %7)
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = icmp ult i64 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i8* @strdup(i8* %14)
store i8* %15, i8** %3
br label %44
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = call i64 @strchr(i8* %17, i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %41
23: ; preds = %16
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = load i8*, i8** %4
%29 = load i64, i64* %6
%30 = sub i64 %29, 1
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %27, %33
br i1 %34, label %35, label %41
35: ; preds = %23
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = load i64, i64* %6
%39 = sub i64 %38, 2
%40 = call i8* @strndup(i8* %37, i64 %39)
store i8* %40, i8** %3
br label %44
41: ; preds = %23, %16
%42 = load i8*, i8** %4
%43 = call i8* @strdup(i8* %42)
store i8* %43, i8** %3
br label %44
44: ; preds = %41, %35, %13
%45 = load i8*, i8** %3
ret i8* %45
}

LLVM IR (-O2):
define noalias i8* @strdup_unquote(i8* %0, i8* %1) {
%3 = tail call i32 @assert(i8* %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = icmp ult i64 %4, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i8* @strdup(i8* %0)
br label %24
8: ; preds = %2
%9 = load i8, i8* %0
%10 = tail call i64 @strchr(i8* %1, i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %8
%13 = load i8, i8* %0
%14 = add i64 %4, -1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %13, %16
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = getelementptr inbounds i8, i8* %0, i64 1
%20 = add i64 %4, -2
%21 = tail call i8* @strndup(i8* %19, i64 %20)
br label %24
22: ; preds = %12, %8
%23 = tail call i8* @strdup(i8* %0)
br label %24
24: ; preds = %22, %18, %6
%25 = phi i8* [ %7, %6 ], [ %21, %18 ], [ %23, %22 ]
ret i8* %25
}