#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 *, char);
int _split_string_by_comma(char *string, char **values, int max_values) {
  int i = 0;
  values[i++] = string;
  while (i < max_values && NULL != (string = strchr(string, ','))) {
    *string = '\0';
    values[i++] = ++string;
  }
  return i;
}


x86 assembly (clang, -O0):
<_split_string_by_comma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x19(%rbp)
jge    1175 <_split_string_by_comma+0x65>
mov    -0x8(%rbp),%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
mov    %rcx,-0x8(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1185 <_split_string_by_comma+0x75>
jmp    11b3 <_split_string_by_comma+0xa3>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1144 <_split_string_by_comma+0x34>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_split_string_by_comma>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,(%rsi)
mov    $0x1,%ebx
cmp    $0x2,%edx
jl     1159 <_split_string_by_comma+0x49>
mov    %rsi,%r14
mov    %rdi,%rax
mov    %edx,%r15d
mov    $0x1,%ebx
mov    %rax,%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1159 <_split_string_by_comma+0x49>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <_split_string_by_comma+0x20>
mov    %r15d,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @_split_string_by_comma(i8* %0, i8** %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = load i8**, i8*** %5
%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 = %24, %3
%15 = load i32, i32* %7
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = call i8* @strchr(i8* %19, i8 signext 44)
store i8* %20, i8** %4
%21 = icmp ne i8* null, %20
br label %22
22: ; preds = %18, %14
%23 = phi i1 [ false, %14 ], [ %21, %18 ]
br i1 %23, label %24, label %33
24: ; preds = %22
%25 = load i8*, i8** %4
store i8 0, i8* %25
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %4
%28 = load i8**, i8*** %5
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8*, i8** %28, i64 %31
store i8* %27, i8** %32
br label %14
33: ; preds = %22
%34 = load i32, i32* %7
ret i32 %34
}

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