#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*/ free(char *);
char *strdup(char *);
char *strrchr(char *, char);
int m_splitpath(char *path, char **dir, char **file) {
  char *lastslash, *buf;
  buf = strdup(path);
  lastslash = strrchr(buf, '/');
  if (dir != NULL) {
    if (lastslash != NULL) {
      *lastslash = '\0';
      if ((*dir = strdup(buf)) == NULL) {
        free(buf);
        return -1;
      }
      lastslash++;
    } else {
      *dir = NULL;
      lastslash = buf;
    }
  } else {
    if (lastslash == NULL)
      lastslash = buf;
  }
  if (file != NULL) {
    if ((*file = strdup(lastslash)) == NULL) {
      free(buf);
      return -1;
    }
  }
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<m_splitpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d8 <m_splitpath+0xa8>
cmpq   $0x0,-0x28(%rbp)
je     11c0 <m_splitpath+0x90>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
call   1050 <strdup@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11af <m_splitpath+0x7f>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123f <m_splitpath+0x10f>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11d3 <m_splitpath+0xa3>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11f0 <m_splitpath+0xc0>
cmpq   $0x0,-0x28(%rbp)
jne    11eb <m_splitpath+0xbb>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11f0 <m_splitpath+0xc0>
cmpq   $0x0,-0x20(%rbp)
je     122f <m_splitpath+0xff>
mov    -0x28(%rbp),%rdi
call   1050 <strdup@plt>
mov    -0x20(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    122a <m_splitpath+0xfa>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123f <m_splitpath+0x10f>
jmp    122f <m_splitpath+0xff>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_splitpath>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
call   1050 <strdup@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,%rbx
test   %r12,%r12
je     117f <m_splitpath+0x4f>
test   %rbx,%rbx
je     118d <m_splitpath+0x5d>
movb   $0x0,(%rbx)
mov    %r15,%rdi
call   1050 <strdup@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     11b1 <m_splitpath+0x81>
add    $0x1,%rbx
test   %r14,%r14
jne    119d <m_splitpath+0x6d>
jmp    11ad <m_splitpath+0x7d>
test   %rbx,%rbx
cmove  %r15,%rbx
test   %r14,%r14
jne    119d <m_splitpath+0x6d>
jmp    11ad <m_splitpath+0x7d>
movq   $0x0,(%r12)
mov    %r15,%rbx
test   %r14,%r14
je     11ad <m_splitpath+0x7d>
mov    %rbx,%rdi
call   1050 <strdup@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11b1 <m_splitpath+0x81>
xor    %ebx,%ebx
jmp    11b6 <m_splitpath+0x86>
mov    $0xffffffff,%ebx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @m_splitpath(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%10 = load i8*, i8** %5
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %9
%12 = load i8*, i8** %9
%13 = call i8* @strrchr(i8* %12, i8 signext 47)
store i8* %13, i8** %8
%14 = load i8**, i8*** %6
%15 = icmp ne i8** %14, null
br i1 %15, label %16, label %35
16: ; preds = %3
%17 = load i8*, i8** %8
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %31
19: ; preds = %16
%20 = load i8*, i8** %8
store i8 0, i8* %20
%21 = load i8*, i8** %9
%22 = call i8* @strdup(i8* %21)
%23 = load i8**, i8*** %6
store i8* %22, i8** %23
%24 = icmp eq i8* %22, null
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i8*, i8** %9
%27 = call i32 @free(i8* %26)
store i32 -1, i32* %4
br label %56
28: ; preds = %19
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %8
br label %34
31: ; preds = %16
%32 = load i8**, i8*** %6
store i8* null, i8** %32
%33 = load i8*, i8** %9
store i8* %33, i8** %8
br label %34
34: ; preds = %31, %28
br label %41
35: ; preds = %3
%36 = load i8*, i8** %8
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = load i8*, i8** %9
store i8* %39, i8** %8
br label %40
40: ; preds = %38, %35
br label %41
41: ; preds = %40, %34
%42 = load i8**, i8*** %7
%43 = icmp ne i8** %42, null
br i1 %43, label %44, label %53
44: ; preds = %41
%45 = load i8*, i8** %8
%46 = call i8* @strdup(i8* %45)
%47 = load i8**, i8*** %7
store i8* %46, i8** %47
%48 = icmp eq i8* %46, null
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = load i8*, i8** %9
%51 = call i32 @free(i8* %50)
store i32 -1, i32* %4
br label %56
52: ; preds = %44
br label %53
53: ; preds = %52, %41
%54 = load i8*, i8** %9
%55 = call i32 @free(i8* %54)
store i32 0, i32* %4
br label %56
56: ; preds = %53, %49, %25
%57 = load i32, i32* %4
ret i32 %57
}

LLVM IR (-O2):
define i32 @m_splitpath(i8* nocapture %0, i8** writeonly %1, i8** writeonly %2) {
%4 = tail call i8* @strdup(i8* %0)
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %4, i8 signext 47)
%6 = icmp eq i8** %1, null
%7 = icmp eq i8* %5, null
br i1 %6, label %15, label %8
8: ; preds = %3
br i1 %7, label %14, label %9
9: ; preds = %8
store i8 0, i8* %5
%10 = tail call i8* @strdup(i8* %4)
store i8* %10, i8** %1
%11 = icmp eq i8* %10, null
br i1 %11, label %24, label %12
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %5, i64 1
br label %17
14: ; preds = %8
store i8* null, i8** %1
br label %17
15: ; preds = %3
%16 = select i1 %7, i8* %4, i8* %5
br label %17
17: ; preds = %15, %12, %14
%18 = phi i8* [ %13, %12 ], [ %4, %14 ], [ %16, %15 ]
%19 = icmp eq i8** %2, null
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = tail call i8* @strdup(i8* %18)
store i8* %21, i8** %2
%22 = icmp eq i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %20, %17
br label %24
24: ; preds = %20, %9, %23
%25 = phi i32 [ 0, %23 ], [ -1, %9 ], [ -1, %20 ]
%26 = tail call i32 @free(i8* %4)
ret i32 %25
}