#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 strlen(char const *);
char *strstr(char const *, char const *);
int ends_with(char const *str, char const *suffix) {
  size_t len = strlen(str);
  char const *p = strstr(str, suffix);
  return p && p - str + strlen(suffix) == len;
}


x86 assembly (clang, -O0):
<ends_with>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x21(%rbp)
je     118e <ends_with+0x6e>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
cmp    -0x18(%rbp),%rax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ends_with>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     1165 <ends_with+0x45>
mov    %rax,%rbx
movslq %ebp,%rbp
sub    %r15,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rcx
add    %rbx,%rcx
xor    %eax,%eax
cmp    %rbp,%rcx
sete   %al
jmp    1167 <ends_with+0x47>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ends_with(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = sext i32 %3 to i64
%8 = ptrtoint i8* %4 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 %8, %9
%11 = tail call i32 @strlen(i8* %1)
%12 = sext i32 %11 to i64
%13 = add nsw i64 %10, %12
%14 = icmp eq i64 %13, %7
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %6, %2
%17 = phi i32 [ 0, %2 ], [ %15, %6 ]
ret i32 %17
}