#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 *skip_char_match_replace(char, char *, char);
char *skip_char_not_match(char, char *);
void str_splt(char separator, char *str, char **parts, int n, int *part_count) {
  char *c = str;
  int count = 0;
  do {
    c = skip_char_match_replace(separator, c, '\0');
    if (*c != '\0') {
      *parts = c;
      count++;
      parts++;
      c = skip_char_not_match(separator, c);
    }
  } while (*c != '\0' && count < n);
  *part_count = count;
}


x86 assembly (clang, -O0):
<str_splt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x1(%rbp),%al
mov    -0x30(%rbp),%rsi
xor    %edx,%edx
movsbl %al,%edi
call   1030 <skip_char_match_replace@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a4 <str_splt+0x84>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1(%rbp),%al
mov    -0x30(%rbp),%rsi
movsbl %al,%edi
call   1040 <skip_char_not_match@plt>
mov    %rax,-0x30(%rbp)
jmp    11a9 <str_splt+0x89>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x35(%rbp)
je     11ca <str_splt+0xaa>
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setl   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    114c <str_splt+0x2c>
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_splt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8,%r14
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%rax
xor    %ebx,%ebx
movsbl %dil,%ebp
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rax,%rsi
xor    %edx,%edx
call   1030 <skip_char_match_replace@plt>
cmpb   $0x0,(%rax)
je     116d <str_splt+0x4d>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
mov    %ebp,%edi
mov    %rax,%rsi
call   1040 <skip_char_not_match@plt>
cmpb   $0x0,(%rax)
je     116d <str_splt+0x4d>
cmp    %r15d,%ebx
jl     1140 <str_splt+0x20>
mov    %ebx,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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