#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__ strcmp(char *, char const *);
scalar_t__ strlen(char const *);
scalar_t__ substr(char const *, char **, scalar_t__, scalar_t__);
int _check_ender(const char *host, const char *tld, const char *expand) {
  char *res = NULL;
  int ret = -1;
  if (substr(host, &res, (strlen(host) - strlen(tld)), strlen(tld))) {
    if (strcmp(res, tld) == 0) {
      ret = 1;
    } else {
      ret = -1;
    }
  } else {
    ret = -2;
  }
  free(res);
  return ret;
}


x86 assembly (clang, -O0):
<_check_ender>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    -0x20(%rbp),%rsi
call   1050 <substr@plt>
cmp    $0x0,%rax
je     11e5 <_check_ender+0xa5>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11d9 <_check_ender+0x99>
movl   $0x1,-0x24(%rbp)
jmp    11e0 <_check_ender+0xa0>
movl   $0xffffffff,-0x24(%rbp)
jmp    11ec <_check_ender+0xac>
movl   $0xfffffffe,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_check_ender>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movq   $0x0,0x8(%rsp)
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1050 <substr@plt>
test   %rax,%rax
je     119a <_check_ender+0x5a>
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
neg    %rax
sbb    %ebx,%ebx
or     $0x1,%ebx
jmp    119f <_check_ender+0x5f>
mov    $0xfffffffe,%ebx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @_check_ender(i8* %0, i8* %1, i8* nocapture readnone %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = sub nsw i64 %6, %7
%9 = call i64 @substr(i8* %0, i8** %4, i64 %8, i64 %7)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = call i64 @strcmp(i8* %12, i8* %1)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i32 1, i32 -1
br label %16
16: ; preds = %3, %11
%17 = phi i32 [ %15, %11 ], [ -2, %3 ]
%18 = load i8*, i8** %4
%19 = call i32 @free(i8* %18)
ret i32 %17
}