#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 */
char *strchr(char *, char);
int yuarel_split_path(char *path, char **parts, int max_parts) {
  int i = 0;
  if (NULL == path || '\0' == *path) {
    return -1;
  }
  do {
    while (*path == '/')
      path++;
    if ('\0' == *path) {
      break;
    }
    parts[i++] = path;
    path = strchr(path, '/');
    if (NULL == path) {
      break;
    }
    *(path++) = '\0';
  } while (i < max_parts);
  return i;
}


x86 assembly (clang, -O0):
<yuarel_split_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     1147 <yuarel_split_path+0x37>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    1153 <yuarel_split_path+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f5 <yuarel_split_path+0xe5>
jmp    1158 <yuarel_split_path+0x48>
jmp    115d <yuarel_split_path+0x4d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    117e <yuarel_split_path+0x6e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115d <yuarel_split_path+0x4d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    1194 <yuarel_split_path+0x84>
jmp    11ef <yuarel_split_path+0xdf>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    11d1 <yuarel_split_path+0xc1>
jmp    11ef <yuarel_split_path+0xdf>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1158 <yuarel_split_path+0x48>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yuarel_split_path>:
push   %r15
push   %r14
push   %rbx
mov    $0xffffffff,%r15d
test   %rdi,%rdi
je     117a <yuarel_split_path+0x6a>
cmpb   $0x0,(%rdi)
je     117a <yuarel_split_path+0x6a>
mov    %rsi,%r14
cmp    $0x2,%edx
mov    $0x1,%r15d
cmovge %edx,%r15d
xor    %ebx,%ebx
jmp    1144 <yuarel_split_path+0x34>
nopl   0x0(%rax)
add    $0x1,%rdi
movzbl (%rdi),%eax
cmp    $0x2f,%al
je     1140 <yuarel_split_path+0x30>
test   %al,%al
je     1177 <yuarel_split_path+0x67>
mov    %rdi,(%r14,%rbx,8)
add    $0x1,%rbx
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1177 <yuarel_split_path+0x67>
mov    %rax,%rdi
add    $0x1,%rdi
movb   $0x0,(%rax)
cmp    %r15,%rbx
jne    1144 <yuarel_split_path+0x34>
jmp    117a <yuarel_split_path+0x6a>
mov    %ebx,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @yuarel_split_path(i8* %0, i8** nocapture writeonly %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %31, label %5
5: ; preds = %3
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %31, label %8
8: ; preds = %5
%9 = call i32 @llvm.smax.i32(i32 %2, i32 1)
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %8, %24
%12 = phi i64 [ 0, %8 ], [ %20, %24 ]
%13 = phi i8* [ %0, %8 ], [ %25, %24 ]
br label %14
14: ; preds = %17, %11
%15 = phi i8* [ %13, %11 ], [ %18, %17 ]
%16 = load i8, i8* %15
switch i8 %16, label %19 [
i8 47, label %17
i8 0, label %27
]
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %15, i64 1
br label %14
19: ; preds = %14
%20 = add nuw nsw i64 %12, 1
%21 = getelementptr inbounds i8*, i8** %1, i64 %12
store i8* %15, i8** %21
%22 = tail call i8* @strchr(i8* %15, i8 signext 47)
%23 = icmp eq i8* %22, null
br i1 %23, label %29, label %24
24: ; preds = %19
%25 = getelementptr inbounds i8, i8* %22, i64 1
store i8 0, i8* %22
%26 = icmp eq i64 %20, %10
br i1 %26, label %31, label %11
27: ; preds = %14
%28 = trunc i64 %12 to i32
br label %31
29: ; preds = %19
%30 = trunc i64 %20 to i32
br label %31
31: ; preds = %24, %29, %27, %3, %5
%32 = phi i32 [ -1, %5 ], [ -1, %3 ], [ %28, %27 ], [ %30, %29 ], [ %9, %24 ]
ret i32 %32
}