#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 */
char const *basename(char *);
char *dirname(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char const *, char *);
char *strdup(char const *);
void parsepath(const char *path, char **dirfn, char **leaffn) {
  char *duppath = strdup(path);
  const char *dn = dirname(duppath);
  if (strcmp(dn, ".") == 0) {
    *dirfn = NULL;
  } else {
    *dirfn = strdup(dn);
  }
  free(duppath);
  duppath = strdup(path);
  *leaffn = strdup(basename(duppath));
  free(duppath);
}


x86 assembly (clang, -O0):
<parsepath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <dirname@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11a8 <parsepath+0x58>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
jmp    11bb <parsepath+0x6b>
mov    -0x28(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <basename@plt>
mov    %rax,%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parsepath>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1070 <strdup@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1040 <dirname@plt>
mov    %rax,%rbx
lea    0xe84(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1193 <parsepath+0x43>
mov    %rbx,%rdi
call   1070 <strdup@plt>
jmp    1195 <parsepath+0x45>
xor    %eax,%eax
mov    %rax,(%r15)
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1070 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <basename@plt>
mov    %rax,%rdi
call   1070 <strdup@plt>
mov    %rax,(%r14)
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define void @parsepath(i8* nocapture %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = tail call i8* @strdup(i8* %0)
%5 = tail call i8* @dirname(i8* %4)
%6 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i8* @strdup(i8* %5)
br label %10
10: ; preds = %3, %8
%11 = phi i8* [ %9, %8 ], [ null, %3 ]
store i8* %11, i8** %1
%12 = tail call i32 @free(i8* %4)
%13 = tail call i8* @strdup(i8* %0)
%14 = tail call i8* @basename(i8* %13)
%15 = tail call i8* @strdup(i8* %14)
store i8* %15, i8** %2
%16 = tail call i32 @free(i8* %13)
ret void
}