#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(char const *);
char *dirname(char *);
int /*<<< orphan*/ perfx_free(char *);
char *strdup(char const *);
char *PerfxPath_GetDirectory(const char *filename) {
  char *copy;
  char *dir;
  assert(filename);
  copy = ((filename) ? strdup((filename)) : NULL);
  dir = dirname(copy);
  dir = ((dir) ? strdup((dir)) : NULL);
  perfx_free(copy);
  return dir;
}


x86 assembly (clang, -O0):
<PerfxPath_GetDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
je     1172 <PerfxPath_GetDirectory+0x32>
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    117d <PerfxPath_GetDirectory+0x3d>
xor    %eax,%eax
mov    %rax,-0x20(%rbp)
jmp    117d <PerfxPath_GetDirectory+0x3d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <dirname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11af <PerfxPath_GetDirectory+0x6f>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
jmp    11ba <PerfxPath_GetDirectory+0x7a>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    11ba <PerfxPath_GetDirectory+0x7a>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <perfx_free@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PerfxPath_GetDirectory>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <assert@plt>
test   %rbx,%rbx
je     115e <PerfxPath_GetDirectory+0x1e>
mov    %rbx,%rdi
call   1060 <strdup@plt>
mov    %rax,%r14
jmp    1161 <PerfxPath_GetDirectory+0x21>
xor    %r14d,%r14d
mov    %r14,%rdi
call   1030 <dirname@plt>
test   %rax,%rax
je     117b <PerfxPath_GetDirectory+0x3b>
mov    %rax,%rdi
call   1060 <strdup@plt>
mov    %rax,%rbx
jmp    117d <PerfxPath_GetDirectory+0x3d>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1050 <perfx_free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @PerfxPath_GetDirectory(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @assert(i8* %5)
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i8* @strdup(i8* %10)
br label %13
12: ; preds = %1
br label %13
13: ; preds = %12, %9
%14 = phi i8* [ %11, %9 ], [ null, %12 ]
store i8* %14, i8** %3
%15 = load i8*, i8** %3
%16 = call i8* @dirname(i8* %15)
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i8*, i8** %4
%21 = call i8* @strdup(i8* %20)
br label %23
22: ; preds = %13
br label %23
23: ; preds = %22, %19
%24 = phi i8* [ %21, %19 ], [ null, %22 ]
store i8* %24, i8** %4
%25 = load i8*, i8** %3
%26 = call i32 @perfx_free(i8* %25)
%27 = load i8*, i8** %4
ret i8* %27
}

LLVM IR (-O2):
define noalias i8* @PerfxPath_GetDirectory(i8* %0) {
%2 = tail call i32 @assert(i8* %0)
%3 = icmp eq i8* %0, null
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i8* @strdup(i8* %0)
br label %6
6: ; preds = %1, %4
%7 = phi i8* [ %5, %4 ], [ null, %1 ]
%8 = tail call i8* @dirname(i8* %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i8* @strdup(i8* %8)
br label %12
12: ; preds = %6, %10
%13 = phi i8* [ %11, %10 ], [ null, %6 ]
%14 = tail call i32 @perfx_free(i8* %7)
ret i8* %13
}