char *end_delim(str, str_len, quoted_comment)
char *str;
int str_len;
int quoted_comment;
{
  static char *e_delim[4];
  char **ptr, *str_ptr;
  e_delim[0] = ";";
  if (quoted_comment)
    e_delim[1] = "'end'", e_delim[2] = "'else'";
  else
    e_delim[1] = "end", e_delim[2] = "else";
  e_delim[3] = "";
  for (ptr = e_delim; ptr && *ptr && **ptr; ptr++) {
    str_ptr = str + str_len - strlen(*ptr);
    if (str_ptr >= str && !strncmp(str_ptr, *ptr, strlen(*ptr))) {
      return str_ptr;
    }
  }
  return (char *)0;
}


x86 assembly (clang, -O0):
<end_delim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
lea    0xec7(%rip),%rax
mov    %rax,0x2f00(%rip)
cmpl   $0x0,-0x18(%rbp)
je     116b <end_delim+0x4b>
lea    0xeb1(%rip),%rax
mov    %rax,0x2ef0(%rip)
lea    0xea9(%rip),%rax
mov    %rax,0x2eea(%rip)
jmp    1187 <end_delim+0x67>
lea    0xe9d(%rip),%rax
mov    %rax,0x2ecf(%rip)
lea    0xe93(%rip),%rax
mov    %rax,0x2ec9(%rip)
lea    0xe79(%rip),%rax
mov    %rax,0x2ec3(%rip)
lea    0x2ea4(%rip),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x29(%rbp)
je     11d6 <end_delim+0xb6>
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmpq   $0x0,(%rcx)
mov    %al,-0x29(%rbp)
je     11d6 <end_delim+0xb6>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11e6 <end_delim+0xc6>
jmp    127d <end_delim+0x15d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     1267 <end_delim+0x147>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1267 <end_delim+0x147>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1285 <end_delim+0x165>
jmp    126c <end_delim+0x14c>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    11a0 <end_delim+0x80>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<end_delim>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
lea    0xecd(%rip),%r15
test   %edx,%edx
lea    0xed3(%rip),%rax
lea    0xebf(%rip),%rcx
cmove  %rax,%rcx
lea    0xec5(%rip),%rax
lea    0xeb3(%rip),%rdx
cmove  %rax,%rdx
mov    %r15,0x2ee0(%rip)
mov    %rcx,0x2ee1(%rip)
lea    0x2eda(%rip),%r12
mov    %rdx,0x2edb(%rip)
lea    0xe8b(%rip),%rax
mov    %rax,0x2ed5(%rip)
movslq %esi,%r13
add    %rdi,%r13
jmp    119d <end_delim+0x7d>
nopl   0x0(%rax,%rax,1)
mov    (%r12),%r15
add    $0x8,%r12
test   %r15,%r15
je     11ca <end_delim+0xaa>
cmpb   $0x0,(%r15)
je     11ca <end_delim+0xaa>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r13,%rbx
sub    %rax,%rbx
cmp    %r14,%rbx
jb     1190 <end_delim+0x70>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1190 <end_delim+0x70>
jmp    11cc <end_delim+0xac>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@end_delim.e_delim = internal global [4 x i8*] zeroinitializer
@.str = [2 x i8] c";\00"
@.str.1 = [6 x i8] c"'end'\00"
@.str.2 = [7 x i8] c"'else'\00"
@.str.3 = [4 x i8] c"end\00"
@.str.4 = [5 x i8] c"else\00"
@.str.5 = [1 x i8] zeroinitializer
define i8* @end_delim(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @end_delim.e_delim, i64 0, i64 0)
%10 = load i32, i32* %7
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @end_delim.e_delim, i64 0, i64 1)
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @end_delim.e_delim, i64 0, i64 2)
br label %14
13: ; preds = %3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @end_delim.e_delim, i64 0, i64 1)
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @end_delim.e_delim, i64 0, i64 2)
br label %14
14: ; preds = %13, %12
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @end_delim.e_delim, i64 0, i64 3)
store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @end_delim.e_delim, i64 0, i64 0), i8*** %8
br label %15
15: ; preds = %55, %14
%16 = load i8**, i8*** %8
%17 = icmp ne i8** %16, null
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i8**, i8*** %8
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i8**, i8*** %8
%24 = load i8*, i8** %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br label %28
28: ; preds = %22, %18, %15
%29 = phi i1 [ false, %18 ], [ false, %15 ], [ %27, %22 ]
br i1 %29, label %30, label %58
30: ; preds = %28
%31 = load i8*, i8** %5
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8**, i8*** %8
%36 = load i8*, i8** %35
%37 = call i64 @strlen(i8* %36)
%38 = sub i64 0, %37
%39 = getelementptr inbounds i8, i8* %34, i64 %38
store i8* %39, i8** %9
%40 = load i8*, i8** %9
%41 = load i8*, i8** %5
%42 = icmp uge i8* %40, %41
br i1 %42, label %43, label %54
43: ; preds = %30
%44 = load i8*, i8** %9
%45 = load i8**, i8*** %8
%46 = load i8*, i8** %45
%47 = load i8**, i8*** %8
%48 = load i8*, i8** %47
%49 = call i64 @strlen(i8* %48)
%50 = call i32 @strncmp(i8* %44, i8* %46, i64 %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %43
%53 = load i8*, i8** %9
store i8* %53, i8** %4
br label %59
54: ; preds = %43, %30
br label %55
55: ; preds = %54
%56 = load i8**, i8*** %8
%57 = getelementptr inbounds i8*, i8** %56, i32 1
store i8** %57, i8*** %8
br label %15
58: ; preds = %28
store i8* null, i8** %4
br label %59
59: ; preds = %58, %52
%60 = load i8*, i8** %4
ret i8* %60
}

LLVM IR (-O2):
@end_delim.e_delim = internal unnamed_addr global [4 x i8*] zeroinitializer
@.str = [2 x i8] c";\00"
@.str.1 = [6 x i8] c"'end'\00"
@.str.2 = [7 x i8] c"'else'\00"
@.str.3 = [4 x i8] c"end\00"
@.str.4 = [5 x i8] c"else\00"
@.str.5 = [1 x i8] zeroinitializer
define i8* @end_delim(i8* %0, i32 %1, i32 %2) {
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @end_delim.e_delim, i64 0, i64 0)
%4 = icmp eq i32 %2, 0
%5 = select i1 %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%6 = select i1 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
store i8* %5, i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @end_delim.e_delim, i64 0, i64 1)
store i8* %6, i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @end_delim.e_delim, i64 0, i64 2)
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @end_delim.e_delim, i64 0, i64 3)
%7 = sext i32 %1 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
br label %9
9: ; preds = %3, %22
%10 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %3 ], [ %24, %22 ]
%11 = phi i8** [ getelementptr inbounds ([4 x i8*], [4 x i8*]* @end_delim.e_delim, i64 0, i64 0), %3 ], [ %23, %22 ]
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 0
br i1 %13, label %26, label %14
14: ; preds = %9
%15 = tail call i64 @strlen(i8* %10)
%16 = sub i64 0, %15
%17 = getelementptr inbounds i8, i8* %8, i64 %16
%18 = icmp ult i8* %17, %0
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = tail call i32 @strncmp(i8* %17, i8* %10, i64 %15)
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %14, %19
%23 = getelementptr inbounds i8*, i8** %11, i64 1
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %9
26: ; preds = %19, %22, %9
%27 = phi i8* [ %17, %19 ], [ null, %22 ], [ null, %9 ]
ret i8* %27
}