#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*/ assert(int /*<<< orphan*/);
char *strrchr(char *, char);
char *xstrdup(char const *);
char *dir_up(const char *path) {
  char *slash;
  char *dir;
  assert(path != NULL);
  dir = xstrdup(path);
  slash = strrchr(dir, '/');
  assert(slash != NULL);
  if (slash == dir)
    *(slash + 1) = 0;
  else
    *slash = 0;
  return dir;
}


x86 assembly (clang, -O0):
<dir_up>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <xstrdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    119a <dir_up+0x6a>
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    11a1 <dir_up+0x71>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_up>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1040 <xstrdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,%r14
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
lea    0x1(%rbx),%rax
cmp    %rbx,%r14
cmovne %r14,%rax
movb   $0x0,(%rax)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @dir_up(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i8*, i8** %2
%10 = call i8* @xstrdup(i8* %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = call i8* @strrchr(i8* %11, i8 signext 47)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8*, i8** %3
%18 = load i8*, i8** %4
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %23
20: ; preds = %1
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8 0, i8* %22
br label %25
23: ; preds = %1
%24 = load i8*, i8** %3
store i8 0, i8* %24
br label %25
25: ; preds = %23, %20
%26 = load i8*, i8** %4
ret i8* %26
}

LLVM IR (-O2):
define i8* @dir_up(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i8* @xstrdup(i8* %0)
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %5, i8 signext 47)
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp eq i8* %6, %5
%11 = getelementptr inbounds i8, i8* %5, i64 1
%12 = select i1 %10, i8* %11, i8* %6
store i8 0, i8* %12
ret i8* %5
}