#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*/ die(char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int ends_with(char *string, char *with) {
  if (!string || !with)
    die("strlen(empty-string)\n");
  int sl = strlen(string);
  int wl = strlen(with);
  if (wl > sl)
    return 0;
  return strncmp(string + (sl - wl), with, wl) ? 0 : 1;
}


x86 assembly (clang, -O0):
<ends_with>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1156 <ends_with+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1162 <ends_with+0x32>
lea    0xea3(%rip),%rdi
call   1050 <die@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    1192 <ends_with+0x62>
movl   $0x0,-0x4(%rbp)
jmp    11c1 <ends_with+0x91>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
sub    -0x20(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <strncmp@plt>
mov    %rax,%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ends_with>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     1144 <ends_with+0x14>
test   %r14,%r14
jne    1150 <ends_with+0x20>
lea    0xeb5(%rip),%rdi
call   1050 <die@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
xor    %ecx,%ecx
sub    %eax,%ebp
jl     1183 <ends_with+0x53>
movslq %ebp,%rcx
add    %rcx,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"strlen(empty-string)\0A\00"
define i32 @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 ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %10, %2
%14 = call i32 @die(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = load i8*, i8** %4
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %6
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = load i32, i32* %6
%22 = icmp sgt i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %15
store i32 0, i32* %3
br label %37
24: ; preds = %15
%25 = load i8*, i8** %4
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = sub nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %25, i64 %29
%31 = load i8*, i8** %5
%32 = load i32, i32* %7
%33 = call i64 @strncmp(i8* %30, i8* %31, i32 %32)
%34 = icmp ne i64 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i32 0, i32 1
store i32 %36, i32* %3
br label %37
37: ; preds = %24, %23
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [22 x i8] c"strlen(empty-string)\0A\00"
define i32 @ends_with(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @die(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %2, %6
%9 = tail call i32 @strlen(i8* %0)
%10 = tail call i32 @strlen(i8* %1)
%11 = icmp slt i32 %9, %10
br i1 %11, label %19, label %12
12: ; preds = %8
%13 = sub nsw i32 %9, %10
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = tail call i64 @strncmp(i8* %15, i8* %1, i32 %10)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %8, %12
%20 = phi i32 [ %18, %12 ], [ 0, %8 ]
ret i32 %20
}