#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 const *, char);
int parse_split(const char *start, char ch, const char **dividers, int parts) {
  int i = 0;
  const char *curr = start - 1;
  while (curr && i < parts) {
    if ((curr = dividers[i] = strchr(curr + 1, ch)))
      i++;
  }
  return i;
}


x86 assembly (clang, -O0):
<parse_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x29(%rbp)
je     1158 <parse_split+0x48>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setl   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1168 <parse_split+0x58>
jmp    11a1 <parse_split+0x91>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
movsbl -0x9(%rbp),%esi
call   1030 <strchr@plt>
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     119c <parse_split+0x8c>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113c <parse_split+0x2c>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_split>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %ecx,%ecx
jle    115c <parse_split+0x4c>
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rdi,%rax
add    $0xffffffffffffffff,%rax
xor    %ecx,%ecx
movsbl %sil,%ebp
xchg   %ax,%ax
mov    %ecx,%ebx
add    $0x1,%rax
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
add    %ebx,%ecx
mov    %ebx,%edx
mov    %rax,(%r14,%rdx,8)
test   %rax,%rax
je     115e <parse_split+0x4e>
cmp    %r15d,%ecx
jl     1130 <parse_split+0x20>
jmp    115e <parse_split+0x4e>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_split(i8* %0, i8 signext %1, i8** %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i8 %1, i8* %6
store i8** %2, i8*** %7
store i32 %3, i32* %8
store i32 0, i32* %9
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 -1
store i8* %12, i8** %10
br label %13
13: ; preds = %35, %4
%14 = load i8*, i8** %10
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* %9
%18 = load i32, i32* %8
%19 = icmp slt i32 %17, %18
br label %20
20: ; preds = %16, %13
%21 = phi i1 [ false, %13 ], [ %19, %16 ]
br i1 %21, label %22, label %36
22: ; preds = %20
%23 = load i8*, i8** %10
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %6
%26 = call i8* @strchr(i8* %24, i8 signext %25)
%27 = load i8**, i8*** %7
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
store i8* %26, i8** %30
store i8* %26, i8** %10
%31 = icmp ne i8* %26, null
br i1 %31, label %32, label %35
32: ; preds = %22
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %35
35: ; preds = %32, %22
br label %13
36: ; preds = %20
%37 = load i32, i32* %9
ret i32 %37
}

LLVM IR (-O2):
define i32 @parse_split(i8* %0, i8 signext %1, i8** nocapture writeonly %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %20
6: ; preds = %4
%7 = getelementptr inbounds i8, i8* %0, i64 -1
br label %8
8: ; preds = %6, %8
%9 = phi i8* [ %12, %8 ], [ %7, %6 ]
%10 = phi i32 [ %17, %8 ], [ 0, %6 ]
%11 = getelementptr inbounds i8, i8* %9, i64 1
%12 = tail call i8* @strchr(i8* %11, i8 signext %1)
%13 = zext i32 %10 to i64
%14 = getelementptr inbounds i8*, i8** %2, i64 %13
store i8* %12, i8** %14
%15 = icmp ne i8* %12, null
%16 = zext i1 %15 to i32
%17 = add nuw nsw i32 %10, %16
%18 = icmp slt i32 %17, %3
%19 = select i1 %15, i1 %18, i1 false
br i1 %19, label %8, label %20
20: ; preds = %8, %4
%21 = phi i32 [ 0, %4 ], [ %17, %8 ]
ret i32 %21
}