#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*/ strcmp(char const *, char const *);
int strlen(char const *);
bool str_ends_with(const char *str, const char *end) {
  int end_len;
  int str_len;
  if (NULL == str || NULL == end)
    return false;
  end_len = strlen(end);
  str_len = strlen(str);
  return str_len < end_len ? false : !strcmp(str + str_len - end_len, end);
}


x86 assembly (clang, -O0):
<str_ends_with>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     1148 <str_ends_with+0x28>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    1154 <str_ends_with+0x34>
movl   $0x0,-0x4(%rbp)
jmp    11b8 <str_ends_with+0x98>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1182 <str_ends_with+0x62>
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
jmp    11b2 <str_ends_with+0x92>
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
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%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   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     116f <str_ends_with+0x4f>
mov    %rsi,%r14
test   %rsi,%rsi
je     116f <str_ends_with+0x4f>
mov    %rdi,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %r15d,%eax
jl     116f <str_ends_with+0x4f>
cltq
add    %rax,%rbx
movslq %r15d,%rax
sub    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
xor    %ebp,%ebp
test   %eax,%eax
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @str_ends_with(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** %4
%9 = icmp eq i8* null, %8
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp eq i8* null, %11
br i1 %12, label %13, label %14
13: ; preds = %10, %2
store i32 0, i32* %3
br label %39
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %6
%17 = load i8*, i8** %4
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %14
br label %37
23: ; preds = %14
%24 = load i8*, i8** %4
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = sub i64 0, %29
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = load i8*, i8** %5
%33 = call i32 @strcmp(i8* %31, i8* %32)
%34 = icmp ne i32 %33, 0
%35 = xor i1 %34, true
%36 = zext i1 %35 to i32
br label %37
37: ; preds = %23, %22
%38 = phi i32 [ 0, %22 ], [ %36, %23 ]
store i32 %38, i32* %3
br label %39
39: ; preds = %37, %13
%40 = load i32, i32* %3
ret i32 %40
}

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