#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 strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
int compare_filename(char *filename, char *match) {
  char *lasttoken, *token;
  char temp[256];
  if (strlen(filename) == strlen(match))
    return strcmp(filename, match);
  if (filename[strlen(filename) - 1] == '/')
    return 1;
  strcpy(temp, filename);
  for (lasttoken = token = strtok(temp, "/"); token != NULL;
       token = strtok(NULL, "/"))
    lasttoken = token;
  if (lasttoken == NULL)
    return 1;
  else
    return strcmp(lasttoken, match);
}


x86 assembly (clang, -O0):
<compare_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x134(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x134(%rbp),%eax
cmp    %ecx,%eax
jne    1190 <compare_filename+0x50>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,-0x4(%rbp)
jmp    124a <compare_filename+0x10a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x140(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11cc <compare_filename+0x8c>
movl   $0x1,-0x4(%rbp)
jmp    124a <compare_filename+0x10a>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x130(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1223 <compare_filename+0xe3>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdeb(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    11f7 <compare_filename+0xb7>
cmpq   $0x0,-0x20(%rbp)
jne    123a <compare_filename+0xfa>
movl   $0x1,-0x4(%rbp)
jmp    124a <compare_filename+0x10a>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_filename>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebp
jne    117e <compare_filename+0x3e>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <strcmp@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
mov    $0x1,%ebp
cmpb   $0x2f,-0x1(%rax,%rbx,1)
je     11df <compare_filename+0x9f>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe57(%rip),%rsi
mov    %r15,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     11df <compare_filename+0x9f>
lea    0xe43(%rip),%rbx
nopl   (%rax)
mov    %rax,%rbp
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
jne    11c0 <compare_filename+0x80>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i32 @compare_filename(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [256 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = icmp eq i32 %10, %12
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = call i32 @strcmp(i8* %15, i8* %16)
store i32 %17, i32* %3
br label %50
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %19, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 47
br i1 %27, label %28, label %29
28: ; preds = %18
store i32 1, i32* %3
br label %50
29: ; preds = %18
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%31 = load i8*, i8** %4
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%34 = call i8* @strtok(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %34, i8** %7
store i8* %34, i8** %6
br label %35
35: ; preds = %40, %29
%36 = load i8*, i8** %7
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load i8*, i8** %7
store i8* %39, i8** %6
br label %40
40: ; preds = %38
%41 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %41, i8** %7
br label %35
42: ; preds = %35
%43 = load i8*, i8** %6
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %46
45: ; preds = %42
store i32 1, i32* %3
br label %50
46: ; preds = %42
%47 = load i8*, i8** %6
%48 = load i8*, i8** %5
%49 = call i32 @strcmp(i8* %47, i8* %48)
store i32 %49, i32* %3
br label %50
50: ; preds = %46, %45, %28, %14
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i32 @compare_filename(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i32 @strlen(i8* %1)
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
br label %27
10: ; preds = %2
%11 = tail call i32 @strlen(i8* %0)
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 47
br i1 %16, label %27, label %17
17: ; preds = %10
%18 = call i32 @strcpy(i8* %4, i8* %0)
%19 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %27, label %21
21: ; preds = %17, %21
%22 = phi i8* [ %23, %21 ], [ %19, %17 ]
%23 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %21
25: ; preds = %21
%26 = call i32 @strcmp(i8* %22, i8* dereferenceable(1) %1)
br label %27
27: ; preds = %17, %10, %25, %8
%28 = phi i32 [ %9, %8 ], [ %26, %25 ], [ 1, %10 ], [ 1, %17 ]
ret i32 %28
}