#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*/ free(char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, scalar_t__);
char *strutil_substring(char *, scalar_t__, scalar_t__);
int strutil_ends_with(char *string, char *endtok) {
  if (strlen(endtok) > strlen(string)) {
    return 0;
  }
  char *substr = strutil_substring(string, strlen(string) - strlen(endtok),
                                   strlen(string));
  if (!strncmp(substr, endtok, strlen(endtok))) {
    free(substr);
    return 1;
  } else {
    free(substr);
    return 0;
  }
}


x86 assembly (clang, -O0):
<strutil_ends_with>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jle    1182 <strutil_ends_with+0x42>
movl   $0x0,-0x4(%rbp)
jmp    1222 <strutil_ends_with+0xe2>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
call   1040 <strutil_substring@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
call   1050 <strncmp@plt>
cmp    $0x0,%eax
jne    1212 <strutil_ends_with+0xd2>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1222 <strutil_ends_with+0xe2>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strutil_ends_with>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1060 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1060 <strlen@plt>
xor    %ebp,%ebp
mov    %rax,%rsi
sub    %rbx,%rsi
jl     119e <strutil_ends_with+0x5e>
mov    %r15,%rdi
mov    %rax,%rdx
call   1040 <strutil_substring@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1050 <strncmp@plt>
xor    %ebp,%ebp
test   %eax,%eax
sete   %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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