#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_GetContainingDirectoryStaticN(char *,
                                                        unsigned long const);
char *malloc(unsigned long const);
int /*<<< orphan*/ memcpy(char *, char const *const, unsigned long const);
unsigned long strlen(char const *const);
char *Athena_GetContainingDirectory(const char *const in) {
  if (in[0] == '\0')
    return NULL;
  else {
    const unsigned long in_len = strlen(in);
    char *r_path = malloc(in_len + 1);
    memcpy(r_path, in, in_len + 1);
    Athena_GetContainingDirectoryStaticN(r_path, in_len);
    return r_path;
  }
}


x86 assembly (clang, -O0):
<Athena_GetContainingDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1169 <Athena_GetContainingDirectory+0x29>
movq   $0x0,-0x8(%rbp)
jmp    11b1 <Athena_GetContainingDirectory+0x71>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <Athena_GetContainingDirectoryStaticN@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Athena_GetContainingDirectory>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     1182 <Athena_GetContainingDirectory+0x42>
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r15
lea    0x1(%rax),%r12
mov    %r12,%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1050 <memcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <Athena_GetContainingDirectoryStaticN@plt>
jmp    1185 <Athena_GetContainingDirectory+0x45>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @Athena_GetContainingDirectory(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %2
br label %27
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i64 @strlen(i8* %13)
store i64 %14, i64* %4
%15 = load i64, i64* %4
%16 = add i64 %15, 1
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = load i8*, i8** %3
%20 = load i64, i64* %4
%21 = add i64 %20, 1
%22 = call i32 @memcpy(i8* %18, i8* %19, i64 %21)
%23 = load i8*, i8** %5
%24 = load i64, i64* %4
%25 = call i32 @Athena_GetContainingDirectoryStaticN(i8* %23, i64 %24)
%26 = load i8*, i8** %5
store i8* %26, i8** %2
br label %27
27: ; preds = %12, %11
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
define i8* @Athena_GetContainingDirectory(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call i64 @strlen(i8* %0)
%6 = add i64 %5, 1
%7 = tail call i8* @malloc(i64 %6)
%8 = tail call i32 @memcpy(i8* %7, i8* %0, i64 %6)
%9 = tail call i32 @Athena_GetContainingDirectoryStaticN(i8* %7, i64 %5)
br label %10
10: ; preds = %1, %4
%11 = phi i8* [ %7, %4 ], [ null, %1 ]
ret i8* %11
}