int endsWith(const char *str, const char *tail) {
  if (strlen(tail) > strlen(str))
    return (0);
  else if (strlen(tail) == strlen(str))
    return strcmp_case(str, tail) == 0;
  else {
    const char *p = str + strlen(str) - strlen(tail);
    return strcmp_case(p, tail) == 0;
  }
}


x86 assembly (clang, -O0):
<endsWith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jbe    1162 <endsWith+0x42>
movl   $0x0,-0x4(%rbp)
jmp    1202 <endsWith+0xe2>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jne    11aa <endsWith+0x8a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <strcmp_case@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1202 <endsWith+0xe2>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1040 <strcmp_case@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endsWith>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rbx
ja     1169 <endsWith+0x49>
lea    (%r15,%rcx,1),%rdi
sub    %rbx,%rdi
cmp    %rcx,%rbx
cmove  %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <strcmp_case@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
pop    %rbx
pop    %r14
pop    %r15
ret

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

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