#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;
  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,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    112f <yuarel_split_path+0x1f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1150 <yuarel_split_path+0x40>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112f <yuarel_split_path+0x1f>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    1166 <yuarel_split_path+0x56>
jmp    11c1 <yuarel_split_path+0xb1>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
jne    11a3 <yuarel_split_path+0x93>
jmp    11c1 <yuarel_split_path+0xb1>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x0,(%rax)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     112a <yuarel_split_path+0x1a>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yuarel_split_path>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x2,%edx
mov    $0x1,%r15d
cmovge %edx,%r15d
xor    %ebx,%ebx
jmp    1134 <yuarel_split_path+0x24>
nopl   0x0(%rax)
add    $0x1,%rdi
movzbl (%rdi),%eax
cmp    $0x2f,%al
je     1130 <yuarel_split_path+0x20>
test   %al,%al
je     1167 <yuarel_split_path+0x57>
mov    %rdi,(%r14,%rbx,8)
add    $0x1,%rbx
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1167 <yuarel_split_path+0x57>
mov    %rax,%rdi
add    $0x1,%rdi
movb   $0x0,(%rax)
cmp    %r15,%rbx
jne    1134 <yuarel_split_path+0x24>
jmp    116a <yuarel_split_path+0x5a>
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 i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %38, %3
br label %9
9: ; preds = %14, %8
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 47
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %4
br label %9
17: ; preds = %9
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 0, %20
br i1 %21, label %22, label %23
22: ; preds = %17
br label %42
23: ; preds = %17
%24 = load i8*, i8** %4
%25 = load i8**, i8*** %5
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8*, i8** %25, i64 %28
store i8* %24, i8** %29
%30 = load i8*, i8** %4
%31 = call i8* @strchr(i8* %30, i8 signext 47)
store i8* %31, i8** %4
%32 = load i8*, i8** %4
%33 = icmp eq i8* null, %32
br i1 %33, label %34, label %35
34: ; preds = %23
br label %42
35: ; preds = %23
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %4
store i8 0, i8* %36
br label %38
38: ; preds = %35
%39 = load i32, i32* %7
%40 = load i32, i32* %6
%41 = icmp slt i32 %39, %40
br i1 %41, label %8, label %42
42: ; preds = %38, %34, %22
%43 = load i32, i32* %7
ret i32 %43
}

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