void hugo_splitpath(char *path, char *drive, char *dir, char *fname,
                    char *ext) {
  char *file;
  char *extension;
  strcpy(drive, "");
  strcpy(dir, "");
  strcpy(fname, "");
  strcpy(ext, "");
  if ((file = strrchr(path, '/')) == 0) {
    if ((file = strrchr(path, ':')) == 0)
      file = path;
  }
  strncpy(dir, path, strlen(path) - strlen(file));
  *(dir + strlen(path) - strlen(file)) = 0;
  extension = strrchr(file, '.');
  if (extension != 0) {
    strncpy(fname, file, strlen(file) - strlen(extension));
    *(fname + strlen(file) - strlen(extension)) = 0;
    strcpy(ext, extension + 1);
  } else
    strcpy(fname, file);
  if (strcmp(dir, "") && fname[0] == '/')
    strcpy(fname, fname + 1);
}


x86 assembly (clang, -O0):
<hugo_splitpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11f4 <hugo_splitpath+0xa4>
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11ef <hugo_splitpath+0x9f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11f4 <hugo_splitpath+0xa4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x60(%rbp),%rdx
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
sub    %rax,%rdx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdx
mov    -0x40(%rbp),%rax
xor    %ecx,%ecx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1311 <hugo_splitpath+0x1c1>
mov    -0x20(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x88(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x88(%rbp),%rdx
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
sub    %rax,%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x68(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdx
mov    -0x68(%rbp),%rax
xor    %ecx,%ecx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
add    $0x1,%rsi
call   1040 <strcpy@plt>
jmp    131e <hugo_splitpath+0x1ce>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xcd7(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     1358 <hugo_splitpath+0x208>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1358 <hugo_splitpath+0x208>
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
call   1040 <strcpy@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hugo_splitpath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r15
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rdi,%r13
movb   $0x0,(%rsi)
movb   $0x0,(%rdx)
movb   $0x0,(%rcx)
movb   $0x0,(%r8)
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    118d <hugo_splitpath+0x4d>
mov    %r13,%rdi
mov    $0x3a,%esi
call   1060 <strrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
cmove  %r13,%rbx
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
sub    %rax,%rbp
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
add    %r12,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
sub    %rax,%rbp
movb   $0x0,0x0(%rbp)
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     122f <hugo_splitpath+0xef>
mov    %rax,%r13
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
mov    %r13,%rdi
call   1050 <strlen@plt>
sub    %rax,%rbp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
add    %r14,%rbx
mov    %r13,%rdi
call   1050 <strlen@plt>
sub    %rax,%rbx
movb   $0x0,(%rbx)
add    $0x1,%r13
mov    %r15,%rdi
mov    %r13,%rsi
jmp    1235 <hugo_splitpath+0xf5>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
cmpb   $0x0,(%r12)
je     1261 <hugo_splitpath+0x121>
cmpb   $0x2f,(%r14)
jne    1261 <hugo_splitpath+0x121>
lea    0x1(%r14),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <strcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define void @hugo_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*
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
%13 = load i8*, i8** %7
%14 = call i8* @strcpy(i8* %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%15 = load i8*, i8** %8
%16 = call i8* @strcpy(i8* %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %9
%18 = call i8* @strcpy(i8* %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %10
%20 = call i8* @strcpy(i8* %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%21 = load i8*, i8** %6
%22 = call i8* @strrchr(i8* %21, i32 47)
store i8* %22, i8** %11
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %31
24: ; preds = %5
%25 = load i8*, i8** %6
%26 = call i8* @strrchr(i8* %25, i32 58)
store i8* %26, i8** %11
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = load i8*, i8** %6
store i8* %29, i8** %11
br label %30
30: ; preds = %28, %24
br label %31
31: ; preds = %30, %5
%32 = load i8*, i8** %8
%33 = load i8*, i8** %6
%34 = load i8*, i8** %6
%35 = call i64 @strlen(i8* %34)
%36 = load i8*, i8** %11
%37 = call i64 @strlen(i8* %36)
%38 = sub i64 %35, %37
%39 = call i8* @strncpy(i8* %32, i8* %33, i64 %38)
%40 = load i8*, i8** %8
%41 = load i8*, i8** %6
%42 = call i64 @strlen(i8* %41)
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8*, i8** %11
%45 = call i64 @strlen(i8* %44)
%46 = sub i64 0, %45
%47 = getelementptr inbounds i8, i8* %43, i64 %46
store i8 0, i8* %47
%48 = load i8*, i8** %11
%49 = call i8* @strrchr(i8* %48, i32 46)
store i8* %49, i8** %12
%50 = load i8*, i8** %12
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %73
52: ; preds = %31
%53 = load i8*, i8** %9
%54 = load i8*, i8** %11
%55 = load i8*, i8** %11
%56 = call i64 @strlen(i8* %55)
%57 = load i8*, i8** %12
%58 = call i64 @strlen(i8* %57)
%59 = sub i64 %56, %58
%60 = call i8* @strncpy(i8* %53, i8* %54, i64 %59)
%61 = load i8*, i8** %9
%62 = load i8*, i8** %11
%63 = call i64 @strlen(i8* %62)
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8*, i8** %12
%66 = call i64 @strlen(i8* %65)
%67 = sub i64 0, %66
%68 = getelementptr inbounds i8, i8* %64, i64 %67
store i8 0, i8* %68
%69 = load i8*, i8** %10
%70 = load i8*, i8** %12
%71 = getelementptr inbounds i8, i8* %70, i64 1
%72 = call i8* @strcpy(i8* %69, i8* %71)
br label %77
73: ; preds = %31
%74 = load i8*, i8** %9
%75 = load i8*, i8** %11
%76 = call i8* @strcpy(i8* %74, i8* %75)
br label %77
77: ; preds = %73, %52
%78 = load i8*, i8** %8
%79 = call i32 @strcmp(i8* %78, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %92
81: ; preds = %77
%82 = load i8*, i8** %9
%83 = getelementptr inbounds i8, i8* %82, i64 0
%84 = load i8, i8* %83
%85 = sext i8 %84 to i32
%86 = icmp eq i32 %85, 47
br i1 %86, label %87, label %92
87: ; preds = %81
%88 = load i8*, i8** %9
%89 = load i8*, i8** %9
%90 = getelementptr inbounds i8, i8* %89, i64 1
%91 = call i8* @strcpy(i8* %88, i8* %90)
br label %92
92: ; preds = %87, %81, %77
ret void
}

LLVM IR (-O2):
define void @hugo_splitpath(i8* %0, i8* nocapture writeonly %1, i8* %2, i8* %3, i8* %4) {
store i8 0, i8* %1
store i8 0, i8* %2
store i8 0, i8* %3
store i8 0, i8* %4
%6 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i32 47)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i32 58)
%10 = icmp eq i8* %9, null
%11 = select i1 %10, i8* %0, i8* %9
br label %12
12: ; preds = %8, %5
%13 = phi i8* [ %6, %5 ], [ %11, %8 ]
%14 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%15 = tail call i64 @strlen(i8* dereferenceable(1) %13)
%16 = sub i64 %14, %15
%17 = tail call i8* @strncpy(i8* %2, i8* %0, i64 %16)
%18 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%19 = getelementptr inbounds i8, i8* %2, i64 %18
%20 = tail call i64 @strlen(i8* dereferenceable(1) %13)
%21 = sub i64 0, %20
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
%23 = tail call i8* @strrchr(i8* dereferenceable(1) %13, i32 46)
%24 = icmp eq i8* %23, null
br i1 %24, label %37, label %25
25: ; preds = %12
%26 = tail call i64 @strlen(i8* dereferenceable(1) %13)
%27 = tail call i64 @strlen(i8* %23)
%28 = sub i64 %26, %27
%29 = tail call i8* @strncpy(i8* %3, i8* %13, i64 %28)
%30 = tail call i64 @strlen(i8* dereferenceable(1) %13)
%31 = getelementptr inbounds i8, i8* %3, i64 %30
%32 = tail call i64 @strlen(i8* %23)
%33 = sub i64 0, %32
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
%35 = getelementptr inbounds i8, i8* %23, i64 1
%36 = tail call i8* @strcpy(i8* %4, i8* %35)
br label %39
37: ; preds = %12
%38 = tail call i8* @strcpy(i8* %3, i8* dereferenceable(1) %13)
br label %39
39: ; preds = %37, %25
%40 = load i8, i8* %2
%41 = icmp eq i8 %40, 0
br i1 %41, label %48, label %42
42: ; preds = %39
%43 = load i8, i8* %3
%44 = icmp eq i8 %43, 47
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = getelementptr inbounds i8, i8* %3, i64 1
%47 = tail call i8* @strcpy(i8* %3, i8* %46)
br label %48
48: ; preds = %45, %42, %39
ret void
}