#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 */
typedef int /*<<< orphan*/ dir_only;
typedef int /*<<< orphan*/ canonic;

/* Variables and functions */
int /*<<< orphan*/ canonicalize_path(char *, char *, int);
int /*<<< orphan*/ copy_str(char *, int, char const *);
int /*<<< orphan*/ remove_last_path_component(char *);
char *strdup(char *);
int /*<<< orphan*/ strlen(char const *);
char *pretty_dir_path(const char path[]) {
  char dir_only[strlen(path) + 1];
  char canonic[4096];
  copy_str(dir_only, sizeof(dir_only), path);
  remove_last_path_component(dir_only);
  canonicalize_path(dir_only, canonic, sizeof(canonic));
  return strdup(canonic);
}


x86 assembly (clang, -O0):
<pretty_dir_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x1028(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
call   1050 <copy_str@plt>
mov    -0x1028(%rbp),%rdi
call   1040 <remove_last_path_component@plt>
mov    -0x1028(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <canonicalize_path@plt>
lea    -0x1020(%rbp),%rdi
call   1070 <strdup@plt>
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pretty_dir_path>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rdi,%r14
call   1030 <strlen@plt>
lea    0x1(%rax),%esi
mov    %rsp,%rbx
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <copy_str@plt>
mov    %rbx,%rdi
call   1040 <remove_last_path_component@plt>
lea    -0x1010(%rbp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1000,%edx
call   1060 <canonicalize_path@plt>
mov    %r14,%rdi
call   1070 <strdup@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @pretty_dir_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [4096 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = add nsw i32 %7, 1
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i8, i64 %9
store i64 %9, i64* %4
%12 = trunc i64 %9 to i32
%13 = load i8*, i8** %2
%14 = call i32 @copy_str(i8* %11, i32 %12, i8* %13)
%15 = call i32 @remove_last_path_component(i8* %11)
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%17 = call i32 @canonicalize_path(i8* %11, i8* %16, i32 4096)
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%19 = call i8* @strdup(i8* %18)
%20 = load i8*, i8** %3
ret i8* %19
}

LLVM IR (-O2):
define noalias i8* @pretty_dir_path(i8* %0) {
%2 = alloca [4096 x i8]
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%8 = call i32 @copy_str(i8* %6, i32 %4, i8* %0)
%9 = call i32 @remove_last_path_component(i8* %6)
%10 = call i32 @canonicalize_path(i8* %6, i8* %7, i32 4096)
%11 = call i8* @strdup(i8* %7)
ret i8* %11
}