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


x86 assembly (clang, -O0):
<argconfig_parse_comma_sep_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
je     1188 <argconfig_parse_comma_sep_array+0x38>
cmpq   $0x0,-0x8(%rbp)
jne    1192 <argconfig_parse_comma_sep_array+0x42>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d4 <argconfig_parse_comma_sep_array+0x84>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1209 <argconfig_parse_comma_sep_array+0xb9>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xde3(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    123a <argconfig_parse_comma_sep_array+0xea>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jb     1250 <argconfig_parse_comma_sep_array+0x100>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1285 <argconfig_parse_comma_sep_array+0x135>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1212 <argconfig_parse_comma_sep_array+0xc2>

x86 assembly (clang, -O2):
<argconfig_parse_comma_sep_array>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmpb   $0x0,(%rdi)
je     11f9 <argconfig_parse_comma_sep_array+0xc9>
mov    %edx,%ebp
mov    %rsi,%r12
lea    0xeaf(%rip),%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     11f9 <argconfig_parse_comma_sep_array+0xc9>
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %eax,(%r12)
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    11f9 <argconfig_parse_comma_sep_array+0xc9>
lea    0xe79(%rip),%rsi
xor    %edi,%edi
call   1040 <strtok@plt>
test   %rax,%rax
je     11e5 <argconfig_parse_comma_sep_array+0xb5>
cmp    $0x2,%ebp
mov    $0x1,%ebx
cmovae %ebp,%ebx
mov    $0x1,%ebp
lea    0x8(%rsp),%r14
lea    0xe51(%rip),%r15
nop
cmp    %rbp,%rbx
je     11f9 <argconfig_parse_comma_sep_array+0xc9>
mov    %rax,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %eax,(%r12,%rbp,4)
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    11f9 <argconfig_parse_comma_sep_array+0xc9>
add    $0x1,%rbp
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
jne    11b0 <argconfig_parse_comma_sep_array+0x80>
jmp    11ea <argconfig_parse_comma_sep_array+0xba>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1050 <exit@plt>

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

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 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%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 %13, label %15
13: ; preds = %10
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %10
%16 = call i32 @strtol(i8* %11, i8** %4, i32 0)
store i32 %16, i32* %1
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %30, label %23
23: ; preds = %20
%24 = call i32 @llvm.umax.i32(i32 %2, i32 1)
%25 = zext i32 %24 to i64
br label %32
26: ; preds = %15
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %46
%29 = trunc i64 %47 to i32
br label %30
30: ; preds = %28, %20
%31 = phi i32 [ 1, %20 ], [ %29, %28 ]
ret i32 %31
32: ; preds = %23, %46
%33 = phi i64 [ 1, %23 ], [ %47, %46 ]
%34 = phi i8* [ %21, %23 ], [ %48, %46 ]
%35 = icmp eq i64 %33, %25
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %32
%39 = call i32 @strtol(i8* %34, i8** %4, i32 0)
%40 = getelementptr inbounds i32, i32* %1, i64 %33
store i32 %39, i32* %40
%41 = load i8*, i8** %4
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %38
%45 = tail call i32 @exit(i32 1)
unreachable
46: ; preds = %38
%47 = add nuw nsw i64 %33, 1
%48 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%49 = icmp eq i8* %48, null
br i1 %49, label %28, label %32
}