#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*/ assert(int);
int atoi(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
size_t strsplit(char *, char **, char *);
int main(void) {
  {
    char str[] = "hello\nworld";
    char *parts[2] = {NULL};
    size_t size = strsplit(str, parts, "\n");
    assert(size);
    int i = 0;
    for (; i < size; i++) {
      printf("%s\n", parts[i]);
    }
    for (i = 0; i < (int)size; i++) {
      free(parts[i]);
    }
  }
  {
    char str[] = "0 1 2 3 4 5 6 7 8 9";
    char *parts[10] = {NULL};
    size_t size = strsplit(str, parts, " ");
    assert(size);
    int i = 0;
    for (; i < (int)size; i++) {
      assert(i == atoi(parts[i]));
      printf("%s\n", parts[i]);
    }
    for (i = 0; i < (int)size; i++) {
      free(parts[i]);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xe85(%rip),%eax
mov    %eax,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    0xe69(%rip),%rdx
call   1080 <strsplit@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,%edi
call   1060 <assert@plt>
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11f1 <main+0x91>
movslq -0x2c(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%rsi
lea    0xe2e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c0 <main+0x60>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x28(%rbp),%rcx
cmp    %ecx,%eax
jge    1223 <main+0xc3>
movslq -0x2c(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11f8 <main+0x98>
mov    0xdf6(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xdf3(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xdf1(%rip),%eax
mov    %eax,-0x30(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
lea    -0x40(%rbp),%rdi
lea    -0x90(%rbp),%rsi
lea    0xda9(%rip),%rdx
call   1080 <strsplit@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
mov    %eax,%edi
call   1060 <assert@plt>
movl   $0x0,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
mov    -0x98(%rbp),%rcx
cmp    %ecx,%eax
jge    1306 <main+0x1a6>
mov    -0x9c(%rbp),%eax
mov    %eax,-0xa0(%rbp)
movslq -0x9c(%rbp),%rax
mov    -0x90(%rbp,%rax,8),%rdi
ff
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0xa0(%rbp),%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movslq -0x9c(%rbp),%rax
mov    -0x90(%rbp,%rax,8),%rsi
ff
lea    0xd1f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    128b <main+0x12b>
movl   $0x0,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
mov    -0x98(%rbp),%rcx
cmp    %ecx,%eax
jge    134d <main+0x1ed>
movslq -0x9c(%rbp),%rax
mov    -0x90(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x9c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c(%rbp)
jmp    1310 <main+0x1b0>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x78,%rsp
movabs $0x6f770a6f6c6c6568,%rax
0a 77 6f
mov    %rax,(%rsp)
movl   $0x646c72,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
lea    0xe8e(%rip),%rdx
mov    %rsp,%rdi
lea    0x20(%rsp),%rsi
call   1070 <strsplit@plt>
mov    %rax,%r15
mov    %r15d,%edi
call   1050 <assert@plt>
test   %r15,%r15
je     11e3 <main+0x93>
xor    %ebx,%ebx
lea    0xe66(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    0x20(%rsp,%rbx,8),%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11b0 <main+0x60>
test   %r15d,%r15d
jle    11e3 <main+0x93>
mov    %r15d,%r14d
xor    %ebx,%ebx
mov    0x20(%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11d0 <main+0x80>
movaps 0xe36(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x392038,0x10(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0xdf7(%rip),%rdx
mov    %rsp,%rdi
lea    0x20(%rsp),%rsi
call   1070 <strsplit@plt>
mov    %rax,%r14
mov    %r14d,%edi
call   1050 <assert@plt>
test   %r14d,%r14d
jle    12a3 <main+0x153>
mov    %r14d,%r12d
xor    %ebx,%ebx
lea    0xdca(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x20(%rsp,%rbx,8),%rdi
call   1060 <atoi@plt>
mov    %eax,%eax
xor    %edi,%edi
cmp    %rax,%rbx
sete   %dil
call   1050 <assert@plt>
mov    0x20(%rsp,%rbx,8),%rsi
mov    %r15,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1250 <main+0x100>
test   %r14d,%r14d
jle    12a3 <main+0x153>
mov    %r14d,%r14d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x20(%rsp,%rbx,8),%rdi
call   1030 <free@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1290 <main+0x140>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.str = [12 x i8] c"hello\0Aworld\00"
@.str = [2 x i8] c"\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@__const.main.str.2 = [20 x i8] c"0 1 2 3 4 5 6 7 8 9\00"
@.str.3 = [2 x i8] c" \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = alloca [2 x i8*]
%4 = alloca i64
%5 = alloca i32
%6 = alloca [20 x i8]
%7 = alloca [10 x i8*]
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %1
%10 = bitcast [12 x i8]* %2 to i8*
%11 = bitcast [2 x i8*]* %3 to i8*
%12 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%13 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%14 = call i64 @strsplit(i8* %12, i8** %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i64 %14, i64* %4
%15 = load i64, i64* %4
%16 = trunc i64 %15 to i32
%17 = call i32 @assert(i32 %16)
store i32 0, i32* %5
br label %18
18: ; preds = %29, %0
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = load i64, i64* %4
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %32
23: ; preds = %18
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %23
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %18
32: ; preds = %18
store i32 0, i32* %5
br label %33
33: ; preds = %44, %32
%34 = load i32, i32* %5
%35 = load i64, i64* %4
%36 = trunc i64 %35 to i32
%37 = icmp slt i32 %34, %36
br i1 %37, label %38, label %47
38: ; preds = %33
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 @free(i8* %42)
br label %44
44: ; preds = %38
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %33
47: ; preds = %33
%48 = bitcast [20 x i8]* %6 to i8*
%49 = bitcast [10 x i8*]* %7 to i8*
%50 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%51 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%52 = call i64 @strsplit(i8* %50, i8** %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i64 %52, i64* %8
%53 = load i64, i64* %8
%54 = trunc i64 %53 to i32
%55 = call i32 @assert(i32 %54)
store i32 0, i32* %9
br label %56
56: ; preds = %76, %47
%57 = load i32, i32* %9
%58 = load i64, i64* %8
%59 = trunc i64 %58 to i32
%60 = icmp slt i32 %57, %59
br i1 %60, label %61, label %79
61: ; preds = %56
%62 = load i32, i32* %9
%63 = load i32, i32* %9
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 %64
%66 = load i8*, i8** %65
%67 = call i32 @atoi(i8* %66)
%68 = icmp eq i32 %62, %67
%69 = zext i1 %68 to i32
%70 = call i32 @assert(i32 %69)
%71 = load i32, i32* %9
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 %72
%74 = load i8*, i8** %73
%75 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %61
%77 = load i32, i32* %9
%78 = add nsw i32 %77, 1
store i32 %78, i32* %9
br label %56
79: ; preds = %56
store i32 0, i32* %9
br label %80
80: ; preds = %91, %79
%81 = load i32, i32* %9
%82 = load i64, i64* %8
%83 = trunc i64 %82 to i32
%84 = icmp slt i32 %81, %83
br i1 %84, label %85, label %94
85: ; preds = %80
%86 = load i32, i32* %9
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 %87
%89 = load i8*, i8** %88
%90 = call i32 @free(i8* %89)
br label %91
91: ; preds = %85
%92 = load i32, i32* %9
%93 = add nsw i32 %92, 1
store i32 %93, i32* %9
br label %80
94: ; preds = %80
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [12 x i8] c"hello\0Aworld\00"
@.str = [2 x i8] c"\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@__const.main.str.2 = [20 x i8] c"0 1 2 3 4 5 6 7 8 9\00"
@.str.3 = [2 x i8] c" \00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = alloca [2 x i8*]
%3 = alloca [20 x i8]
%4 = alloca [10 x i8*]
%5 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%6 = bitcast [2 x i8*]* %2 to i8*
%7 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%8 = call i64 @strsplit(i8* %5, i8** %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = trunc i64 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = icmp eq i64 %8, 0
br i1 %11, label %30, label %16
12: ; preds = %16
%13 = icmp sgt i32 %9, 0
br i1 %13, label %14, label %30
14: ; preds = %12
%15 = and i64 %8, 4294967295
br label %23
16: ; preds = %0, %16
%17 = phi i64 [ %21, %16 ], [ 0, %0 ]
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = add nuw i64 %17, 1
%22 = icmp eq i64 %21, %8
br i1 %22, label %12, label %16
23: ; preds = %14, %23
%24 = phi i64 [ 0, %14 ], [ %28, %23 ]
%25 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @free(i8* %26)
%28 = add nuw nsw i64 %24, 1
%29 = icmp eq i64 %28, %15
br i1 %29, label %30, label %23
30: ; preds = %23, %0, %12
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%32 = bitcast [10 x i8*]* %4 to i8*
%33 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 0
%34 = call i64 @strsplit(i8* %31, i8** %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%35 = trunc i64 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = icmp sgt i32 %35, 0
br i1 %37, label %38, label %63
38: ; preds = %30
%39 = and i64 %34, 4294967295
br label %43
40: ; preds = %43
br i1 %37, label %41, label %63
41: ; preds = %40
%42 = and i64 %34, 4294967295
br label %56
43: ; preds = %38, %43
%44 = phi i64 [ 0, %38 ], [ %54, %43 ]
%45 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 %44
%46 = load i8*, i8** %45
%47 = call i32 @atoi(i8* %46)
%48 = zext i32 %47 to i64
%49 = icmp eq i64 %44, %48
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = load i8*, i8** %45
%53 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %52)
%54 = add nuw nsw i64 %44, 1
%55 = icmp eq i64 %54, %39
br i1 %55, label %40, label %43
56: ; preds = %41, %56
%57 = phi i64 [ 0, %41 ], [ %61, %56 ]
%58 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 %57
%59 = load i8*, i8** %58
%60 = call i32 @free(i8* %59)
%61 = add nuw nsw i64 %57, 1
%62 = icmp eq i64 %61, %42
br i1 %62, label %63, label %56
63: ; preds = %56, %30, %40
ret i32 0
}