#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 *);
size_t strlen(char const *);
int ends_with(const char *name, const char *with) {
  size_t n_len = strlen(name);
  size_t w_len = strlen(with);
  if (n_len > w_len) {
    if (!strcmp(name + (n_len - w_len), with)) {
      return (n_len - w_len);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<ends_with>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
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
jbe    118e <ends_with+0x6e>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
sub    -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1189 <ends_with+0x69>
mov    -0x20(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    1195 <ends_with+0x75>
jmp    118e <ends_with+0x6e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ends_with>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
sub    %rcx,%rbx
jbe    115c <ends_with+0x3c>
add    %rbx,%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
cmovne %ecx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @ends_with(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 i64 @strlen(i8* %8)
store i64 %9, i64* %6
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %7
%12 = load i64, i64* %6
%13 = load i64, i64* %7
%14 = icmp ugt i64 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = load i64, i64* %6
%18 = load i64, i64* %7
%19 = sub i64 %17, %18
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = load i8*, i8** %5
%22 = call i32 @strcmp(i8* %20, i8* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %15
%25 = load i64, i64* %6
%26 = load i64, i64* %7
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
store i32 %28, i32* %3
br label %31
29: ; preds = %15
br label %30
30: ; preds = %29, %2
store i32 0, i32* %3
br label %31
31: ; preds = %30, %24
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
define i32 @ends_with(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = icmp ugt i64 %3, %4
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = sub i64 %3, %4
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(1) %1)
%10 = icmp eq i32 %9, 0
%11 = trunc i64 %7 to i32
%12 = select i1 %10, i32 %11, i32 0
br label %13
13: ; preds = %6, %2
%14 = phi i32 [ 0, %2 ], [ %12, %6 ]
ret i32 %14
}