#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*/ free(char *);
int /*<<< orphan*/ kcn_key_free(size_t, char **);
char **realloc(char **, int);
char *strdup(char const *);
char *strtok_r(char *, char *, char **);
char **kcn_key_split(const char *keys0, size_t *keycp) {
  char *k, *kp, *keys, **keyv, **tmp;
  size_t keyc;
  keys = strdup(keys0);
  if (keys == NULL)
    return NULL;
  keyc = 0;
  keyv = NULL;
  for (k = strtok_r(keys, " \t", &kp); k != NULL;
       k = strtok_r(NULL, " \t", &kp)) {
    tmp = realloc(keyv, sizeof(char *) * (keyc + 1));
    if (tmp == NULL)
      goto bad;
    keyv = tmp;
    keyv[keyc++] = strdup(k);
    if (keyv[keyc - 1] == NULL)
      goto bad;
  }
  free(keys);
  *keycp = keyc;
  return keyv;
bad:
  free(keys);
  kcn_key_free(keyc, keyv);
  return NULL;
}


x86 assembly (clang, -O0):
<kcn_key_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1185 <kcn_key_split+0x35>
movq   $0x0,-0x8(%rbp)
jmp    128b <kcn_key_split+0x13b>
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe60(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     124c <kcn_key_split+0xfc>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rax
add    $0x1,%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1060 <realloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11e3 <kcn_key_split+0x93>
jmp    126d <kcn_key_split+0x11d>
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
mov    -0x48(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x48(%rbp)
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    $0x1,%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    122a <kcn_key_split+0xda>
jmp    126d <kcn_key_split+0x11d>
jmp    122f <kcn_key_split+0xdf>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc6(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
jmp    11ad <kcn_key_split+0x5d>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    128b <kcn_key_split+0x13b>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <kcn_key_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kcn_key_split>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
call   1070 <strdup@plt>
test   %rax,%rax
je     122e <kcn_key_split+0xde>
mov    %rbx,0x8(%rsp)
lea    0xe85(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,(%rsp)
mov    %rax,%rdi
call   1050 <strtok_r@plt>
test   %rax,%rax
je     11f9 <kcn_key_split+0xa9>
mov    %rax,%r15
mov    $0x8,%ebp
xor    %ebx,%ebx
lea    0x10(%rsp),%r14
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %ebp,%esi
call   1060 <realloc@plt>
test   %rax,%rax
je     1211 <kcn_key_split+0xc1>
mov    %rax,%r13
mov    %r15,%rdi
call   1070 <strdup@plt>
mov    %rax,0x0(%r13,%rbx,8)
test   %rax,%rax
je     1216 <kcn_key_split+0xc6>
xor    %edi,%edi
lea    0xe23(%rip),%rsi
mov    %r14,%rdx
call   1050 <strtok_r@plt>
mov    %rax,%r15
add    $0x8,%ebp
add    $0x1,%rbx
mov    %r13,%r12
test   %rax,%rax
jne    11b0 <kcn_key_split+0x60>
jmp    11fe <kcn_key_split+0xae>
xor    %r13d,%r13d
xor    %ebx,%ebx
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rax
mov    %rbx,(%rax)
jmp    1231 <kcn_key_split+0xe1>
mov    %r12,%r13
jmp    121a <kcn_key_split+0xca>
add    $0x1,%rbx
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <kcn_key_free@plt>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c" \09\00"
define i8** @kcn_key_split(i8* %0, i64* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i8**
%11 = alloca i64
store i8* %0, i8** %4
store i64* %1, i64** %5
%12 = load i8*, i8** %4
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i8** null, i8*** %3
br label %63
17: ; preds = %2
store i64 0, i64* %11
store i8** null, i8*** %9
%18 = load i8*, i8** %8
%19 = call i8* @strtok_r(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %7)
store i8* %19, i8** %6
br label %20
20: ; preds = %49, %17
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %51
23: ; preds = %20
%24 = load i8**, i8*** %9
%25 = load i64, i64* %11
%26 = add i64 %25, 1
%27 = mul i64 8, %26
%28 = trunc i64 %27 to i32
%29 = call i8** @realloc(i8** %24, i32 %28)
store i8** %29, i8*** %10
%30 = load i8**, i8*** %10
%31 = icmp eq i8** %30, null
br i1 %31, label %32, label %33
32: ; preds = %23
br label %57
33: ; preds = %23
%34 = load i8**, i8*** %10
store i8** %34, i8*** %9
%35 = load i8*, i8** %6
%36 = call i8* @strdup(i8* %35)
%37 = load i8**, i8*** %9
%38 = load i64, i64* %11
%39 = add i64 %38, 1
store i64 %39, i64* %11
%40 = getelementptr inbounds i8*, i8** %37, i64 %38
store i8* %36, i8** %40
%41 = load i8**, i8*** %9
%42 = load i64, i64* %11
%43 = sub i64 %42, 1
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %48
47: ; preds = %33
br label %57
48: ; preds = %33
br label %49
49: ; preds = %48
%50 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %7)
store i8* %50, i8** %6
br label %20
51: ; preds = %20
%52 = load i8*, i8** %8
%53 = call i32 @free(i8* %52)
%54 = load i64, i64* %11
%55 = load i64*, i64** %5
store i64 %54, i64* %55
%56 = load i8**, i8*** %9
store i8** %56, i8*** %3
br label %63
57: ; preds = %47, %32
%58 = load i8*, i8** %8
%59 = call i32 @free(i8* %58)
%60 = load i64, i64* %11
%61 = load i8**, i8*** %9
%62 = call i32 @kcn_key_free(i64 %60, i8** %61)
store i8** null, i8*** %3
br label %63
63: ; preds = %57, %51, %16
%64 = load i8**, i8*** %3
ret i8** %64
}

LLVM IR (-O2):
@.str = [3 x i8] c" \09\00"
define i8** @kcn_key_split(i8* nocapture %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i8* @strdup(i8* %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %35, label %7
7: ; preds = %2
%8 = call i8* @strtok_r(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %3)
%9 = icmp eq i8* %8, null
br i1 %9, label %26, label %10
10: ; preds = %7, %23
%11 = phi i64 [ %14, %23 ], [ 0, %7 ]
%12 = phi i8** [ %17, %23 ], [ null, %7 ]
%13 = phi i8* [ %24, %23 ], [ %8, %7 ]
%14 = add i64 %11, 1
%15 = trunc i64 %14 to i32
%16 = shl i32 %15, 3
%17 = call i8** @realloc(i8** %12, i32 %16)
%18 = icmp eq i8** %17, null
br i1 %18, label %30, label %19
19: ; preds = %10
%20 = call i8* @strdup(i8* %13)
%21 = getelementptr inbounds i8*, i8** %17, i64 %11
store i8* %20, i8** %21
%22 = icmp eq i8* %20, null
br i1 %22, label %30, label %23
23: ; preds = %19
%24 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %3)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %10
26: ; preds = %23, %7
%27 = phi i8** [ null, %7 ], [ %17, %23 ]
%28 = phi i64 [ 0, %7 ], [ %14, %23 ]
%29 = call i32 @free(i8* %5)
store i64 %28, i64* %1
br label %35
30: ; preds = %19, %10
%31 = phi i8** [ %12, %10 ], [ %17, %19 ]
%32 = phi i64 [ %11, %10 ], [ %14, %19 ]
%33 = call i32 @free(i8* %5)
%34 = call i32 @kcn_key_free(i64 %32, i8** %31)
br label %35
35: ; preds = %2, %30, %26
%36 = phi i8** [ null, %30 ], [ %27, %26 ], [ null, %2 ]
ret i8** %36
}