#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*/ path_remove_trailing_slashes(char *);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strrchr(char *, char);
void path_dirname(const char *path, char *dir) {
  char *c;
  strcpy(dir, path);
  path_remove_trailing_slashes(dir);
  c = strrchr(dir, '/');
  if (c) {
    for (; c >= dir && *c == '/'; c--)
      *c = 0;
    if (dir[0] == 0)
      strcpy(dir, "/");
  } else {
    strcpy(dir, ".");
  }
}


x86 assembly (clang, -O0):
<path_dirname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <path_remove_trailing_slashes@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e8 <path_dirname+0xb8>
jmp    1178 <path_dirname+0x48>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x19(%rbp)
jb     119b <path_dirname+0x6b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11ab <path_dirname+0x7b>
jmp    11c3 <path_dirname+0x93>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1178 <path_dirname+0x48>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11e3 <path_dirname+0xb3>
mov    -0x10(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11f8 <path_dirname+0xc8>
mov    -0x10(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_dirname>:
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <path_remove_trailing_slashes@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     117d <path_dirname+0x4d>
nopl   0x0(%rax)
cmp    %rbx,%rax
jb     1176 <path_dirname+0x46>
cmpb   $0x2f,(%rax)
jne    1176 <path_dirname+0x46>
movb   $0x0,(%rax)
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jae    1165 <path_dirname+0x35>
cmpb   $0x0,(%rbx)
je     1186 <path_dirname+0x56>
pop    %rbx
ret
lea    0xe7e(%rip),%rsi
jmp    118d <path_dirname+0x5d>
lea    0xe73(%rip),%rsi
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
define void @path_dirname(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @strcpy(i8* %6, i8* %7)
%9 = load i8*, i8** %4
%10 = call i32 @path_remove_trailing_slashes(i8* %9)
%11 = load i8*, i8** %4
%12 = call i8* @strrchr(i8* %11, i8 signext 47)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %42
15: ; preds = %2
br label %16
16: ; preds = %29, %15
%17 = load i8*, i8** %5
%18 = load i8*, i8** %4
%19 = icmp uge i8* %17, %18
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 47
br label %25
25: ; preds = %20, %16
%26 = phi i1 [ false, %16 ], [ %24, %20 ]
br i1 %26, label %27, label %32
27: ; preds = %25
%28 = load i8*, i8** %5
store i8 0, i8* %28
br label %29
29: ; preds = %27
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %5
br label %16
32: ; preds = %25
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = load i8*, i8** %4
%40 = call i32 @strcpy(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %41
41: ; preds = %38, %32
br label %45
42: ; preds = %2
%43 = load i8*, i8** %4
%44 = call i32 @strcpy(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %45
45: ; preds = %42, %41
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
define void @path_dirname(i8* %0, i8* %1) {
%3 = tail call i32 @strcpy(i8* %1, i8* %0)
%4 = tail call i32 @path_remove_trailing_slashes(i8* %1)
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%6 = icmp eq i8* %5, null
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = icmp ult i8* %5, %1
br i1 %8, label %16, label %9
9: ; preds = %7, %13
%10 = phi i8* [ %14, %13 ], [ %5, %7 ]
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 47
br i1 %12, label %13, label %16
13: ; preds = %9
store i8 0, i8* %10
%14 = getelementptr inbounds i8, i8* %10, i64 -1
%15 = icmp ult i8* %14, %1
br i1 %15, label %16, label %9
16: ; preds = %9, %13, %7
%17 = load i8, i8* %1
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %23
21: ; preds = %2
%22 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %16, %19, %21
ret void
}