#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 *);
char *strstr(char const *, char const *);
int cse_match_suffix(const char *full, const char *suffix) {
  int len = strlen(suffix);
  do {
    char *match = strstr(full, suffix);
    if (!match)
      return 0;
    if (!match[len] || match[len] == '/')
      return 1;
    full = match + len;
  } while (*full);
  return 0;
}


x86 assembly (clang, -O0):
<cse_match_suffix>:
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,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1164 <cse_match_suffix+0x44>
movl   $0x0,-0x4(%rbp)
jmp    11ba <cse_match_suffix+0x9a>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     118b <cse_match_suffix+0x6b>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1197 <cse_match_suffix+0x77>
movl   $0x1,-0x4(%rbp)
jmp    11ba <cse_match_suffix+0x9a>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    113c <cse_match_suffix+0x1c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cse_match_suffix>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
movslq %eax,%r15
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     116b <cse_match_suffix+0x4b>
mov    %rax,%rbx
movzbl (%rax,%r15,1),%ecx
mov    $0x1,%eax
cmp    $0x2f,%cl
je     116d <cse_match_suffix+0x4d>
add    %r15,%rbx
test   %cl,%cl
jne    1140 <cse_match_suffix+0x20>
jmp    116d <cse_match_suffix+0x4d>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @cse_match_suffix(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
br label %10
10: ; preds = %38, %2
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i8* @strstr(i8* %11, i8* %12)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %10
store i32 0, i32* %3
br label %43
17: ; preds = %10
%18 = load i8*, i8** %7
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %17
%25 = load i8*, i8** %7
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 47
br i1 %31, label %32, label %33
32: ; preds = %24, %17
store i32 1, i32* %3
br label %43
33: ; preds = %24
%34 = load i8*, i8** %7
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8* %37, i8** %4
br label %38
38: ; preds = %33
%39 = load i8*, i8** %4
%40 = load i8, i8* %39
%41 = icmp ne i8 %40, 0
br i1 %41, label %10, label %42
42: ; preds = %38
store i32 0, i32* %3
br label %43
43: ; preds = %42, %32, %16
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
define i32 @cse_match_suffix(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = sext i32 %3 to i64
br label %5
5: ; preds = %9, %2
%6 = phi i8* [ %0, %2 ], [ %10, %9 ]
%7 = tail call i8* @strstr(i8* dereferenceable(1) %6, i8* dereferenceable(1) %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %7, i64 %4
%11 = load i8, i8* %10
switch i8 %11, label %5 [
i8 0, label %12
i8 47, label %12
]
12: ; preds = %9, %9, %5
%13 = phi i32 [ 1, %9 ], [ 1, %9 ], [ 0, %5 ]
ret i32 %13
}