#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 */
scalar_t__ memcmp(char const *, char const *, int const);
int strlen(char const *);
int EndsWith(const char *s, const char *suffix) {
  const int suffix_len = strlen(suffix);
  if (suffix_len == 0) {
    return 1;
  }
  const int s_len = strlen(s);
  if (s_len < suffix_len) {
    return 0;
  }
  return memcmp(s + s_len - suffix_len, suffix, suffix_len) == 0;
}


x86 assembly (clang, -O0):
<EndsWith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1152 <EndsWith+0x32>
movl   $0x1,-0x4(%rbp)
jmp    11a8 <EndsWith+0x88>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1176 <EndsWith+0x56>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <EndsWith+0x88>
mov    -0x10(%rbp),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
movslq -0x1c(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EndsWith>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     116e <EndsWith+0x4e>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ebp,%ecx
jl     1173 <EndsWith+0x53>
movslq %ecx,%rax
add    %rax,%rbx
movslq %ebp,%rax
sub    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    1173 <EndsWith+0x53>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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