#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*/ str_trim_ht(char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int split(char *str, char *seg, char array[][100]) {
  int i = 0;
  str_trim_ht(str);
  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
call   1050 <str_trim_ht@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11c0 <split+0x80>
mov    -0x28(%rbp),%rdi
call   1060 <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    1175 <split+0x35>
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,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <str_trim_ht@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     119f <split+0x5f>
mov    %rax,%rbx
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <str_trim_crlf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
mov    %rax,%rbx
add    $0x64,%r15
add    $0x1,%r12d
test   %rax,%rax
jne    1170 <split+0x30>
jmp    11a2 <split+0x62>
xor    %r12d,%r12d
mov    %r12d,%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 = call i32 @str_trim_ht(i8* %9)
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i8* @strtok(i8* %11, i8* %12)
store i8* %13, i8** %8
br label %14
14: ; preds = %17, %3
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = load i8*, i8** %8
%19 = call i32 @str_trim_crlf(i8* %18)
%20 = load [100 x i8]*, [100 x i8]** %6
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %20, i64 %22
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %23, i64 0, i64 0
%25 = load i8*, i8** %8
%26 = call i32 @strcpy(i8* %24, i8* %25)
%27 = load i8*, i8** %5
%28 = call i8* @strtok(i8* null, i8* %27)
store i8* %28, i8** %8
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %14
31: ; preds = %14
%32 = load i32, i32* %7
ret i32 %32
}

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