#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*/ memcmp(char const *, char const *, int);
int strlen(char const *);
int str_ends_with(const char *s, int slen, const char *sub) {
  int sublen = strlen(sub);
  if (sublen > slen)
    return 0;
  return !memcmp(s + slen - sublen, sub, sublen);
}


x86 assembly (clang, -O0):
<str_ends_with>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    1157 <str_ends_with+0x37>
movl   $0x0,-0x4(%rbp)
jmp    118a <str_ends_with+0x6a>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
movslq -0x24(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_ends_with>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1030 <strlen@plt>
xor    %ecx,%ecx
cmp    %ebp,%eax
jg     115a <str_ends_with+0x3a>
movslq %ebp,%rcx
add    %rcx,%rbx
movslq %eax,%rcx
sub    %rcx,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <memcmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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