#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 *);
unsigned int strings_length(char *);
bool strings_ends_with_imp(char *string, char *end,
                           bool (*equals_function)(char *, char *,
                                                   unsigned int)) {
  assert(string);
  assert(end);
  unsigned int string_length = strings_length(string),
               end_length = strings_length(end);
  if (end_length > string_length)
    return false;
  return equals_function(&string[string_length - end_length], end, end_length);
}


x86 assembly (clang, -O0):
<strings_ends_with_imp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strings_length@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strings_length@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jbe    1176 <strings_ends_with_imp+0x56>
movl   $0x0,-0x4(%rbp)
jmp    1195 <strings_ends_with_imp+0x75>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%ecx
sub    -0x28(%rbp),%ecx
mov    %ecx,%ecx
add    %rcx,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   *%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strings_ends_with_imp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <assert@plt>
mov    %r14,%rdi
call   1040 <assert@plt>
mov    %r15,%rdi
call   1030 <strings_length@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strings_length@plt>
sub    %eax,%ebx
jae    1162 <strings_ends_with_imp+0x42>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
add    %rbx,%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    *%rax

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

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