#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 get_1st_field(char *, int, char *, char *, int *);
int str_2_fields(char *record, int arrSz, char *fieldArr[]) {
  int nkey = 0, keylen = 0, pos = 0;
  keylen = get_1st_field(record, 0, " ", " ,", &pos);
  while (keylen && nkey < arrSz) {
    fieldArr[nkey++] = &record[pos];
    if (record[pos + keylen] == 0) {
      break;
    } else {
      record[pos + keylen] = 0;
      keylen = get_1st_field(record, pos + keylen + 1, " ,", " ,", &pos);
    }
  }
  return nkey;
}


x86 assembly (clang, -O0):
<str_2_fields>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
lea    0xebb(%rip),%rdx
lea    0xeb6(%rip),%rcx
lea    -0x24(%rbp),%r8
call   1030 <get_1st_field@plt>
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x20(%rbp)
mov    %al,-0x25(%rbp)
je     1173 <str_2_fields+0x63>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1183 <str_2_fields+0x73>
jmp    11fc <str_2_fields+0xec>
mov    -0x8(%rbp),%rdx
movslq -0x24(%rbp),%rax
add    %rax,%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),%rax
mov    -0x24(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    11c3 <str_2_fields+0xb3>
jmp    11fc <str_2_fields+0xec>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    -0x20(%rbp),%esi
add    $0x1,%esi
lea    0xe1a(%rip),%rcx
lea    -0x24(%rbp),%r8
mov    %rcx,%rdx
call   1030 <get_1st_field@plt>
mov    %eax,-0x20(%rbp)
jmp    1158 <str_2_fields+0x48>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_2_fields>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
movl   $0x0,0x4(%rsp)
lea    0xece(%rip),%rdx
lea    0xec9(%rip),%rcx
xor    %ebx,%ebx
lea    0x4(%rsp),%r8
xor    %esi,%esi
call   1030 <get_1st_field@plt>
test   %eax,%eax
je     11b3 <str_2_fields+0xa3>
test   %ebp,%ebp
jle    11b3 <str_2_fields+0xa3>
mov    %ebp,%ebp
mov    $0x1,%ecx
lea    0xea5(%rip),%r12
lea    0x4(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rcx,%rbx
movslq 0x4(%rsp),%rcx
lea    (%r15,%rcx,1),%rdx
mov    %rdx,-0x8(%r14,%rbx,8)
cltq
add    %rcx,%rax
cmpb   $0x0,(%r15,%rax,1)
je     11b3 <str_2_fields+0xa3>
movb   $0x0,(%r15,%rax,1)
lea    0x1(%rax),%esi
mov    %r15,%rdi
mov    %r12,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1030 <get_1st_field@plt>
test   %eax,%eax
je     11b3 <str_2_fields+0xa3>
lea    0x1(%rbx),%rcx
cmp    %rbp,%rbx
jb     1170 <str_2_fields+0x60>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c" ,\00"
define i32 @str_2_fields(i8* %0, i32 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%10 = load i8*, i8** %4
%11 = call i32 @get_1st_field(i8* %10, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
store i32 %11, i32* %8
br label %12
12: ; preds = %54, %3
%13 = load i32, i32* %8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* %7
%17 = load i32, i32* %5
%18 = icmp slt i32 %16, %17
br label %19
19: ; preds = %15, %12
%20 = phi i1 [ false, %12 ], [ %18, %15 ]
br i1 %20, label %21, label %55
21: ; preds = %19
%22 = load i8*, i8** %4
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8**, i8*** %6
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8*, i8** %26, i64 %29
store i8* %25, i8** %30
%31 = load i8*, i8** %4
%32 = load i32, i32* %9
%33 = load i32, i32* %8
%34 = add nsw i32 %32, %33
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %31, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %21
br label %55
41: ; preds = %21
%42 = load i8*, i8** %4
%43 = load i32, i32* %9
%44 = load i32, i32* %8
%45 = add nsw i32 %43, %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %42, i64 %46
store i8 0, i8* %47
%48 = load i8*, i8** %4
%49 = load i32, i32* %9
%50 = load i32, i32* %8
%51 = add nsw i32 %49, %50
%52 = add nsw i32 %51, 1
%53 = call i32 @get_1st_field(i8* %48, i32 %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
store i32 %53, i32* %8
br label %54
54: ; preds = %41
br label %12
55: ; preds = %40, %19
%56 = load i32, i32* %7
ret i32 %56
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c" ,\00"
define i32 @str_2_fields(i8* %0, i32 %1, i8** nocapture writeonly %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%6 = call i32 @get_1st_field(i8* %0, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%7 = icmp ne i32 %6, 0
%8 = icmp sgt i32 %1, 0
%9 = and i1 %7, %8
br i1 %9, label %10, label %33
10: ; preds = %3
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %10, %25
%13 = phi i64 [ 0, %10 ], [ %18, %25 ]
%14 = phi i32 [ %6, %10 ], [ %27, %25 ]
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = add nuw nsw i64 %13, 1
%19 = getelementptr inbounds i8*, i8** %2, i64 %13
store i8* %17, i8** %19
%20 = add nsw i32 %15, %14
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %12
store i8 0, i8* %22
%26 = add nsw i32 %20, 1
%27 = call i32 @get_1st_field(i8* %0, i32 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%28 = icmp ne i32 %27, 0
%29 = icmp ult i64 %18, %11
%30 = select i1 %28, i1 %29, i1 false
br i1 %30, label %12, label %31
31: ; preds = %12, %25
%32 = trunc i64 %18 to i32
br label %33
33: ; preds = %31, %3
%34 = phi i32 [ 0, %3 ], [ %32, %31 ]
ret i32 %34
}