#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 */
char *strchr(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
char *strlen(char *);
int strend(char *str1, char *str2) {
  char *pt1;
  if (strlen(str2) >= strlen(str1))
    return (0);
  else {
    pt1 = str1;
    pt1 = strchr(str1, 0);
    pt1 = pt1 - strlen(str2);
    return (!strcmp(pt1, str2));
  }
}


x86 assembly (clang, -O0):
<strend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jb     1172 <strend+0x42>
movl   $0x0,-0x4(%rbp)
jmp    11c5 <strend+0x95>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%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):
<strend>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%r15
jae    1172 <strend+0x52>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
sub    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @strend(i8* %0, i8* %1) {
%3 = tail call i8* @strlen(i8* %1)
%4 = tail call i8* @strlen(i8* %0)
%5 = icmp ult i8* %3, %4
br i1 %5, label %6, label %18
6: ; preds = %2
%7 = tail call i8* @strlen(i8* %0)
%8 = ptrtoint i8* %7 to i64
%9 = getelementptr i8, i8* %0, i64 %8
%10 = tail call i8* @strlen(i8* %1)
%11 = ptrtoint i8* %9 to i64
%12 = ptrtoint i8* %10 to i64
%13 = sub i64 %11, %12
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 @strcmp(i8* dereferenceable(1) %14, i8* dereferenceable(1) %1)
%16 = icmp eq i32 %15, 0
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %2, %6
%19 = phi i32 [ %17, %6 ], [ 0, %2 ]
ret i32 %19
}