#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 */
size_t strlen(char const *);
int surrounded_with(const char str[], char left, char right) {
  const size_t len = strlen(str);
  return len > 2 && str[0] == left && str[len - 1] == right;
}


x86 assembly (clang, -O0):
<surrounded_with>:
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   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x2,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jbe    1178 <surrounded_with+0x68>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
movsbl -0x9(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x19(%rbp)
jne    1178 <surrounded_with+0x68>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0xa(%rbp),%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<surrounded_with>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x3,%rcx
jb     113b <surrounded_with+0x2b>
cmp    %bpl,(%rbx)
jne    113b <surrounded_with+0x2b>
xor    %eax,%eax
cmp    %r14b,-0x1(%rcx,%rbx,1)
sete   %al
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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