#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*/ printf(char *, ...);
char *strchr(char *, char);
char *strdup(char const *);
scalar_t__ strlen(char const *);
int split(const char *data) {
  if (!data || strlen(data) == 0)
    return 0;
  int i = 0;
  char *temp = strdup(data);
  char *curr = temp;
  while (curr) {
    char *next = strchr(curr + 1, ':');
    if (next) {
      *next = '\0';
      next++;
    }
    printf("%s ", curr);
    ++i;
    curr = next;
  }
  printf("\n");
  free(temp);
  return i;
}


x86 assembly (clang, -O0):
<split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117a <split+0x2a>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    1186 <split+0x36>
movl   $0x0,-0x4(%rbp)
jmp    1226 <split+0xd6>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1209 <split+0xb9>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11e1 <split+0x91>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11a2 <split+0x52>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
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
xor    %r12d,%r12d
test   %rdi,%rdi
je     1214 <split+0xc4>
cmpb   $0x0,(%rdi)
je     1214 <split+0xc4>
call   1070 <strdup@plt>
mov    %rax,%r14
test   %rax,%rax
je     11e3 <split+0x93>
mov    %r14,%rdi
add    $0x1,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11e8 <split+0x98>
mov    %rax,%rbx
mov    $0x1,%r12d
lea    0xe60(%rip),%r15
mov    %r14,%rsi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x0,(%rbx)
lea    0x1(%rbx),%rbp
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r12d
add    $0x2,%rbx
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
mov    %rbp,%rsi
test   %rax,%rax
jne    11b0 <split+0x60>
jmp    11f1 <split+0xa1>
xor    %r12d,%r12d
jmp    1202 <split+0xb2>
mov    $0x1,%r12d
mov    %r14,%rbp
lea    0xe08(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%s \00"
define i32 @split(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %31, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %31, label %6
6: ; preds = %3
%7 = tail call i8* @strdup(i8* %0)
%8 = icmp eq i8* %7, null
br i1 %8, label %27, label %9
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = tail call i8* @strchr(i8* %10, i8 signext 58)
%12 = icmp eq i8* %11, null
br i1 %12, label %23, label %13
13: ; preds = %9, %13
%14 = phi i8* [ %21, %13 ], [ %11, %9 ]
%15 = phi i32 [ %19, %13 ], [ 1, %9 ]
%16 = phi i8* [ %17, %13 ], [ %7, %9 ]
store i8 0, i8* %14
%17 = getelementptr inbounds i8, i8* %14, i64 1
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %16)
%19 = add i32 %15, 1
%20 = getelementptr inbounds i8, i8* %14, i64 2
%21 = tail call i8* @strchr(i8* %20, i8 signext 58)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %13
23: ; preds = %13, %9
%24 = phi i8* [ %7, %9 ], [ %17, %13 ]
%25 = phi i32 [ 1, %9 ], [ %19, %13 ]
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %27
27: ; preds = %23, %6
%28 = phi i32 [ 0, %6 ], [ %25, %23 ]
%29 = tail call i32 @putchar(i32 10)
%30 = tail call i32 @free(i8* %7)
br label %31
31: ; preds = %1, %3, %27
%32 = phi i32 [ %28, %27 ], [ 0, %3 ], [ 0, %1 ]
ret i32 %32
}