#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*/ chomp(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t, size_t);
int /*<<< orphan*/ stderr;
char *strsep(char **, char *);
int split(char *parts[64], char *str, size_t expected_count) {
  char *part;
  size_t i;
  i = (size_t)0U;
  chomp(str);
  while ((part = strsep(&str, " \t")) != NULL) {
    parts[i] = part;
    i++;
  }
  if (expected_count != i) {
    fprintf(stderr, "Expected %zu parts, found %zu\n", expected_count, i);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <chomp@plt>
lea    -0x18(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1040 <strsep@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1194 <split+0x64>
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1155 <split+0x25>
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     11cb <split+0x9b>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe49(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <split+0xa2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%r12
mov    %rsi,(%rsp)
mov    %rsi,%rdi
call   1050 <chomp@plt>
lea    0xeac(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strsep@plt>
xor    %r15d,%r15d
xor    %ebx,%ebx
test   %rax,%rax
je     1188 <split+0x58>
lea    0xe93(%rip),%r13
mov    %rsp,%rbp
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
mov    %rbp,%rdi
mov    %r13,%rsi
call   1040 <strsep@plt>
test   %rax,%rax
jne    1170 <split+0x40>
cmp    %r14,%rbx
je     11ae <split+0x7e>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c" \09\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"Expected %zu parts, found %zu\0A\00"
define i32 @split(i8** %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64 0, i64* %9
%10 = load i8*, i8** %6
%11 = call i32 @chomp(i8* %10)
br label %12
12: ; preds = %15, %3
%13 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i8*, i8** %8
%17 = load i8**, i8*** %5
%18 = load i64, i64* %9
%19 = getelementptr inbounds i8*, i8** %17, i64 %18
store i8* %16, i8** %19
%20 = load i64, i64* %9
%21 = add i64 %20, 1
store i64 %21, i64* %9
br label %12
22: ; preds = %12
%23 = load i64, i64* %7
%24 = load i64, i64* %9
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i64, i64* %7
%29 = load i64, i64* %9
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i64 %28, i64 %29)
store i32 -1, i32* %4
br label %32
31: ; preds = %22
store i32 0, i32* %4
br label %32
32: ; preds = %31, %26
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@.str = [3 x i8] c" \09\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"Expected %zu parts, found %zu\0A\00"
define i32 @split(i8** nocapture writeonly %0, i8* %1, i64 %2) {
%4 = alloca i8*
store i8* %1, i8** %4
%5 = tail call i32 @chomp(i8* %1)
%6 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %15, label %8
8: ; preds = %3, %8
%9 = phi i8* [ %13, %8 ], [ %6, %3 ]
%10 = phi i64 [ %12, %8 ], [ 0, %3 ]
%11 = getelementptr inbounds i8*, i8** %0, i64 %10
store i8* %9, i8** %11
%12 = add i64 %10, 1
%13 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %8
15: ; preds = %8, %3
%16 = phi i64 [ 0, %3 ], [ %12, %8 ]
%17 = icmp eq i64 %16, %2
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i64 %2, i64 %16)
br label %21
21: ; preds = %15, %18
%22 = phi i32 [ -1, %18 ], [ 0, %15 ]
ret i32 %22
}