#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*/ memcpy(char *, char *, int);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void splitpath(const char *path, char *dirname, char *basename) {
  if (strlen(path) == 1 && path[0] == '/') {
    strncpy(dirname, "/", 1);
    strncpy(basename, "/", 1);
    return;
  }
  char p[256];
  strncpy(p, path, 256);
  int pos = strlen(p) - 1;
  if (p[pos] == '/') {
    p[pos] = 0;
    pos--;
  }
  for (;;) {
    pos--;
    if (pos == -1) {
      strncpy(dirname, ".", 2);
      strncpy(basename, p, 256);
      return;
    }
    if (p[pos] == '/') {
      if (pos == 0)
        strncpy(dirname, "/", 2);
      else {
        memcpy(dirname, p, pos);
        dirname[pos] = 0;
      }
      strncpy(basename, p + pos + 1, 30);
      return;
    }
  }
}


x86 assembly (clang, -O0):
<splitpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    1198 <splitpath+0x68>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1198 <splitpath+0x68>
mov    -0x10(%rbp),%rdi
lea    0xe8c(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe77(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncpy@plt>
jmp    12d9 <splitpath+0x1a9>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x124(%rbp)
movslq -0x124(%rbp),%rax
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    11f8 <splitpath+0xc8>
movslq -0x124(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
mov    -0x124(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x124(%rbp)
jmp    11fd <splitpath+0xcd>
mov    -0x124(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x124(%rbp)
cmpl   $0xffffffff,-0x124(%rbp)
jne    1248 <splitpath+0x118>
mov    -0x10(%rbp),%rdi
lea    0xdde(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
jmp    12d9 <splitpath+0x1a9>
movslq -0x124(%rbp),%rax
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    12d4 <splitpath+0x1a4>
cmpl   $0x0,-0x124(%rbp)
jne    1287 <splitpath+0x157>
mov    -0x10(%rbp),%rdi
lea    0xd88(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
jmp    12ac <splitpath+0x17c>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    -0x124(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x124(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    -0x120(%rbp),%rsi
movslq -0x124(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
mov    $0x1e,%edx
call   1030 <strncpy@plt>
jmp    12d9 <splitpath+0x1a9>
jmp    11fd <splitpath+0xcd>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<splitpath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    1193 <splitpath+0x63>
cmpb   $0x2f,(%r12)
jne    1193 <splitpath+0x63>
lea    0xe9e(%rip),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strncpy@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
lea    -0x1(%rcx),%r12
cmpb   $0x2f,-0x1(%rsp,%rcx,1)
jne    11c7 <splitpath+0x97>
movb   $0x0,(%rsp,%r12,1)
add    $0xfffffffe,%eax
movslq %eax,%r12
xor    %eax,%eax
mov    %r15,%rbp
nopl   0x0(%rax)
cmp    %rax,%r12
je     1207 <splitpath+0xd7>
lea    -0x1(%rbx),%r13
add    $0x1,%rax
add    $0xffffffffffffffff,%rbp
cmpb   $0x2f,-0x1(%rbx,%r12,1)
mov    %r13,%rbx
jne    11d0 <splitpath+0xa0>
cmp    %eax,%r12d
jne    1228 <splitpath+0xf8>
lea    0xe08(%rip),%rsi
mov    %r15,%rdi
mov    $0x2,%edx
call   1030 <strncpy@plt>
jmp    123f <splitpath+0x10f>
lea    0xdf4(%rip),%rsi
mov    %r15,%rdi
mov    $0x2,%edx
call   1030 <strncpy@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x100,%edx
jmp    124f <splitpath+0x11f>
mov    %r12,%rdx
sub    %rax,%rdx
mov    %rsp,%rsi
mov    %r15,%rdi
call   1050 <memcpy@plt>
movb   $0x0,0x0(%rbp,%r12,1)
lea    (%r12,%r13,1),%rsi
add    $0x1,%rsi
mov    %r14,%rdi
mov    $0x1e,%edx
call   1030 <strncpy@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
define void @splitpath(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [256 x i8]
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %23
12: ; preds = %3
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 47
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = load i8*, i8** %5
%20 = call i32 @strncpy(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%21 = load i8*, i8** %6
%22 = call i32 @strncpy(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %85
23: ; preds = %12, %3
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%25 = load i8*, i8** %4
%26 = call i32 @strncpy(i8* %24, i8* %25, i32 256)
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %28, 1
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 47
br i1 %35, label %36, label %42
36: ; preds = %23
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %38
store i8 0, i8* %39
%40 = load i32, i32* %8
%41 = add nsw i32 %40, -1
store i32 %41, i32* %8
br label %42
42: ; preds = %36, %23
br label %43
43: ; preds = %84, %42
%44 = load i32, i32* %8
%45 = add nsw i32 %44, -1
store i32 %45, i32* %8
%46 = load i32, i32* %8
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %54
48: ; preds = %43
%49 = load i8*, i8** %5
%50 = call i32 @strncpy(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 2)
%51 = load i8*, i8** %6
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%53 = call i32 @strncpy(i8* %51, i8* %52, i32 256)
br label %85
54: ; preds = %43
%55 = load i32, i32* %8
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %56
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 47
br i1 %60, label %61, label %84
61: ; preds = %54
%62 = load i32, i32* %8
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i8*, i8** %5
%66 = call i32 @strncpy(i8* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 2)
br label %76
67: ; preds = %61
%68 = load i8*, i8** %5
%69 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%70 = load i32, i32* %8
%71 = call i32 @memcpy(i8* %68, i8* %69, i32 %70)
%72 = load i8*, i8** %5
%73 = load i32, i32* %8
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
store i8 0, i8* %75
br label %76
76: ; preds = %67, %64
%77 = load i8*, i8** %6
%78 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%79 = load i32, i32* %8
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
%82 = getelementptr inbounds i8, i8* %81, i64 1
%83 = call i32 @strncpy(i8* %77, i8* %82, i32 30)
br label %85
84: ; preds = %54
br label %43
85: ; preds = %76, %48, %18
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
define void @splitpath(i8* %0, i8* %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %13
7: ; preds = %3
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 47
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%12 = tail call i32 @strncpy(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %50
13: ; preds = %7, %3
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%15 = call i32 @strncpy(i8* %14, i8* %0, i32 256)
%16 = call i32 @strlen(i8* %14)
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 47
br i1 %21, label %22, label %25
22: ; preds = %13
store i8 0, i8* %19
%23 = add nsw i32 %16, -2
%24 = sext i32 %23 to i64
br label %25
25: ; preds = %22, %13
%26 = phi i64 [ %18, %13 ], [ %24, %22 ]
br label %27
27: ; preds = %25, %34
%28 = phi i64 [ %29, %34 ], [ %26, %25 ]
%29 = add nsw i64 %28, -1
%30 = icmp eq i64 %28, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 2)
%33 = call i32 @strncpy(i8* %2, i8* %14, i32 256)
br label %49
34: ; preds = %27
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %29
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 47
br i1 %37, label %38, label %27
38: ; preds = %34
%39 = trunc i64 %29 to i32
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @strncpy(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 2)
br label %46
43: ; preds = %38
%44 = call i32 @memcpy(i8* %1, i8* %14, i32 %39)
%45 = getelementptr inbounds i8, i8* %1, i64 %29
store i8 0, i8* %45
br label %46
46: ; preds = %43, %41
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %28
%48 = call i32 @strncpy(i8* %2, i8* %47, i32 30)
br label %49
49: ; preds = %46, %31
br label %50
50: ; preds = %49, %10
ret void
}