#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 *strsep(char **, char *);
__attribute__((always_)) int string_split(char *const a, char **arr, int arrn) {
  int idx = 0;
  char **str = (char **)&a;
  while (((arr[idx++] = strsep(str, "|")) != NULL) && (idx < arrn))
    ;
  return ((idx > 1) ? (idx - 1) : 0);
}


x86 assembly (clang, -O0):
<string_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xec3(%rip),%rsi
call   1030 <strsep@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%edx
mov    %edx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %edx,%rdx
mov    %rcx,(%rax,%rdx,8)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
je     1176 <string_split+0x66>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1186 <string_split+0x76>
jmp    118b <string_split+0x7b>
jmp    1132 <string_split+0x22>
cmpl   $0x1,-0x18(%rbp)
jle    11a3 <string_split+0x93>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ad <string_split+0x9d>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    11ad <string_split+0x9d>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_split>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,(%rsp)
movslq %edx,%r13
mov    $0xffffffff,%ebp
mov    $0x1,%ebx
lea    0xeca(%rip),%r14
mov    %rsp,%r15
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strsep@plt>
mov    %rax,-0x8(%r12,%rbx,8)
add    $0x1,%ebp
test   %rax,%rax
je     1164 <string_split+0x54>
lea    0x1(%rbx),%rax
cmp    %r13,%rbx
mov    %rax,%rbx
jl     1140 <string_split+0x30>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"|\00"
define i32 @string_split(i8* %0, i8** nocapture writeonly %1, i32 %2) {
%4 = alloca i8*
store i8* %0, i8** %4
%5 = sext i32 %2 to i64
br label %6
6: ; preds = %6, %3
%7 = phi i64 [ %9, %6 ], [ 0, %3 ]
%8 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = add nuw nsw i64 %7, 1
%10 = getelementptr inbounds i8*, i8** %1, i64 %7
store i8* %8, i8** %10
%11 = icmp ne i8* %8, null
%12 = icmp slt i64 %9, %5
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %6, label %14
14: ; preds = %6
%15 = trunc i64 %7 to i32
ret i32 %15
}