#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 strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
bool endsto(char *str, int slen, char *str2) {
  if (slen)
    str += slen - strlen(str2);
  else
    str += strlen(str) - strlen(str2);
  return !strncmp(str, str2, strlen(str2));
}


x86 assembly (clang, -O0):
<endsto>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1164 <endsto+0x44>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1c(%rbp),%ecx
sub    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    118c <endsto+0x6c>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%ecx
sub    %eax,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endsto>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
test   %esi,%esi
jne    113a <endsto+0x1a>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
movslq %ebp,%rax
add    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @endsto(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%7 = load i32, i32* %5
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %3
%10 = load i32, i32* %5
%11 = load i8*, i8** %6
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %10, %12
%14 = load i8*, i8** %4
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds i8, i8* %14, i64 %15
store i8* %16, i8** %4
br label %26
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %6
%21 = call i32 @strlen(i8* %20)
%22 = sub nsw i32 %19, %21
%23 = load i8*, i8** %4
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8* %25, i8** %4
br label %26
26: ; preds = %17, %9
%27 = load i8*, i8** %4
%28 = load i8*, i8** %6
%29 = load i8*, i8** %6
%30 = call i32 @strlen(i8* %29)
%31 = call i32 @strncmp(i8* %27, i8* %28, i32 %30)
%32 = icmp ne i32 %31, 0
%33 = xor i1 %32, true
%34 = zext i1 %33 to i32
ret i32 %34
}

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