#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*/ strncpy(char *, char const *, int);
char *strrchr(char *, int);
void _splitpath2(const char *constpath, char *dir, char *fname) {
  static char pathcopy[1024 + 1];
  char *slash;
  strncpy(pathcopy, constpath, 1024);
  slash = strrchr(pathcopy, '/');
  if (!slash)
    slash = strrchr(pathcopy, (int)'\\');
  if (slash != NULL) {
    slash[0] = 0;
    strncpy(dir, pathcopy, 1024);
    dir[255] = 0;
    strncpy(fname, slash + 1, 128);
    fname[128] = 0;
  } else {
    dir[0] = 0;
    strncpy(fname, pathcopy, 128);
    fname[128] = 0;
  }
}


x86 assembly (clang, -O0):
<_splitpath2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    0x2f01(%rip),%rdi
mov    $0x400,%edx
call   1030 <strncpy@plt>
lea    0x2ef0(%rip),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117e <_splitpath2+0x5e>
lea    0x2ed0(%rip),%rdi
mov    $0x5c,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d6 <_splitpath2+0xb6>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0x2ea5(%rip),%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,0xff(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x80(%rax)
jmp    11fd <_splitpath2+0xdd>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    0x2e58(%rip),%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movb   $0x0,0x80(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_splitpath2>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rsi
lea    0x2f0b(%rip),%rbx
mov    %rbx,%rdi
mov    $0x400,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1170 <_splitpath2+0x50>
lea    0x2ee2(%rip),%rdi
mov    $0x5c,%esi
call   1040 <strrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11b1 <_splitpath2+0x91>
movb   $0x0,(%rbx)
lea    0x2ec6(%rip),%rsi
mov    %r15,%rdi
mov    $0x400,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xff(%r15)
add    $0x1,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x80(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret
movb   $0x0,(%r15)
lea    0x2e84(%rip),%rsi
mov    %r14,%rdi
jmp    1199 <_splitpath2+0x79>

LLVM IR (-O0):
@_splitpath2.pathcopy = internal global [1025 x i8] zeroinitializer
define void @_splitpath2(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 = call i32 @strncpy(i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @_splitpath2.pathcopy, i64 0, i64 0), i8* %8, i32 1024)
%10 = call i8* @strrchr(i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @_splitpath2.pathcopy, i64 0, i64 0), i32 47)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %3
%14 = call i8* @strrchr(i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @_splitpath2.pathcopy, i64 0, i64 0), i32 92)
store i8* %14, i8** %7
br label %15
15: ; preds = %13, %3
%16 = load i8*, i8** %7
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %31
18: ; preds = %15
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i64 0
store i8 0, i8* %20
%21 = load i8*, i8** %5
%22 = call i32 @strncpy(i8* %21, i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @_splitpath2.pathcopy, i64 0, i64 0), i32 1024)
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 255
store i8 0, i8* %24
%25 = load i8*, i8** %6
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = call i32 @strncpy(i8* %25, i8* %27, i32 128)
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i64 128
store i8 0, i8* %30
br label %38
31: ; preds = %15
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 0
store i8 0, i8* %33
%34 = load i8*, i8** %6
%35 = call i32 @strncpy(i8* %34, i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @_splitpath2.pathcopy, i64 0, i64 0), i32 128)
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i64 128
store i8 0, i8* %37
br label %38
38: ; preds = %31, %18
ret void
}

LLVM IR (-O2):
@_splitpath2.pathcopy = internal global [1025 x i8] zeroinitializer
define void @_splitpath2(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strncpy(i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @_splitpath2.pathcopy, i64 0, i64 0), i8* %0, i32 1024)
%5 = tail call i8* @strrchr(i8* dereferenceable(1) getelementptr inbounds ([1025 x i8], [1025 x i8]* @_splitpath2.pathcopy, i64 0, i64 0), i32 47)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i8* @strrchr(i8* dereferenceable(1) getelementptr inbounds ([1025 x i8], [1025 x i8]* @_splitpath2.pathcopy, i64 0, i64 0), i32 92)
%9 = icmp eq i8* %8, null
br i1 %9, label %16, label %10
10: ; preds = %3, %7
%11 = phi i8* [ %8, %7 ], [ %5, %3 ]
store i8 0, i8* %11
%12 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @_splitpath2.pathcopy, i64 0, i64 0), i32 1024)
%13 = getelementptr inbounds i8, i8* %1, i64 255
store i8 0, i8* %13
%14 = getelementptr inbounds i8, i8* %11, i64 1
%15 = tail call i32 @strncpy(i8* %2, i8* %14, i32 128)
br label %18
16: ; preds = %7
store i8 0, i8* %1
%17 = tail call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([1025 x i8], [1025 x i8]* @_splitpath2.pathcopy, i64 0, i64 0), i32 128)
br label %18
18: ; preds = %16, %10
%19 = getelementptr inbounds i8, i8* %2, i64 128
store i8 0, i8* %19
ret void
}