#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*/ memchr(char *, char, size_t);
int /*<<< orphan*/ memmove(char *, char *, size_t);
size_t strlen(char *);
char *quote_fixup(char *text) {
  size_t n = strlen(text);
  if (*text == '"' && text[n - 1] == '"' && !memchr(text + 1, '"', n - 2)) {
    text[n - 1] = 0;
    memmove(text, text + 1, n - 1);
  }
  return text;
}


x86 assembly (clang, -O0):
<quote_fixup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    11be <quote_fixup+0x8e>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x22,%eax
jne    11be <quote_fixup+0x8e>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rdx
sub    $0x2,%rdx
mov    $0x22,%esi
call   1040 <memchr@plt>
cmp    $0x0,%eax
jne    11be <quote_fixup+0x8e>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x1,%rsi
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
call   1050 <memmove@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quote_fixup>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmpb   $0x22,(%rbx)
jne    117c <quote_fixup+0x4c>
mov    %rax,%r14
cmpb   $0x22,-0x1(%rbx,%rax,1)
jne    117c <quote_fixup+0x4c>
lea    0x1(%rbx),%r15
lea    -0x2(%r14),%rdx
mov    %r15,%rdi
mov    $0x22,%esi
call   1040 <memchr@plt>
test   %eax,%eax
jne    117c <quote_fixup+0x4c>
add    $0xffffffffffffffff,%r14
movb   $0x0,(%rbx,%r14,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <memmove@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @quote_fixup(i8* returned %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 34
br i1 %4, label %5, label %17
5: ; preds = %1
%6 = add i64 %2, -1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 34
br i1 %9, label %10, label %17
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = add i64 %2, -2
%13 = tail call i32 @memchr(i8* %11, i8 signext 34, i64 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
store i8 0, i8* %7
%16 = tail call i32 @memmove(i8* %0, i8* %11, i64 %6)
br label %17
17: ; preds = %15, %10, %5, %1
ret i8* %0
}