#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 *);
int endswith(const char *str, const char *suffix) {
  if (strlen(suffix) <= strlen(str)) {
    unsigned long n = strlen(str) - strlen(suffix);
    for (int i = 0; i < strlen(suffix); i++) {
      if (suffix[i] != str[n + i])
        return 0;
    }
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<endswith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jg     11d9 <endswith+0xc9>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
sub    %ecx,%eax
cltq
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jge    11cd <endswith+0xbd>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rdx
movslq -0x24(%rbp),%rsi
add    %rsi,%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11ba <endswith+0xaa>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <endswith+0xd0>
jmp    11bf <endswith+0xaf>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116b <endswith+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    11e0 <endswith+0xd0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endswith>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
xor    %r13d,%r13d
cmp    %eax,%ebp
jg     1192 <endswith+0x82>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0x1,%r13d
test   %eax,%eax
jle    1192 <endswith+0x82>
sub    %r12d,%r15d
movslq %r15d,%rax
add    %rax,%r14
xor    %ebp,%ebp
nopl   (%rax)
movzbl (%rbx,%rbp,1),%eax
cmp    (%r14,%rbp,1),%al
jne    118f <endswith+0x7f>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1170 <endswith+0x60>
jmp    1192 <endswith+0x82>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 i64
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = icmp sle i32 %9, %11
br i1 %12, label %13, label %47
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
%18 = sub nsw i32 %15, %17
%19 = sext i32 %18 to i64
store i64 %19, i64* %6
store i32 0, i32* %7
br label %20
20: ; preds = %43, %13
%21 = load i32, i32* %7
%22 = load i8*, i8** %5
%23 = call i32 @strlen(i8* %22)
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %46
25: ; preds = %20
%26 = load i8*, i8** %5
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = load i8*, i8** %4
%33 = load i64, i64* %6
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = add i64 %33, %35
%37 = getelementptr inbounds i8, i8* %32, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %31, %39
br i1 %40, label %41, label %42
41: ; preds = %25
store i32 0, i32* %3
br label %48
42: ; preds = %25
br label %43
43: ; preds = %42
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
store i32 %45, i32* %7
br label %20
46: ; preds = %20
store i32 1, i32* %3
br label %48
47: ; preds = %2
store i32 0, i32* %3
br label %48
48: ; preds = %47, %46, %41
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
define i32 @endswith(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %3, %4
br i1 %5, label %26, label %6
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i32 @strlen(i8* %1)
%9 = sub nsw i32 %7, %8
%10 = sext i32 %9 to i64
%11 = tail call i32 @strlen(i8* %1)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %17, label %26
13: ; preds = %17
%14 = tail call i32 @strlen(i8* %1)
%15 = sext i32 %14 to i64
%16 = icmp slt i64 %25, %15
br i1 %16, label %17, label %26
17: ; preds = %6, %13
%18 = phi i64 [ %25, %13 ], [ 0, %6 ]
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = load i8, i8* %19
%21 = add nsw i64 %18, %10
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %20, %23
%25 = add nuw nsw i64 %18, 1
br i1 %24, label %13, label %26
26: ; preds = %17, %13, %6, %2
%27 = phi i32 [ 0, %2 ], [ 1, %6 ], [ 0, %17 ], [ 1, %13 ]
ret i32 %27
}