#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 *lib_malloc(size_t);
char *lib_stralloc(char const *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
char *strrchr(char const *, char);
void util_fname_split(const char *path, char **directory_return,
                      char **name_return) {
  const char *p;
  if (path == NULL) {
    *directory_return = *name_return = NULL;
    return;
  }
  p = strrchr(path, '/');
  if (p == NULL) {
    if (directory_return != NULL)
      *directory_return = NULL;
    if (name_return != NULL)
      *name_return = lib_stralloc(path);
    return;
  }
  if (directory_return != NULL) {
    *directory_return = lib_malloc((size_t)(p - path + 1));
    memcpy(*directory_return, path, p - path);
    (*directory_return)[p - path] = '\0';
  }
  if (name_return != NULL)
    *name_return = lib_stralloc(p + 1);
  return;
}


x86 assembly (clang, -O0):
<util_fname_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117a <util_fname_split+0x3a>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
jmp    1253 <util_fname_split+0x113>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d0 <util_fname_split+0x90>
cmpq   $0x0,-0x10(%rbp)
je     11ad <util_fname_split+0x6d>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11cb <util_fname_split+0x8b>
mov    -0x8(%rbp),%rdi
call   1040 <lib_stralloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    1253 <util_fname_split+0x113>
cmpq   $0x0,-0x10(%rbp)
je     122c <util_fname_split+0xec>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
sub    %rax,%rdi
add    $0x1,%rdi
call   1030 <lib_malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x0,-0x18(%rbp)
je     124e <util_fname_split+0x10e>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1040 <lib_stralloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    1253 <util_fname_split+0x113>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_fname_split>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
test   %rdi,%rdi
je     11a4 <util_fname_split+0x64>
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11b4 <util_fname_split+0x74>
mov    %rax,%r12
test   %r15,%r15
je     1196 <util_fname_split+0x56>
mov    %r12,%r13
sub    %rbx,%r13
lea    0x1(%r13),%rdi
call   1030 <lib_malloc@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1060 <memcpy@plt>
mov    (%r15),%rax
movb   $0x0,(%rax,%r13,1)
test   %r14,%r14
je     11d0 <util_fname_split+0x90>
add    $0x1,%r12
mov    %r12,%rdi
jmp    11c8 <util_fname_split+0x88>
movq   $0x0,(%r14)
movq   $0x0,(%r15)
jmp    11d0 <util_fname_split+0x90>
test   %r15,%r15
je     11c0 <util_fname_split+0x80>
movq   $0x0,(%r15)
test   %r14,%r14
je     11d0 <util_fname_split+0x90>
mov    %rbx,%rdi
call   1040 <lib_stralloc@plt>
mov    %rax,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @util_fname_split(i8* %0, i8** %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i8**, i8*** %6
store i8* null, i8** %11
%12 = load i8**, i8*** %5
store i8* null, i8** %12
br label %70
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = call i8* @strrchr(i8* %14, i8 signext 47)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %31
18: ; preds = %13
%19 = load i8**, i8*** %5
%20 = icmp ne i8** %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = load i8**, i8*** %5
store i8* null, i8** %22
br label %23
23: ; preds = %21, %18
%24 = load i8**, i8*** %6
%25 = icmp ne i8** %24, null
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i8*, i8** %4
%28 = call i8* @lib_stralloc(i8* %27)
%29 = load i8**, i8*** %6
store i8* %28, i8** %29
br label %30
30: ; preds = %26, %23
br label %70
31: ; preds = %13
%32 = load i8**, i8*** %5
%33 = icmp ne i8** %32, null
br i1 %33, label %34, label %61
34: ; preds = %31
%35 = load i8*, i8** %7
%36 = load i8*, i8** %4
%37 = ptrtoint i8* %35 to i64
%38 = ptrtoint i8* %36 to i64
%39 = sub i64 %37, %38
%40 = add nsw i64 %39, 1
%41 = call i8* @lib_malloc(i64 %40)
%42 = load i8**, i8*** %5
store i8* %41, i8** %42
%43 = load i8**, i8*** %5
%44 = load i8*, i8** %43
%45 = load i8*, i8** %4
%46 = load i8*, i8** %7
%47 = load i8*, i8** %4
%48 = ptrtoint i8* %46 to i64
%49 = ptrtoint i8* %47 to i64
%50 = sub i64 %48, %49
%51 = trunc i64 %50 to i32
%52 = call i32 @memcpy(i8* %44, i8* %45, i32 %51)
%53 = load i8**, i8*** %5
%54 = load i8*, i8** %53
%55 = load i8*, i8** %7
%56 = load i8*, i8** %4
%57 = ptrtoint i8* %55 to i64
%58 = ptrtoint i8* %56 to i64
%59 = sub i64 %57, %58
%60 = getelementptr inbounds i8, i8* %54, i64 %59
store i8 0, i8* %60
br label %61
61: ; preds = %34, %31
%62 = load i8**, i8*** %6
%63 = icmp ne i8** %62, null
br i1 %63, label %64, label %69
64: ; preds = %61
%65 = load i8*, i8** %7
%66 = getelementptr inbounds i8, i8* %65, i64 1
%67 = call i8* @lib_stralloc(i8* %66)
%68 = load i8**, i8*** %6
store i8* %67, i8** %68
br label %69
69: ; preds = %64, %61
br label %70
70: ; preds = %69, %30, %10
ret void
}

LLVM IR (-O2):
define void @util_fname_split(i8* %0, i8** %1, i8** writeonly %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %6
5: ; preds = %3
store i8* null, i8** %2
store i8* null, i8** %1
br label %32
6: ; preds = %3
%7 = tail call i8* @strrchr(i8* %0, i8 signext 47)
%8 = icmp eq i8* %7, null
%9 = icmp eq i8** %1, null
br i1 %8, label %10, label %16
10: ; preds = %6
br i1 %9, label %12, label %11
11: ; preds = %10
store i8* null, i8** %1
br label %12
12: ; preds = %11, %10
%13 = icmp eq i8** %2, null
br i1 %13, label %32, label %14
14: ; preds = %12
%15 = tail call i8* @lib_stralloc(i8* %0)
store i8* %15, i8** %2
br label %32
16: ; preds = %6
br i1 %9, label %27, label %17
17: ; preds = %16
%18 = ptrtoint i8* %7 to i64
%19 = ptrtoint i8* %0 to i64
%20 = sub i64 %18, %19
%21 = add nsw i64 %20, 1
%22 = tail call i8* @lib_malloc(i64 %21)
store i8* %22, i8** %1
%23 = trunc i64 %20 to i32
%24 = tail call i32 @memcpy(i8* %22, i8* %0, i32 %23)
%25 = load i8*, i8** %1
%26 = getelementptr inbounds i8, i8* %25, i64 %20
store i8 0, i8* %26
br label %27
27: ; preds = %17, %16
%28 = icmp eq i8** %2, null
br i1 %28, label %32, label %29
29: ; preds = %27
%30 = getelementptr inbounds i8, i8* %7, i64 1
%31 = tail call i8* @lib_stralloc(i8* %30)
store i8* %31, i8** %2
br label %32
32: ; preds = %27, %29, %12, %14, %5
ret void
}