#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(char *);
char *dirname(char *);
int /*<<< orphan*/ free(char *);
char *strdup(char *);
char *mx_dirname(char *path) {
  char *tmp;
  char *dname;
  char *result;
  assert(path);
  tmp = strdup(path);
  if (!tmp)
    return NULL;
  dname = dirname(tmp);
  assert(dname);
  result = strdup(dname);
  free(tmp);
  return result;
}


x86 assembly (clang, -O0):
<mx_dirname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117a <mx_dirname+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    11ae <mx_dirname+0x6e>
mov    -0x18(%rbp),%rdi
call   1040 <dirname@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mx_dirname>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1060 <strdup@plt>
test   %rax,%rax
je     1187 <mx_dirname+0x47>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <dirname@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <assert@plt>
mov    %r14,%rdi
call   1060 <strdup@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
jmp    1189 <mx_dirname+0x49>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @mx_dirname(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @assert(i8* %7)
%9 = load i8*, i8** %3
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %1
store i8* null, i8** %2
br label %24
14: ; preds = %1
%15 = load i8*, i8** %4
%16 = call i8* @dirname(i8* %15)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = call i32 @assert(i8* %17)
%19 = load i8*, i8** %5
%20 = call i8* @strdup(i8* %19)
store i8* %20, i8** %6
%21 = load i8*, i8** %4
%22 = call i32 @free(i8* %21)
%23 = load i8*, i8** %6
store i8* %23, i8** %2
br label %24
24: ; preds = %14, %13
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
define noalias i8* @mx_dirname(i8* %0) {
%2 = tail call i32 @assert(i8* %0)
%3 = tail call i8* @strdup(i8* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = tail call i8* @dirname(i8* %3)
%7 = tail call i32 @assert(i8* %6)
%8 = tail call i8* @strdup(i8* %6)
%9 = tail call i32 @free(i8* %3)
br label %10
10: ; preds = %1, %5
%11 = phi i8* [ %8, %5 ], [ null, %1 ]
ret i8* %11
}