#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*/ buff;

/* Variables and functions */
char *path_last_sep(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
const char *dir_name(const char *name) {
  static char buff[256];
  char *sep;
  strncpy(buff, name, sizeof(buff) - 1);
  if ((sep = path_last_sep(buff))) {
    if (sep == buff)
      return "/";
    *sep = '\0';
    return buff;
  }
  return ".";
}


x86 assembly (clang, -O0):
<dir_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0x2f09(%rip),%rdi
mov    $0xff,%edx
call   1030 <strncpy@plt>
lea    0x2ef8(%rip),%rdi
call   1040 <path_last_sep@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1193 <dir_name+0x73>
lea    0x2ede(%rip),%rax
cmp    %rax,-0x18(%rbp)
jne    117c <dir_name+0x5c>
lea    0xe8d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119e <dir_name+0x7e>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2eb6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119e <dir_name+0x7e>
lea    0xe68(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_name>:
push   %rbx
mov    %rdi,%rsi
lea    0x2f15(%rip),%rbx
mov    %rbx,%rdi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <path_last_sep@plt>
test   %rax,%rax
je     114f <dir_name+0x2f>
cmp    %rbx,%rax
je     1158 <dir_name+0x38>
movb   $0x0,(%rax)
jmp    115f <dir_name+0x3f>
lea    0xeac(%rip),%rbx
jmp    115f <dir_name+0x3f>
lea    0xea1(%rip),%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@dir_name.buff = internal global [256 x i8] zeroinitializer
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
define i8* @dir_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @dir_name.buff, i64 0, i64 0), i8* %5, i32 255)
%7 = call i8* @path_last_sep(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @dir_name.buff, i64 0, i64 0))
store i8* %7, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, getelementptr inbounds ([256 x i8], [256 x i8]* @dir_name.buff, i64 0, i64 0)
br i1 %11, label %12, label %13
12: ; preds = %9
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2
br label %16
13: ; preds = %9
%14 = load i8*, i8** %4
store i8 0, i8* %14
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @dir_name.buff, i64 0, i64 0), i8** %2
br label %16
15: ; preds = %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %16
16: ; preds = %15, %13, %12
%17 = load i8*, i8** %2
ret i8* %17
}

LLVM IR (-O2):
@dir_name.buff = internal global [256 x i8] zeroinitializer
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
define i8* @dir_name(i8* %0) {
%2 = tail call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @dir_name.buff, i64 0, i64 0), i8* %0, i32 255)
%3 = tail call i8* @path_last_sep(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @dir_name.buff, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = icmp eq i8* %3, getelementptr inbounds ([256 x i8], [256 x i8]* @dir_name.buff, i64 0, i64 0)
br i1 %6, label %8, label %7
7: ; preds = %5
store i8 0, i8* %3
br label %8
8: ; preds = %1, %5, %7
%9 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @dir_name.buff, i64 0, i64 0), %7 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %1 ]
ret i8* %9
}