#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 */
size_t MAXPATHLEN;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
char *strchr(char const *, char);
size_t strlen(char const *);
char *strrchr(char const *, char);
void _splitpath(const char *src, char *drv, char *dir, char *base, char *ext) {
  const char *p, *q;
  size_t n;
  assert(drv == NULL);
  assert(dir == NULL);
  assert(ext == NULL);
  assert(src != NULL);
  assert(base != NULL);
  p = strrchr(src, '/');
  if (p == NULL)
    p = src;
  q = strchr(p, '.');
  if (q == NULL)
    n = strlen(p);
  else
    n = q - p;
  assert(n < MAXPATHLEN);
  memcpy(base, p, n);
  base[n] = 0;
}


x86 assembly (clang, -O0):
<_splitpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x0,-0x28(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11eb <_splitpath+0x9b>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    121a <_splitpath+0xca>
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x40(%rbp)
jmp    1229 <_splitpath+0xd9>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    0x2db4(%rip),%rcx
cmp    (%rcx),%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1070 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_splitpath>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %r8,%r12
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rdi,%r15
xor    %edi,%edi
test   %rsi,%rsi
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
test   %r12,%r12
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1060 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1060 <assert@plt>
mov    %r15,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,%r12
test   %rax,%rax
cmove  %r15,%r12
mov    %r12,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11db <_splitpath+0x8b>
mov    %rax,%rbx
sub    %r12,%rbx
jmp    11e6 <_splitpath+0x96>
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    0x2dfb(%rip),%rax
xor    %edi,%edi
cmp    (%rax),%rbx
setb   %dil
call   1060 <assert@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1070 <memcpy@plt>
movb   $0x0,(%r14,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@MAXPATHLEN = global i64 0
define void @_splitpath(i8* %0, i8* readnone %1, i8* readnone %2, i8* %3, i8* readnone %4) {
%6 = icmp eq i8* %1, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp eq i8* %2, null
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = icmp eq i8* %4, null
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = icmp ne i8* %0, null
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = icmp ne i8* %3, null
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%22 = icmp eq i8* %21, null
%23 = select i1 %22, i8* %0, i8* %21
%24 = tail call i8* @strchr(i8* dereferenceable(1) %23, i8 signext 46)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %5
%27 = tail call i64 @strlen(i8* dereferenceable(1) %23)
br label %32
28: ; preds = %5
%29 = ptrtoint i8* %24 to i64
%30 = ptrtoint i8* %23 to i64
%31 = sub i64 %29, %30
br label %32
32: ; preds = %28, %26
%33 = phi i64 [ %27, %26 ], [ %31, %28 ]
%34 = load i64, i64* @MAXPATHLEN
%35 = icmp ult i64 %33, %34
%36 = zext i1 %35 to i32
%37 = tail call i32 @assert(i32 %36)
%38 = tail call i32 @memcpy(i8* %3, i8* %23, i64 %33)
%39 = getelementptr inbounds i8, i8* %3, i64 %33
store i8 0, i8* %39
ret void
}