#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 /*<<< orphan*/ strlen(char *);
char *strtok(char *, char *);
int strtol(char *, char **, int /*<<< orphan*/);
unsigned argconfig_parse_comma_sep_array(char *string, int *val,
                                         unsigned max_length) {
  unsigned ret = 0;
  char *tmp;
  char *p;
  if (!string || !strlen(string))
    return 0;
  tmp = strtok(string, ",");
  if (!tmp)
    return 0;
  val[ret] = strtol(tmp, &p, 0);
  if (*p != 0)
    return -1;
  ret++;
  while (1) {
    tmp = strtok(NULL, ",");
    if (tmp == NULL)
      return ret;
    if (ret >= max_length)
      return -1;
    val[ret] = strtol(tmp, &p, 0);
    if (*p != 0)
      return -1;
    ret++;
  }
}


x86 assembly (clang, -O0):
<argconfig_parse_comma_sep_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1167 <argconfig_parse_comma_sep_array+0x37>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    1173 <argconfig_parse_comma_sep_array+0x43>
movl   $0x0,-0x4(%rbp)
jmp    1265 <argconfig_parse_comma_sep_array+0x135>
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119e <argconfig_parse_comma_sep_array+0x6e>
movl   $0x0,-0x4(%rbp)
jmp    1265 <argconfig_parse_comma_sep_array+0x135>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d5 <argconfig_parse_comma_sep_array+0xa5>
movl   $0xffffffff,-0x4(%rbp)
jmp    1265 <argconfig_parse_comma_sep_array+0x135>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe17(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1208 <argconfig_parse_comma_sep_array+0xd8>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1265 <argconfig_parse_comma_sep_array+0x135>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jb     1220 <argconfig_parse_comma_sep_array+0xf0>
movl   $0xffffffff,-0x4(%rbp)
jmp    1265 <argconfig_parse_comma_sep_array+0x135>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1257 <argconfig_parse_comma_sep_array+0x127>
movl   $0xffffffff,-0x4(%rbp)
jmp    1265 <argconfig_parse_comma_sep_array+0x135>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11de <argconfig_parse_comma_sep_array+0xae>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argconfig_parse_comma_sep_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %rdi,%rdi
je     1186 <argconfig_parse_comma_sep_array+0x56>
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbp
call   1030 <strlen@plt>
test   %eax,%eax
je     1186 <argconfig_parse_comma_sep_array+0x56>
lea    0xea5(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     1186 <argconfig_parse_comma_sep_array+0x56>
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,(%r14)
mov    (%rsp),%rax
mov    $0xffffffff,%ebx
cmpb   $0x0,(%rax)
je     1197 <argconfig_parse_comma_sep_array+0x67>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe62(%rip),%rsi
xor    %edi,%edi
call   1050 <strtok@plt>
test   %rax,%rax
je     1206 <argconfig_parse_comma_sep_array+0xd6>
cmp    $0x2,%r15d
mov    $0x1,%r13d
cmovae %r15d,%r13d
mov    $0x1,%ebp
mov    %rsp,%r15
lea    0xe39(%rip),%r12
nopw   0x0(%rax,%rax,1)
cmp    %rbp,%r13
je     1186 <argconfig_parse_comma_sep_array+0x56>
mov    %rax,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,(%r14,%rbp,4)
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
jne    1186 <argconfig_parse_comma_sep_array+0x56>
add    $0x1,%rbp
xor    %edi,%edi
mov    %r12,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    11d0 <argconfig_parse_comma_sep_array+0xa0>
mov    %ebp,%ebx
jmp    1186 <argconfig_parse_comma_sep_array+0x56>
mov    $0x1,%ebx
jmp    1186 <argconfig_parse_comma_sep_array+0x56>

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

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define i32 @argconfig_parse_comma_sep_array(i8* %0, i32* nocapture writeonly %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = icmp eq i8* %0, null
br i1 %6, label %40, label %7
7: ; preds = %3
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %40, label %10
10: ; preds = %7
%11 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %40, label %13
13: ; preds = %10
%14 = call i32 @strtol(i8* %11, i8** %4, i32 0)
store i32 %14, i32* %1
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %40
18: ; preds = %13
%19 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %40, label %21
21: ; preds = %18
%22 = call i32 @llvm.umax.i32(i32 %2, i32 1)
%23 = zext i32 %22 to i64
br label %24
24: ; preds = %21, %34
%25 = phi i64 [ 1, %21 ], [ %35, %34 ]
%26 = phi i8* [ %19, %21 ], [ %36, %34 ]
%27 = icmp eq i64 %25, %23
br i1 %27, label %40, label %28
28: ; preds = %24
%29 = call i32 @strtol(i8* %26, i8** %4, i32 0)
%30 = getelementptr inbounds i32, i32* %1, i64 %25
store i32 %29, i32* %30
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %28
%35 = add nuw nsw i64 %25, 1
%36 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %24
38: ; preds = %34
%39 = trunc i64 %35 to i32
br label %40
40: ; preds = %28, %24, %38, %18, %13, %10, %3, %7
%41 = phi i32 [ 0, %7 ], [ 0, %3 ], [ 0, %10 ], [ -1, %13 ], [ 1, %18 ], [ %39, %38 ], [ -1, %24 ], [ -1, %28 ]
ret i32 %41
}