#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 *strchr(char *, int);
void parse_fields(char *line, int delim, char **start) {
  int pos = 0;
  start[pos++] = line;
  while ((line = strchr(line, delim)) != NULL) {
    *line++ = '\0';
    start[pos++] = line;
  }
}


x86 assembly (clang, -O0):
<parse_fields>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     118f <parse_fields+0x7f>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1144 <parse_fields+0x34>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_fields>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,(%rdx)
call   1030 <strchr@plt>
test   %rax,%rax
je     114d <parse_fields+0x3d>
add    $0x8,%rbx
nopl   0x0(%rax)
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,(%rbx)
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
add    $0x8,%rbx
test   %rax,%rax
jne    1130 <parse_fields+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define void @parse_fields(i8* %0, i32 %1, i8** nocapture writeonly %2) {
store i8* %0, i8** %2
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %14, label %6
6: ; preds = %3, %6
%7 = phi i64 [ %10, %6 ], [ 1, %3 ]
%8 = phi i8* [ %12, %6 ], [ %4, %3 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
store i8 0, i8* %8
%10 = add nuw i64 %7, 1
%11 = getelementptr inbounds i8*, i8** %2, i64 %7
store i8* %9, i8** %11
%12 = tail call i8* @strchr(i8* dereferenceable(1) %9, i32 %1)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %6
14: ; preds = %6, %3
ret void
}