#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 */
unsigned long UINT_MAX;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
char *strtok(char *, char *);
unsigned long strtoul(char *, char **, int /*<<< orphan*/);
int argconfig_parse_comma_sep_array(char *string, int *val,
                                    unsigned max_length) {
  int ret = 0;
  unsigned long v;
  char *tmp;
  char *p;
  if (!string || !strlen(string))
    return 0;
  tmp = strtok(string, ",");
  if (!tmp)
    return 0;
  v = strtoul(tmp, &p, 0);
  if (*p != 0)
    return -1;
  if (v > UINT_MAX) {
    fprintf(stderr, "%s out of range\n", tmp);
    return -1;
  }
  val[ret] = v;
  ret++;
  while (1) {
    tmp = strtok(NULL, ",");
    if (tmp == NULL)
      return ret;
    if (ret >= max_length)
      return -1;
    v = strtoul(tmp, &p, 0);
    if (*p != 0)
      return -1;
    if (v > UINT_MAX) {
      fprintf(stderr, "%s out of range\n", tmp);
      return -1;
    }
    val[ret] = v;
    ret++;
  }
}


x86 assembly (clang, -O0):
<argconfig_parse_comma_sep_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1177 <argconfig_parse_comma_sep_array+0x37>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    1183 <argconfig_parse_comma_sep_array+0x43>
movl   $0x0,-0x4(%rbp)
jmp    12f9 <argconfig_parse_comma_sep_array+0x1b9>
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11ae <argconfig_parse_comma_sep_array+0x6e>
movl   $0x0,-0x4(%rbp)
jmp    12f9 <argconfig_parse_comma_sep_array+0x1b9>
mov    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11dd <argconfig_parse_comma_sep_array+0x9d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f9 <argconfig_parse_comma_sep_array+0x1b9>
mov    -0x28(%rbp),%rax
mov    0x2e00(%rip),%rcx
cmp    (%rcx),%rax
jbe    1216 <argconfig_parse_comma_sep_array+0xd6>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xdfd(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f9 <argconfig_parse_comma_sep_array+0x1b9>
mov    -0x28(%rbp),%rax
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc5(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    125a <argconfig_parse_comma_sep_array+0x11a>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12f9 <argconfig_parse_comma_sep_array+0x1b9>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jb     1272 <argconfig_parse_comma_sep_array+0x132>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f9 <argconfig_parse_comma_sep_array+0x1b9>
mov    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12a1 <argconfig_parse_comma_sep_array+0x161>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f9 <argconfig_parse_comma_sep_array+0x1b9>
mov    -0x28(%rbp),%rax
mov    0x2d3c(%rip),%rcx
cmp    (%rcx),%rax
jbe    12da <argconfig_parse_comma_sep_array+0x19a>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xd39(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f9 <argconfig_parse_comma_sep_array+0x1b9>
mov    -0x28(%rbp),%rax
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1230 <argconfig_parse_comma_sep_array+0xf0>
mov    -0x4(%rbp),%eax
add    $0x40,%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     1249 <argconfig_parse_comma_sep_array+0x109>
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbp
call   1030 <strlen@plt>
test   %eax,%eax
je     1249 <argconfig_parse_comma_sep_array+0x109>
lea    0xe8d(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     1249 <argconfig_parse_comma_sep_array+0x109>
mov    %rax,%rbp
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    (%rsp),%rcx
mov    $0xffffffff,%ebx
cmpb   $0x0,(%rcx)
jne    1249 <argconfig_parse_comma_sep_array+0x109>
mov    0x2e3b(%rip),%r13
cmp    0x0(%r13),%rax
jbe    11cd <argconfig_parse_comma_sep_array+0x8d>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
mov    %rbp,%rdx
call   1040 <fprintf@plt>
jmp    1249 <argconfig_parse_comma_sep_array+0x109>
mov    %eax,(%r14)
lea    0xe29(%rip),%rsi
xor    %edi,%edi
call   1050 <strtok@plt>
test   %rax,%rax
je     1244 <argconfig_parse_comma_sep_array+0x104>
mov    %rax,%rbp
cmp    $0x2,%r15d
mov    $0x1,%r12d
cmovae %r15d,%r12d
mov    $0x1,%r15d
nopw   0x0(%rax,%rax,1)
cmp    %r15,%r12
je     1249 <argconfig_parse_comma_sep_array+0x109>
mov    %rbp,%rdi
mov    %rsp,%rsi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1249 <argconfig_parse_comma_sep_array+0x109>
cmp    0x0(%r13),%rax
ja     11b3 <argconfig_parse_comma_sep_array+0x73>
mov    %eax,(%r14,%r15,4)
add    $0x1,%r15
xor    %edi,%edi
lea    0xdce(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1200 <argconfig_parse_comma_sep_array+0xc0>
mov    %r15d,%ebx
jmp    1249 <argconfig_parse_comma_sep_array+0x109>
mov    $0x1,%ebx
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"
@UINT_MAX = global i64 0
@stderr = global i32 0
@.str.1 = [17 x i8] c"%s out of range\0A\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 i64
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 0, i32* %8
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %14, %3
store i32 0, i32* %4
br label %86
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = call i8* @strtok(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %21, i8** %10
%22 = load i8*, i8** %10
%23 = icmp ne i8* %22, null
br i1 %23, label %25, label %24
24: ; preds = %19
store i32 0, i32* %4
br label %86
25: ; preds = %19
%26 = load i8*, i8** %10
%27 = call i64 @strtoul(i8* %26, i8** %11, i32 0)
store i64 %27, i64* %9
%28 = load i8*, i8** %11
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %25
store i32 -1, i32* %4
br label %86
33: ; preds = %25
%34 = load i64, i64* %9
%35 = load i64, i64* @UINT_MAX
%36 = icmp ugt i64 %34, %35
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %10
%40 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %39)
store i32 -1, i32* %4
br label %86
41: ; preds = %33
%42 = load i64, i64* %9
%43 = trunc i64 %42 to i32
%44 = load i32*, i32** %6
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
store i32 %43, i32* %47
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %50
50: ; preds = %41, %77
%51 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %51, i8** %10
%52 = load i8*, i8** %10
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = load i32, i32* %8
store i32 %55, i32* %4
br label %86
56: ; preds = %50
%57 = load i32, i32* %8
%58 = load i32, i32* %7
%59 = icmp uge i32 %57, %58
br i1 %59, label %60, label %61
60: ; preds = %56
store i32 -1, i32* %4
br label %86
61: ; preds = %56
%62 = load i8*, i8** %10
%63 = call i64 @strtoul(i8* %62, i8** %11, i32 0)
store i64 %63, i64* %9
%64 = load i8*, i8** %11
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %69
68: ; preds = %61
store i32 -1, i32* %4
br label %86
69: ; preds = %61
%70 = load i64, i64* %9
%71 = load i64, i64* @UINT_MAX
%72 = icmp ugt i64 %70, %71
br i1 %72, label %73, label %77
73: ; preds = %69
%74 = load i32, i32* @stderr
%75 = load i8*, i8** %10
%76 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %75)
store i32 -1, i32* %4
br label %86
77: ; preds = %69
%78 = load i64, i64* %9
%79 = trunc i64 %78 to i32
%80 = load i32*, i32** %6
%81 = load i32, i32* %8
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i32, i32* %80, i64 %82
store i32 %79, i32* %83
%84 = load i32, i32* %8
%85 = add nsw i32 %84, 1
store i32 %85, i32* %8
br label %50
86: ; preds = %73, %68, %60, %54, %37, %32, %24, %18
%87 = load i32, i32* %4
ret i32 %87
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@UINT_MAX = global i64 0
@stderr = global i32 0
@.str.1 = [17 x i8] c"%s out of range\0A\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 %54, label %7
7: ; preds = %3
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %54, 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 %54, label %13
13: ; preds = %10
%14 = call i64 @strtoul(i8* %11, i8** %4, i32 0)
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %54
18: ; preds = %13
%19 = load i64, i64* @UINT_MAX
%20 = icmp ugt i64 %14, %19
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %54
24: ; preds = %18
%25 = trunc i64 %14 to i32
store i32 %25, i32* %1
%26 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i8* %26, null
br i1 %27, label %54, label %28
28: ; preds = %24
%29 = call i32 @llvm.umax.i32(i32 %2, i32 1)
%30 = zext i32 %29 to i64
br label %31
31: ; preds = %28, %46
%32 = phi i64 [ 1, %28 ], [ %49, %46 ]
%33 = phi i8* [ %26, %28 ], [ %50, %46 ]
%34 = icmp eq i64 %32, %30
br i1 %34, label %54, label %35
35: ; preds = %31
%36 = call i64 @strtoul(i8* %33, i8** %4, i32 0)
%37 = load i8*, i8** %4
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 0
br i1 %39, label %40, label %54
40: ; preds = %35
%41 = load i64, i64* @UINT_MAX
%42 = icmp ugt i64 %36, %41
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = tail call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %33)
br label %54
46: ; preds = %40
%47 = trunc i64 %36 to i32
%48 = getelementptr inbounds i32, i32* %1, i64 %32
store i32 %47, i32* %48
%49 = add nuw nsw i64 %32, 1
%50 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %31
52: ; preds = %46
%53 = trunc i64 %49 to i32
br label %54
54: ; preds = %35, %31, %52, %24, %13, %10, %3, %7, %43, %21
%55 = phi i32 [ -1, %21 ], [ -1, %43 ], [ 0, %7 ], [ 0, %3 ], [ 0, %10 ], [ -1, %13 ], [ 1, %24 ], [ %53, %52 ], [ -1, %31 ], [ -1, %35 ]
ret i32 %55
}