#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__ strcmp(char const *, char const *);
size_t strlen(char const *);
bool endswith(const char *haystack, const char *needle) {
  size_t hlen;
  size_t nlen;
  if (haystack == NULL || needle == NULL)
    return false;
  hlen = strlen(haystack);
  nlen = strlen(needle);
  if (hlen < nlen)
    return false;
  return strcmp(haystack + hlen - nlen, needle) == 0;
}


x86 assembly (clang, -O0):
<endswith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <endswith+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1152 <endswith+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11af <endswith+0x8f>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1186 <endswith+0x66>
movl   $0x0,-0x4(%rbp)
jmp    11af <endswith+0x8f>
mov    -0x10(%rbp),%rdi
add    -0x20(%rbp),%rdi
xor    %eax,%eax
sub    -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@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   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     1168 <endswith+0x48>
mov    %rsi,%r14
test   %rsi,%rsi
je     1168 <endswith+0x48>
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %rax,%r15
jb     1168 <endswith+0x48>
add    %r15,%rbx
sub    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
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 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %10, %2
store i32 0, i32* %3
br label %34
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %6
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
store i64 %18, i64* %7
%19 = load i64, i64* %6
%20 = load i64, i64* %7
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %14
store i32 0, i32* %3
br label %34
23: ; preds = %14
%24 = load i8*, i8** %4
%25 = load i64, i64* %6
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = load i64, i64* %7
%28 = sub i64 0, %27
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8*, i8** %5
%31 = call i64 @strcmp(i8* %29, i8* %30)
%32 = icmp eq i64 %31, 0
%33 = zext i1 %32 to i32
store i32 %33, i32* %3
br label %34
34: ; preds = %23, %22, %13
%35 = load i32, i32* %3
ret i32 %35
}

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