#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 strcmp(char const *, char const *);
size_t strlen(char const *);
int strncmp(char const *, char const *, size_t);
int strcmpend(const char *s1, const char *s2) {
  size_t n1 = strlen(s1), n2 = strlen(s2);
  if (n2 > n1)
    return strcmp(s1, s2);
  else
    return strncmp(s1 + (n1 - n2), s2, n2);
}


x86 assembly (clang, -O0):
<strcmpend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jbe    117d <strcmpend+0x4d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    119c <strcmpend+0x6c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
sub    -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <strncmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcmpend>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %rax,%rbx
jae    1160 <strcmpend+0x30>
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <strcmp@plt>
add    %rbx,%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strncmp@plt>

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

LLVM IR (-O2):
define i32 @strcmpend(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 ult i64 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
br label %12
8: ; preds = %2
%9 = sub i64 %3, %4
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = tail call i32 @strncmp(i8* %10, i8* %1, i64 %4)
br label %12
12: ; preds = %8, %6
%13 = phi i32 [ %7, %6 ], [ %11, %8 ]
ret i32 %13
}