#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 strlen(char const *);
scalar_t__ strncmp(char const *, char const *, int);
int endswith(const char *s, const char *suffix) {
  int s_len, suffix_len;
  if (!s || !suffix)
    return 0;
  s_len = strlen(s);
  suffix_len = strlen(suffix);
  if (s_len < suffix_len)
    return 0;
  if (strncmp(&s[s_len - suffix_len], suffix, suffix_len) == 0)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<endswith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <endswith+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1152 <endswith+0x32>
movl   $0x0,-0x4(%rbp)
jmp    11ba <endswith+0x9a>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1182 <endswith+0x62>
movl   $0x0,-0x4(%rbp)
jmp    11ba <endswith+0x9a>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
sub    -0x20(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11b3 <endswith+0x93>
movl   $0x1,-0x4(%rbp)
jmp    11ba <endswith+0x9a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endswith>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     116a <endswith+0x4a>
mov    %rsi,%r14
test   %rsi,%rsi
je     116a <endswith+0x4a>
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %eax,%r15d
jl     116a <endswith+0x4a>
movslq %r15d,%rcx
add    %rcx,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10, %2
store i32 0, i32* %3
br label %36
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %6
%17 = load i8*, i8** %5
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %7
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %14
store i32 0, i32* %3
br label %36
23: ; preds = %14
%24 = load i8*, i8** %4
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = sub nsw i32 %25, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
%30 = load i8*, i8** %5
%31 = load i32, i32* %7
%32 = call i64 @strncmp(i8* %29, i8* %30, i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %23
store i32 1, i32* %3
br label %36
35: ; preds = %23
store i32 0, i32* %3
br label %36
36: ; preds = %35, %34, %22, %13
%37 = load i32, i32* %3
ret i32 %37
}

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