#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 *malloc(size_t);
char *strdup(char *);
size_t strlen(char *);
char *strncpy(char *, char *, size_t);
char *sh_unquote(char *string) {
  size_t len = 0;
  char *str_ptr = string;
  char *return_string = NULL;
  if (string == NULL) {
    return NULL;
  }
  if (*str_ptr == '\'' || *str_ptr == '"') {
    str_ptr++;
    len = strlen(str_ptr);
    return_string = malloc(len * sizeof(*string));
    return_string = strncpy(return_string, str_ptr, len - 1);
    return_string[len - 1] = '\0';
  } else {
    return_string = strdup(string);
  }
  return return_string;
}


x86 assembly (clang, -O0):
<sh_unquote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117c <sh_unquote+0x3c>
movq   $0x0,-0x8(%rbp)
jmp    1209 <sh_unquote+0xc9>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
je     119c <sh_unquote+0x5c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    11f4 <sh_unquote+0xb4>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
shl    $0x0,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    $0x1,%rdx
call   1030 <strncpy@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1201 <sh_unquote+0xc1>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sh_unquote>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1188 <sh_unquote+0x48>
mov    %rdi,%rbx
mov    (%rdi),%al
cmp    $0x27,%al
je     1157 <sh_unquote+0x17>
cmp    $0x22,%al
jne    1194 <sh_unquote+0x54>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
lea    -0x1(%r15),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
movb   $0x0,-0x1(%r14,%r15,1)
jmp    118b <sh_unquote+0x4b>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <strdup@plt>

LLVM IR (-O0):
define i8* @sh_unquote(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i64 0, i64* %4
%7 = load i8*, i8** %3
store i8* %7, i8** %5
store i8* null, i8** %6
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %43
11: ; preds = %1
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 39
br i1 %15, label %21, label %16
16: ; preds = %11
%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 %38
21: ; preds = %16, %11
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %5
%24 = load i8*, i8** %5
%25 = call i64 @strlen(i8* %24)
store i64 %25, i64* %4
%26 = load i64, i64* %4
%27 = mul i64 %26, 1
%28 = call i8* @malloc(i64 %27)
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = load i8*, i8** %5
%31 = load i64, i64* %4
%32 = sub i64 %31, 1
%33 = call i8* @strncpy(i8* %29, i8* %30, i64 %32)
store i8* %33, i8** %6
%34 = load i8*, i8** %6
%35 = load i64, i64* %4
%36 = sub i64 %35, 1
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
br label %41
38: ; preds = %16
%39 = load i8*, i8** %3
%40 = call i8* @strdup(i8* %39)
store i8* %40, i8** %6
br label %41
41: ; preds = %38, %21
%42 = load i8*, i8** %6
store i8* %42, i8** %2
br label %43
43: ; preds = %41, %10
%44 = load i8*, i8** %2
ret i8* %44
}

LLVM IR (-O2):
define i8* @sh_unquote(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = load i8, i8* %0
switch i8 %4, label %12 [
i8 39, label %5
i8 34, label %5
]
5: ; preds = %3, %3
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = tail call i64 @strlen(i8* %6)
%8 = tail call i8* @malloc(i64 %7)
%9 = add i64 %7, -1
%10 = tail call i8* @strncpy(i8* dereferenceable(1) %8, i8* %6, i64 %9)
%11 = getelementptr inbounds i8, i8* %8, i64 %9
store i8 0, i8* %11
br label %14
12: ; preds = %3
%13 = tail call i8* @strdup(i8* %0)
br label %14
14: ; preds = %5, %12, %1
%15 = phi i8* [ null, %1 ], [ %8, %5 ], [ %13, %12 ]
ret i8* %15
}