#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*/ assert(char const *);
scalar_t__ memcmp(char const *, char const *, size_t);
size_t strlen(char const *);
bool endswith(const char *s, const char *postfix) {
  size_t sl, pl;
  assert(s);
  assert(postfix);
  sl = strlen(s);
  pl = strlen(postfix);
  if (pl == 0)
    return true;
  if (sl < pl)
    return false;
  return memcmp(s + sl - pl, postfix, pl) == 0;
}


x86 assembly (clang, -O0):
<endswith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1183 <endswith+0x53>
movl   $0x1,-0x4(%rbp)
jmp    11ca <endswith+0x9a>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    119d <endswith+0x6d>
movl   $0x0,-0x4(%rbp)
jmp    11ca <endswith+0x9a>
mov    -0x10(%rbp),%rdi
add    -0x20(%rbp),%rdi
xor    %eax,%eax
sub    -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
sete   %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):
<endswith>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <assert@plt>
mov    %r14,%rdi
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %rax,%rax
je     1185 <endswith+0x55>
xor    %ecx,%ecx
cmp    %rax,%r15
jb     118a <endswith+0x5a>
add    %r15,%rbx
sub    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
jmp    118a <endswith+0x5a>
mov    $0x1,%ecx
mov    %ecx,%eax
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 i64
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32 @assert(i8* %8)
%10 = load i8*, i8** %5
%11 = call i32 @assert(i8* %10)
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %6
%14 = load i8*, i8** %5
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %7
%16 = load i64, i64* %7
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 1, i32* %3
br label %36
19: ; preds = %2
%20 = load i64, i64* %6
%21 = load i64, i64* %7
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %19
store i32 0, i32* %3
br label %36
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = load i64, i64* %6
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = load i64, i64* %7
%29 = sub i64 0, %28
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8*, i8** %5
%32 = load i64, i64* %7
%33 = call i64 @memcmp(i8* %30, i8* %31, i64 %32)
%34 = icmp eq i64 %33, 0
%35 = zext i1 %34 to i32
store i32 %35, i32* %3
br label %36
36: ; preds = %24, %23, %18
%37 = load i32, i32* %3
ret i32 %37
}

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