#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*/ Athena_IsDirectory(char *);
void Athena_GetContainingDirectoryStaticN(char *in, unsigned len) {
  if (len && (!Athena_IsDirectory(in))) {
    char *end = in + len - 1;
    if ((*end == '/')) {
      end--;
    }
    while (end != in && !(*end == '/'))
      end--;
    if (end != in) {
      end[0] = '\0';
    } else {
      in[0] = '.';
      in[1] = '\0';
    }
  }
}


x86 assembly (clang, -O0):
<Athena_GetContainingDirectoryStaticN>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11e2 <Athena_GetContainingDirectoryStaticN+0xd2>
mov    -0x8(%rbp),%rdi
call   1030 <Athena_IsDirectory@plt>
cmp    $0x0,%eax
jne    11e2 <Athena_GetContainingDirectoryStaticN+0xd2>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1169 <Athena_GetContainingDirectoryStaticN+0x59>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    116e <Athena_GetContainingDirectoryStaticN+0x5e>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
je     1193 <Athena_GetContainingDirectoryStaticN+0x83>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
sete   %al
xor    $0xff,%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11a3 <Athena_GetContainingDirectoryStaticN+0x93>
jmp    11b4 <Athena_GetContainingDirectoryStaticN+0xa4>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    116e <Athena_GetContainingDirectoryStaticN+0x5e>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     11ce <Athena_GetContainingDirectoryStaticN+0xbe>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11dd <Athena_GetContainingDirectoryStaticN+0xcd>
mov    -0x8(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    11e2 <Athena_GetContainingDirectoryStaticN+0xd2>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Athena_GetContainingDirectoryStaticN>:
push   %rbp
push   %rbx
push   %rax
test   %esi,%esi
je     116b <Athena_GetContainingDirectoryStaticN+0x5b>
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <Athena_IsDirectory@plt>
test   %eax,%eax
jne    116b <Athena_GetContainingDirectoryStaticN+0x5b>
mov    %ebp,%eax
xor    %ecx,%ecx
cmpb   $0x2f,-0x1(%rbx,%rax,1)
lea    -0x1(%rbx,%rax,1),%rdx
sete   %cl
sub    %rcx,%rdx
cmp    %rbx,%rdx
je     115c <Athena_GetContainingDirectoryStaticN+0x4c>
neg    %rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
nopl   0x0(%rax,%rax,1)
cmpb   $0x2f,(%rbx,%rax,1)
je     1165 <Athena_GetContainingDirectoryStaticN+0x55>
add    $0xffffffffffffffff,%rax
jne    1150 <Athena_GetContainingDirectoryStaticN+0x40>
movb   $0x2e,(%rbx)
add    $0x1,%rbx
jmp    1168 <Athena_GetContainingDirectoryStaticN+0x58>
add    %rax,%rbx
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @Athena_GetContainingDirectoryStaticN(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %54
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i32 @Athena_IsDirectory(i8* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %54, label %12
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = load i32, i32* %4
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = getelementptr inbounds i8, i8* %16, i64 -1
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 47
br i1 %21, label %22, label %25
22: ; preds = %12
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i32 -1
store i8* %24, i8** %5
br label %25
25: ; preds = %22, %12
br label %26
26: ; preds = %38, %25
%27 = load i8*, i8** %5
%28 = load i8*, i8** %3
%29 = icmp ne i8* %27, %28
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load i8*, i8** %5
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 47
%35 = xor i1 %34, true
br label %36
36: ; preds = %30, %26
%37 = phi i1 [ false, %26 ], [ %35, %30 ]
br i1 %37, label %38, label %41
38: ; preds = %36
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i32 -1
store i8* %40, i8** %5
br label %26
41: ; preds = %36
%42 = load i8*, i8** %5
%43 = load i8*, i8** %3
%44 = icmp ne i8* %42, %43
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i8*, i8** %5
%47 = getelementptr inbounds i8, i8* %46, i64 0
store i8 0, i8* %47
br label %53
48: ; preds = %41
%49 = load i8*, i8** %3
%50 = getelementptr inbounds i8, i8* %49, i64 0
store i8 46, i8* %50
%51 = load i8*, i8** %3
%52 = getelementptr inbounds i8, i8* %51, i64 1
store i8 0, i8* %52
br label %53
53: ; preds = %48, %45
br label %54
54: ; preds = %53, %8, %2
ret void
}

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