#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*/ assert(int);
char *filename(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char *, char *);
void test_filename() {
  char *f = filename("asdf.txt");
  assert(strcmp(f, "asdf.txt") == 0);
  free(f);
  f = filename("/foo/bar/asdf.txt");
  assert(strcmp(f, "asdf.txt") == 0);
  free(f);
  f = filename("/foo/bar/");
  assert(strcmp(f, "bar") == 0);
  free(f);
  f = filename(".");
  assert(f == NULL);
  f = filename("..");
  assert(f == NULL);
  f = filename("/foo/bar/.");
  assert(f == NULL);
  f = filename("/foo/bar/..");
  assert(f == NULL);
}


x86 assembly (clang, -O0):
<test_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeba(%rip),%rdi
call   1060 <filename@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
lea    0xe77(%rip),%rdi
call   1060 <filename@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
lea    0xe4f(%rip),%rdi
call   1060 <filename@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
lea    0xe38(%rip),%rdi
call   1060 <filename@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe15(%rip),%rdi
call   1060 <filename@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xddf(%rip),%rdi
call   1060 <filename@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xdc8(%rip),%rdi
call   1060 <filename@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_filename>:
push   %r14
push   %rbx
push   %rax
lea    0xebe(%rip),%r14
mov    %r14,%rdi
call   1060 <filename@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe82(%rip),%rdi
call   1060 <filename@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe64(%rip),%rdi
call   1060 <filename@plt>
mov    %rax,%rbx
lea    0xe5f(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe53(%rip),%rdi
call   1060 <filename@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
lea    0xe38(%rip),%rdi
call   1060 <filename@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
lea    0xe0a(%rip),%rdi
call   1060 <filename@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
lea    0xdfb(%rip),%rdi
call   1060 <filename@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <assert@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"asdf.txt\00"
@.str.1 = [18 x i8] c"/foo/bar/asdf.txt\00"
@.str.2 = [10 x i8] c"/foo/bar/\00"
@.str.3 = [4 x i8] c"bar\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [3 x i8] c"..\00"
@.str.6 = [11 x i8] c"/foo/bar/.\00"
@.str.7 = [12 x i8] c"/foo/bar/..\00"
define void @test_filename() {
%1 = alloca i8*
%2 = call i8* @filename(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %2, i8** %1
%3 = load i8*, i8** %1
%4 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i8*, i8** %1
%9 = call i32 @free(i8* %8)
%10 = call i8* @filename(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i8* %10, i8** %1
%11 = load i8*, i8** %1
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %1
%17 = call i32 @free(i8* %16)
%18 = call i8* @filename(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i8* %18, i8** %1
%19 = load i8*, i8** %1
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i8*, i8** %1
%25 = call i32 @free(i8* %24)
%26 = call i8* @filename(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %26, i8** %1
%27 = load i8*, i8** %1
%28 = icmp eq i8* %27, null
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = call i8* @filename(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i8* %31, i8** %1
%32 = load i8*, i8** %1
%33 = icmp eq i8* %32, null
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = call i8* @filename(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
store i8* %36, i8** %1
%37 = load i8*, i8** %1
%38 = icmp eq i8* %37, null
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = call i8* @filename(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
store i8* %41, i8** %1
%42 = load i8*, i8** %1
%43 = icmp eq i8* %42, null
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"asdf.txt\00"
@.str.1 = [18 x i8] c"/foo/bar/asdf.txt\00"
@.str.2 = [10 x i8] c"/foo/bar/\00"
@.str.3 = [4 x i8] c"bar\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [3 x i8] c"..\00"
@.str.6 = [11 x i8] c"/foo/bar/.\00"
@.str.7 = [12 x i8] c"/foo/bar/..\00"
define void @test_filename() {
%1 = tail call i8* @filename(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 @free(i8* %1)
%7 = tail call i8* @filename(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = tail call i32 @free(i8* %7)
%13 = tail call i8* @filename(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i32 @free(i8* %13)
%19 = tail call i8* @filename(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i8* %19, null
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = tail call i8* @filename(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i8* %23, null
%25 = zext i1 %24 to i32
%26 = tail call i32 @assert(i32 %25)
%27 = tail call i8* @filename(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%28 = icmp eq i8* %27, null
%29 = zext i1 %28 to i32
%30 = tail call i32 @assert(i32 %29)
%31 = tail call i8* @filename(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%32 = icmp eq i8* %31, null
%33 = zext i1 %32 to i32
%34 = tail call i32 @assert(i32 %33)
ret void
}