#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 *);
char *slice(char *, int, int);
size_t strlen(char *);
char *get_enclosed_string(char *s, char left, char right) {
  size_t length;
  char *result;
  length = strlen(s);
  if ((s[0] == left) && (s[length - 1] == right)) {
    result = slice(s, 1, -1);
    free(s);
  } else {
    result = s;
  }
  return result;
}


x86 assembly (clang, -O0):
<get_enclosed_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %rdi,-0x8(%rbp)
mov    %cl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    11a8 <get_enclosed_string+0x78>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0xa(%rbp),%ecx
cmp    %ecx,%eax
jne    11a8 <get_enclosed_string+0x78>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1040 <slice@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
jmp    11b0 <get_enclosed_string+0x80>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_enclosed_string>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
cmp    %sil,(%rdi)
jne    116e <get_enclosed_string+0x3e>
mov    %edx,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    %bpl,-0x1(%rax,%rbx,1)
jne    116e <get_enclosed_string+0x3e>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1040 <slice@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
jmp    1171 <get_enclosed_string+0x41>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @get_enclosed_string(i8* %0, i8 signext %1, i8 signext %2) {
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, %1
br i1 %5, label %6, label %15
6: ; preds = %3
%7 = tail call i64 @strlen(i8* %0)
%8 = add i64 %7, -1
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, %2
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = tail call i8* @slice(i8* %0, i32 1, i32 -1)
%14 = tail call i32 @free(i8* %0)
br label %15
15: ; preds = %3, %6, %12
%16 = phi i8* [ %13, %12 ], [ %0, %6 ], [ %0, %3 ]
ret i8* %16
}