#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*/ strcmp(char *, char const *);
char *strdup(char const *);
char *strrchr(char *, char);
char *dirname(const char *name) {
  char *dir = strdup(name);
  if (strrchr(dir, '/') != NULL)
    *(strrchr(dir, '/')) = '\0';
  else if (strrchr(dir, '\\') != NULL)
    *(strrchr(dir, '\\')) = '\0';
  if (!strcmp(dir, name))
    return "";
  return dir;
}


x86 assembly (clang, -O0):
<dirname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
cmp    $0x0,%rax
je     1177 <dirname+0x47>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
movb   $0x0,(%rax)
jmp    11a5 <dirname+0x75>
mov    -0x18(%rbp),%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
cmp    $0x0,%rax
je     11a0 <dirname+0x70>
mov    -0x18(%rbp),%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
movb   $0x0,(%rax)
jmp    11a5 <dirname+0x75>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11cb <dirname+0x9b>
lea    0xe3e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11d3 <dirname+0xa3>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dirname>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
jne    1163 <dirname+0x33>
mov    %rbx,%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1166 <dirname+0x36>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
lea    0xe86(%rip),%rax
cmove  %rax,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @dirname(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 92)
%7 = icmp eq i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %5, %1
%9 = phi i8* [ %3, %1 ], [ %6, %5 ]
store i8 0, i8* %9
br label %10
10: ; preds = %8, %5
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %2, i8* dereferenceable(1) %0)
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %2
ret i8* %13
}