#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 */
scalar_t__ malloc(scalar_t__);
char *strLabel(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int line2fields(char *pBuf, int max_fields, char *pField[]) {
  char *p, temp[100];
  int fld_cnt = 0;
  if ((p = strchr(pBuf, '\n')) != NULL)
    *p = 0;
  if ((p = strchr(pBuf, '\r')) != NULL)
    *p = 0;
  p = pBuf;
  do {
    pField[fld_cnt] = NULL;
    p = strLabel(p, temp);
    pField[fld_cnt] = (char *)malloc(strlen(temp) + 1);
    strcpy(pField[fld_cnt++], temp);
  } while (*p != 0);
  return fld_cnt;
}


x86 assembly (clang, -O0):
<line2fields>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x94(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1193 <line2fields+0x43>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0xd,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11b6 <line2fields+0x66>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x94(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1070 <strLabel@plt>
mov    %rax,-0x20(%rbp)
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x94(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0x94(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x94(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x90(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11be <line2fields+0x6e>
mov    -0x94(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<line2fields>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdx,%r14
mov    %rdi,%r15
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1173 <line2fields+0x23>
movb   $0x0,(%rax)
mov    %r15,%rdi
mov    $0xd,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1188 <line2fields+0x38>
movb   $0x0,(%rax)
xor    %ebx,%ebx
mov    %rsp,%r12
nopl   (%rax)
movq   $0x0,(%r14,%rbx,8)
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <strLabel@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
cmpb   $0x0,(%r15)
jne    1190 <line2fields+0x40>
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @line2fields(i8* %0, i32 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca [100 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
store i32 0, i32* %9
%10 = load i8*, i8** %4
%11 = call i8* @strchr(i8* %10, i8 signext 10)
store i8* %11, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load i8*, i8** %7
store i8 0, i8* %14
br label %15
15: ; preds = %13, %3
%16 = load i8*, i8** %4
%17 = call i8* @strchr(i8* %16, i8 signext 13)
store i8* %17, i8** %7
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load i8*, i8** %7
store i8 0, i8* %20
br label %21
21: ; preds = %19, %15
%22 = load i8*, i8** %4
store i8* %22, i8** %7
br label %23
23: ; preds = %48, %21
%24 = load i8**, i8*** %6
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
store i8* null, i8** %27
%28 = load i8*, i8** %7
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%30 = call i8* @strLabel(i8* %28, i8* %29)
store i8* %30, i8** %7
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%32 = call i64 @strlen(i8* %31)
%33 = add nsw i64 %32, 1
%34 = call i64 @malloc(i64 %33)
%35 = inttoptr i64 %34 to i8*
%36 = load i8**, i8*** %6
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %36, i64 %38
store i8* %35, i8** %39
%40 = load i8**, i8*** %6
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i8*, i8** %40, i64 %43
%45 = load i8*, i8** %44
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%47 = call i32 @strcpy(i8* %45, i8* %46)
br label %48
48: ; preds = %23
%49 = load i8*, i8** %7
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 0
br i1 %52, label %23, label %53
53: ; preds = %48
%54 = load i32, i32* %9
ret i32 %54
}

LLVM IR (-O2):
define i32 @line2fields(i8* %0, i32 %1, i8** nocapture writeonly %2) {
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%7 = icmp eq i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %3
store i8 0, i8* %6
br label %9
9: ; preds = %8, %3
%10 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 13)
%11 = icmp eq i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %9
store i8 0, i8* %10
br label %13
13: ; preds = %12, %9
br label %14
14: ; preds = %13, %14
%15 = phi i64 [ %23, %14 ], [ 0, %13 ]
%16 = phi i8* [ %18, %14 ], [ %0, %13 ]
%17 = getelementptr inbounds i8*, i8** %2, i64 %15
store i8* null, i8** %17
%18 = call i8* @strLabel(i8* %16, i8* %5)
%19 = call i64 @strlen(i8* %5)
%20 = add nsw i64 %19, 1
%21 = call i64 @malloc(i64 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %17
%23 = add nuw i64 %15, 1
%24 = call i32 @strcpy(i8* %22, i8* %5)
%25 = load i8, i8* %18
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %14
27: ; preds = %14
%28 = trunc i64 %23 to i32
ret i32 %28
}