#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 */
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int stringendswith(char *string, char *end) {
  int endlen = strlen(end);
  int stringlen = strlen(string);
  if (stringlen < endlen)
    return (0);
  if (endlen == 0)
    return (1);
  string += (stringlen - endlen);
  if (strcmp(string, end) == 0)
    return (1);
  return (0);
}


x86 assembly (clang, -O0):
<stringendswith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1160 <stringendswith+0x40>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <stringendswith+0x94>
cmpl   $0x0,-0x1c(%rbp)
jne    1176 <stringendswith+0x56>
movl   $0x1,-0x4(%rbp)
jmp    11b4 <stringendswith+0x94>
mov    -0x20(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ad <stringendswith+0x8d>
movl   $0x1,-0x4(%rbp)
jmp    11b4 <stringendswith+0x94>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringendswith>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ebp,%ecx
jl     116b <stringendswith+0x4b>
test   %ebp,%ebp
je     1166 <stringendswith+0x46>
movslq %ecx,%rax
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    116b <stringendswith+0x4b>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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