#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 */
int strlen(char *);
char *strstr(char *, char *);
void abac_split(char *string, char *delim, char **ret, int *num) {
  int len = strlen(delim);
  char *start = string;
  int count = 0;
  while ((start = strstr(string, delim)) != NULL) {
    *start = 0;
    ret[count++] = string;
    string = start + len;
  }
  ret[count++] = string;
  *num = count;
}


x86 assembly (clang, -O0):
<abac_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11a3 <abac_split+0x83>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1153 <abac_split+0x33>
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x34(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abac_split>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
je     1183 <abac_split+0x63>
movslq %ebp,%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,(%rax)
mov    %rbx,(%r15,%rbp,8)
add    $0x1,%rbp
mov    %rax,%rbx
add    %r13,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
jne    1160 <abac_split+0x40>
jmp    1185 <abac_split+0x65>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x1,%ebp
mov    %rbx,(%r15,%rax,8)
mov    %ebp,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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