#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 /*<<< orphan*/ app_error(char *);
int /*<<< orphan*/ isspace(char);
char *strchr(char *, char);
int split(char *buf, char delim, char *argv[]) {
  size_t argc = 0;
  char *bond = NULL;
  while ((bond = strchr(buf, delim)) != NULL) {
    *bond = '\0';
    if (!isspace(bond[-1])) {
      app_error("There must be space before a delimiter.");
      return -1;
    }
    argv[argc++] = buf;
    buf = bond + 1;
  }
  argv[argc++] = buf;
  argv[argc] = NULL;
  return argc;
}


x86 assembly (clang, -O0):
<split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11d2 <split+0xa2>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movsbl -0x1(%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%eax
jne    11a6 <split+0x76>
lea    0xe6b(%rip),%rdi
call   1050 <app_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1204 <split+0xd4>
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1156 <split+0x26>
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%rbx
call   1030 <strchr@plt>
test   %rax,%rax
je     1196 <split+0x66>
mov    %rax,%r15
xor    %ebp,%ebp
movsbl %r12b,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movb   $0x0,(%r15)
movsbl -0x1(%r15),%edi
call   1040 <isspace@plt>
test   %eax,%eax
je     11ab <split+0x7b>
mov    %rbx,(%r14,%rbp,8)
add    $0x1,%rbp
mov    %r15,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r12d,%esi
call   1030 <strchr@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1160 <split+0x30>
jmp    1198 <split+0x68>
xor    %ebp,%ebp
lea    0x1(%rbp),%rax
mov    %rbx,(%r14,%rbp,8)
movq   $0x0,0x8(%r14,%rbp,8)
jmp    11bc <split+0x8c>
lea    0xe4e(%rip),%rdi
call   1050 <app_error@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"There must be space before a delimiter.\00"
define i32 @split(i8* %0, i8 signext %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8**
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i8 %1, i8* %6
store i8** %2, i8*** %7
store i64 0, i64* %8
store i8* null, i8** %9
br label %10
10: ; preds = %24, %3
%11 = load i8*, i8** %5
%12 = load i8, i8* %6
%13 = call i8* @strchr(i8* %11, i8 signext %12)
store i8* %13, i8** %9
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %32
15: ; preds = %10
%16 = load i8*, i8** %9
store i8 0, i8* %16
%17 = load i8*, i8** %9
%18 = getelementptr inbounds i8, i8* %17, i64 -1
%19 = load i8, i8* %18
%20 = call i32 @isspace(i8 signext %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %15
%23 = call i32 @app_error(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %43
24: ; preds = %15
%25 = load i8*, i8** %5
%26 = load i8**, i8*** %7
%27 = load i64, i64* %8
%28 = add i64 %27, 1
store i64 %28, i64* %8
%29 = getelementptr inbounds i8*, i8** %26, i64 %27
store i8* %25, i8** %29
%30 = load i8*, i8** %9
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8* %31, i8** %5
br label %10
32: ; preds = %10
%33 = load i8*, i8** %5
%34 = load i8**, i8*** %7
%35 = load i64, i64* %8
%36 = add i64 %35, 1
store i64 %36, i64* %8
%37 = getelementptr inbounds i8*, i8** %34, i64 %35
store i8* %33, i8** %37
%38 = load i8**, i8*** %7
%39 = load i64, i64* %8
%40 = getelementptr inbounds i8*, i8** %38, i64 %39
store i8* null, i8** %40
%41 = load i64, i64* %8
%42 = trunc i64 %41 to i32
store i32 %42, i32* %4
br label %43
43: ; preds = %32, %22
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
@.str = [40 x i8] c"There must be space before a delimiter.\00"
define i32 @split(i8* %0, i8 signext %1, i8** nocapture writeonly %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %22, label %6
6: ; preds = %3, %16
%7 = phi i8* [ %20, %16 ], [ %4, %3 ]
%8 = phi i64 [ %17, %16 ], [ 0, %3 ]
%9 = phi i8* [ %19, %16 ], [ %0, %3 ]
store i8 0, i8* %7
%10 = getelementptr inbounds i8, i8* %7, i64 -1
%11 = load i8, i8* %10
%12 = tail call i32 @isspace(i8 signext %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = tail call i32 @app_error(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %29
16: ; preds = %6
%17 = add i64 %8, 1
%18 = getelementptr inbounds i8*, i8** %2, i64 %8
store i8* %9, i8** %18
%19 = getelementptr inbounds i8, i8* %7, i64 1
%20 = tail call i8* @strchr(i8* dereferenceable(1) %19, i8 signext %1)
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %6
22: ; preds = %16, %3
%23 = phi i8* [ %0, %3 ], [ %19, %16 ]
%24 = phi i64 [ 0, %3 ], [ %17, %16 ]
%25 = add i64 %24, 1
%26 = getelementptr inbounds i8*, i8** %2, i64 %24
store i8* %23, i8** %26
%27 = getelementptr inbounds i8*, i8** %2, i64 %25
store i8* null, i8** %27
%28 = trunc i64 %25 to i32
br label %29
29: ; preds = %22, %14
%30 = phi i32 [ -1, %14 ], [ %28, %22 ]
ret i32 %30
}