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


x86 assembly (clang, -O0):
<has_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x21(%rbp)
jb     1186 <has_suffix+0x66>
mov    -0x8(%rbp),%rdi
add    -0x18(%rbp),%rdi
xor    %eax,%eax
sub    -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%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):
<has_suffix>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
xor    %ecx,%ecx
cmp    %rax,%r15
jb     115d <has_suffix+0x3d>
add    %r15,%rbx
sub    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <bcmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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