#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*/ find_variable(char *, int *);
char *strtok_r(char *, char *, char **);
void parse_varlist(char *varlist, int *ivars, int *n) {
  char *item;
  char *toksave;
  int v, i = 0;
  item = strtok_r(varlist, " ,", &toksave);
  if (item[0] == 0)
    return;
  find_variable(item, &v);
  if (v <= 0)
    return;
  ivars[i] = v - 1;
  i++;
  while ((item = strtok_r(NULL, " ,", &toksave)) != NULL) {
    find_variable(item, &v);
    if (v <= 0)
      return;
    ivars[i] = v - 1;
    i++;
  }
  *n = i;
}


x86 assembly (clang, -O0):
<parse_varlist>:
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   1040 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1168 <parse_varlist+0x48>
jmp    1204 <parse_varlist+0xe4>
mov    -0x20(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1030 <find_variable@plt>
cmpl   $0x0,-0x2c(%rbp)
jg     1184 <parse_varlist+0x64>
jmp    1204 <parse_varlist+0xe4>
mov    -0x2c(%rbp),%edx
sub    $0x1,%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    0xe57(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11fb <parse_varlist+0xdb>
mov    -0x20(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1030 <find_variable@plt>
cmpl   $0x0,-0x2c(%rbp)
jg     11dc <parse_varlist+0xbc>
jmp    1204 <parse_varlist+0xe4>
mov    -0x2c(%rbp),%edx
sub    $0x1,%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    119e <parse_varlist+0x7e>
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_varlist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0xec5(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1040 <strtok_r@plt>
cmpb   $0x0,(%rax)
je     11d9 <parse_varlist+0xb9>
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
call   1030 <find_variable@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11d9 <parse_varlist+0xb9>
add    $0xffffffff,%eax
mov    %eax,(%rbx)
lea    0xe91(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %edi,%edi
call   1040 <strtok_r@plt>
test   %rax,%rax
je     11d1 <parse_varlist+0xb1>
mov    $0x1,%ebp
lea    0xc(%rsp),%r15
lea    0xe6f(%rip),%r12
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <find_variable@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11d9 <parse_varlist+0xb9>
add    $0xffffffff,%eax
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
xor    %edi,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1040 <strtok_r@plt>
test   %rax,%rax
jne    11a0 <parse_varlist+0x80>
jmp    11d6 <parse_varlist+0xb6>
mov    $0x1,%ebp
mov    %ebp,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c" ,\00"
define void @parse_varlist(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 %55
19: ; preds = %3
%20 = load i8*, i8** %7
%21 = call i32 @find_variable(i8* %20, i32* %9)
%22 = load i32, i32* %9
%23 = icmp sle i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
br label %55
25: ; preds = %19
%26 = load i32, i32* %9
%27 = sub nsw i32 %26, 1
%28 = load i32*, i32** %5
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
store i32 %27, i32* %31
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %10
br label %34
34: ; preds = %43, %25
%35 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %8)
store i8* %35, i8** %7
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %52
37: ; preds = %34
%38 = load i8*, i8** %7
%39 = call i32 @find_variable(i8* %38, i32* %9)
%40 = load i32, i32* %9
%41 = icmp sle i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %37
br label %55
43: ; preds = %37
%44 = load i32, i32* %9
%45 = sub nsw i32 %44, 1
%46 = load i32*, i32** %5
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
store i32 %45, i32* %49
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
store i32 %51, i32* %10
br label %34
52: ; preds = %34
%53 = load i32, i32* %10
%54 = load i32*, i32** %6
store i32 %53, i32* %54
br label %55
55: ; preds = %52, %42, %24, %18
ret void
}

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