#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 atoi(char *);
char *strtok_r(char *, char *, char **);
void parse_collist(char *collist, int *icols, int *n) {
  char *item;
  char *toksave;
  int v, i = 0;
  item = strtok_r(collist, " ,", &toksave);
  if (item[0] == 0)
    return;
  v = atoi(item);
  icols[i] = v;
  i++;
  while ((item = strtok_r(NULL, " ,", &toksave)) != NULL) {
    v = atoi(item);
    icols[i] = v;
    i++;
  }
  *n = i;
}


x86 assembly (clang, -O0):
<parse_collist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeba(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1168 <parse_collist+0x48>
jmp    11de <parse_collist+0xbe>
mov    -0x20(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe6a(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11d5 <parse_collist+0xb5>
mov    -0x20(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    118b <parse_collist+0x6b>
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_collist>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r13
lea    0xec6(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1030 <strtok_r@plt>
cmpb   $0x0,(%rax)
je     11ad <parse_collist+0x8d>
mov    %rax,%rdi
call   1040 <atoi@plt>
mov    %eax,0x0(%r13)
lea    0xea4(%rip),%rsi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1030 <strtok_r@plt>
test   %rax,%rax
je     11a5 <parse_collist+0x85>
mov    $0x1,%ebx
lea    0xe87(%rip),%r15
lea    0x8(%rsp),%r12
xchg   %ax,%ax
mov    %rax,%rdi
call   1040 <atoi@plt>
mov    %eax,0x0(%r13,%rbx,4)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <strtok_r@plt>
test   %rax,%rax
jne    1180 <parse_collist+0x60>
jmp    11aa <parse_collist+0x8a>
mov    $0x1,%ebx
mov    %ebx,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c" ,\00"
define void @parse_collist(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i8* @strtok_r(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %4)
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %25, label %9
9: ; preds = %3
%10 = call i32 @atoi(i8* %6)
store i32 %10, i32* %1
%11 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %4)
%12 = icmp eq i8* %11, null
br i1 %12, label %23, label %13
13: ; preds = %9, %13
%14 = phi i64 [ %18, %13 ], [ 1, %9 ]
%15 = phi i8* [ %19, %13 ], [ %11, %9 ]
%16 = call i32 @atoi(i8* %15)
%17 = getelementptr inbounds i32, i32* %1, i64 %14
store i32 %16, i32* %17
%18 = add nuw i64 %14, 1
%19 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %4)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %13
21: ; preds = %13
%22 = trunc i64 %18 to i32
br label %23
23: ; preds = %21, %9
%24 = phi i32 [ 1, %9 ], [ %22, %21 ]
store i32 %24, i32* %2
br label %25
25: ; preds = %3, %23
ret void
}