#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*/ sprintf(char *, char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strrchr(char *, char);
void mxml_dirname(char *path) {
  char *p;
  if (!path || strlen(path) == 0)
    return;
  p = strrchr(path, '/');
  if (p == 0)
    strcpy(path, ".");
  else if (p == path)
    sprintf(path, "%c", *p);
  else
    *p = 0;
  return;
}


x86 assembly (clang, -O0):
<mxml_dirname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     116a <mxml_dirname+0x2a>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    116f <mxml_dirname+0x2f>
jmp    11dc <mxml_dirname+0x9c>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a1 <mxml_dirname+0x61>
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11d7 <mxml_dirname+0x97>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11cb <mxml_dirname+0x8b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
lea    0xe44(%rip),%rsi
movsbl (%rax),%edx
call   1060 <sprintf@plt>
jmp    11d2 <mxml_dirname+0x92>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11d7 <mxml_dirname+0x97>
jmp    11dc <mxml_dirname+0x9c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mxml_dirname>:
push   %rbx
test   %rdi,%rdi
je     1148 <mxml_dirname+0x28>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1148 <mxml_dirname+0x28>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     114a <mxml_dirname+0x2a>
cmp    %rbx,%rax
je     115a <mxml_dirname+0x3a>
movb   $0x0,(%rax)
pop    %rbx
ret
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <strcpy@plt>
movb   $0x0,0x1(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"%c\00"
define void @mxml_dirname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %6, %1
br label %32
11: ; preds = %6
%12 = load i8*, i8** %2
%13 = call i8* @strrchr(i8* %12, i8 signext 47)
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %2
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %31
19: ; preds = %11
%20 = load i8*, i8** %3
%21 = load i8*, i8** %2
%22 = icmp eq i8* %20, %21
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i8*, i8** %2
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %26)
br label %30
28: ; preds = %19
%29 = load i8*, i8** %3
store i8 0, i8* %29
br label %30
30: ; preds = %28, %23
br label %31
31: ; preds = %30, %16
br label %32
32: ; preds = %31, %10
ret void
}

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