#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*/ str_trim_crlf(char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int split(char *str, char *seg, char array[][100]) {
  int i = 0;
  char *substr = strtok(str, seg);
  while (substr != NULL) {
    str_trim_crlf(substr);
    strcpy(array[i], substr);
    substr = strtok(NULL, seg);
    i++;
  }
  return i;
}


x86 assembly (clang, -O0):
<split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11a7 <split+0x77>
mov    -0x28(%rbp),%rdi
call   1050 <str_trim_crlf@plt>
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
imul   $0x64,%rax,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115c <split+0x2c>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
call   1040 <strtok@plt>
test   %rax,%rax
je     117f <split+0x4f>
mov    %rax,%rbx
xor    %r15d,%r15d
xchg   %ax,%ax
mov    %rbx,%rdi
call   1050 <str_trim_crlf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
mov    %rax,%rbx
add    $0x64,%r12
add    $0x1,%r15d
test   %rax,%rax
jne    1150 <split+0x20>
jmp    1182 <split+0x52>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @split(i8* %0, i8* %1, [100 x i8]* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [100 x i8]*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store [100 x i8]* %2, [100 x i8]** %6
store i32 0, i32* %7
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i8* @strtok(i8* %9, i8* %10)
store i8* %11, i8** %8
br label %12
12: ; preds = %15, %3
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = load i8*, i8** %8
%17 = call i32 @str_trim_crlf(i8* %16)
%18 = load [100 x i8]*, [100 x i8]** %6
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %18, i64 %20
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %21, i64 0, i64 0
%23 = load i8*, i8** %8
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %5
%26 = call i8* @strtok(i8* null, i8* %25)
store i8* %26, i8** %8
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %12
29: ; preds = %12
%30 = load i32, i32* %7
ret i32 %30
}

LLVM IR (-O2):
define i32 @split(i8* %0, i8* nocapture %1, [100 x i8]* %2) {
%4 = tail call i8* @strtok(i8* %0, i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %17, label %6
6: ; preds = %3, %6
%7 = phi i64 [ %13, %6 ], [ 0, %3 ]
%8 = phi i8* [ %12, %6 ], [ %4, %3 ]
%9 = tail call i32 @str_trim_crlf(i8* %8)
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 %7, i64 0
%11 = tail call i32 @strcpy(i8* %10, i8* %8)
%12 = tail call i8* @strtok(i8* null, i8* %1)
%13 = add nuw i64 %7, 1
%14 = icmp eq i8* %12, null
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = trunc i64 %13 to i32
br label %17
17: ; preds = %15, %3
%18 = phi i32 [ 0, %3 ], [ %16, %15 ]
ret i32 %18
}