#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 */
scalar_t__ 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 = (char *)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 i64 @path_last_sep(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @dir_name.buff, i64 0, i64 0))
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, getelementptr inbounds ([256 x i8], [256 x i8]* @dir_name.buff, i64 0, i64 0)
br i1 %12, label %13, label %14
13: ; preds = %10
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2
br label %17
14: ; preds = %10
%15 = load i8*, i8** %4
store i8 0, i8* %15
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @dir_name.buff, i64 0, i64 0), i8** %2
br label %17
16: ; preds = %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %17
17: ; preds = %16, %14, %13
%18 = load i8*, i8** %2
ret i8* %18
}

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 i64 @path_last_sep(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @dir_name.buff, i64 0, i64 0))
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = icmp eq i8* %4, getelementptr inbounds ([256 x i8], [256 x i8]* @dir_name.buff, i64 0, i64 0)
br i1 %7, label %9, label %8
8: ; preds = %6
store i8 0, i8* %4
br label %9
9: ; preds = %1, %6, %8
%10 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @dir_name.buff, i64 0, i64 0), %8 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %6 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %1 ]
ret i8* %10
}