#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 */
char *strtok(char *, char *);
int split_lines(char *token, char *buffer, char **output, int max_size) {
  char *tok = NULL;
  int count = 0;
  tok = strtok(buffer, token);
  while (tok != NULL) {
    if (count > max_size - 1)
      break;
    output[count] = tok;
    count++;
    tok = strtok(NULL, token);
  }
  return count;
}


x86 assembly (clang, -O0):
<split_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1197 <split_lines+0x87>
mov    -0x2c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    1168 <split_lines+0x58>
jmp    1197 <split_lines+0x87>
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1030 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1147 <split_lines+0x37>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_lines>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
mov    %r15,%rsi
call   1030 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     115c <split_lines+0x4c>
test   %ebp,%ebp
jle    115c <split_lines+0x4c>
mov    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r15,%rsi
call   1030 <strtok@plt>
test   %rax,%rax
je     115c <split_lines+0x4c>
cmp    %rbp,%rbx
jb     1140 <split_lines+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @split_lines(i8* nocapture %0, i8* %1, i8** nocapture writeonly %2, i32 %3) {
%5 = tail call i8* @strtok(i8* %1, i8* %0)
%6 = icmp ne i8* %5, null
%7 = icmp sgt i32 %3, 0
%8 = and i1 %6, %7
br i1 %8, label %9, label %22
9: ; preds = %4
%10 = zext i32 %3 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %15, %11 ]
%13 = phi i8* [ %5, %9 ], [ %16, %11 ]
%14 = getelementptr inbounds i8*, i8** %2, i64 %12
store i8* %13, i8** %14
%15 = add nuw nsw i64 %12, 1
%16 = tail call i8* @strtok(i8* null, i8* %0)
%17 = icmp ne i8* %16, null
%18 = icmp ult i64 %15, %10
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %11, label %20
20: ; preds = %11
%21 = trunc i64 %15 to i32
br label %22
22: ; preds = %20, %4
%23 = phi i32 [ 0, %4 ], [ %21, %20 ]
ret i32 %23
}