#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 *, char *);
int strlen(char *);
char *subsequence(char *, int, int);
int endswith(char string[], char substring[]) {
  int len = strlen(string);
  int lsub = strlen(substring);
  if (len < lsub)
    return -1;
  char *correct_end = subsequence(string, len - lsub, len);
  if (!strcmp(correct_end, substring))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<endswith>:
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    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1170 <endswith+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <endswith+0x7f>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1040 <subsequence@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11a8 <endswith+0x78>
movl   $0x1,-0x4(%rbp)
jmp    11af <endswith+0x7f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endswith>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
mov    %ebp,%esi
sub    %ecx,%esi
jl     1174 <endswith+0x44>
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <subsequence@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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