#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 atof(char *);
scalar_t__ realloc(int *, int);
char *strtok_r(char *, char const *, char **);
unsigned int str2intlist(char **string, const char *sep, int **list) {
  int i = 0;
  char *str = (char *)NULL;
  char *orig_string = *string;
  ;
  while (1) {
    str = *string;
    str = strtok_r(str, sep, string);
    ;
    if (str == NULL)
      break;
    else {
      *list = (int *)realloc(*list, (i + 1) * sizeof(int));
      (*list)[i] = atof(str);
    };
    i++;
  };
  *string = orig_string;
  return i;
}


x86 assembly (clang, -O0):
<str2intlist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118e <str2intlist+0x5e>
jmp    11d9 <str2intlist+0xa9>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <atof@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115e <str2intlist+0x2e>
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2intlist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%rbx
mov    (%rdi),%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1040 <strtok_r@plt>
test   %rax,%rax
je     11d2 <str2intlist+0xa2>
mov    %rax,%r14
mov    %rbp,0x8(%rsp)
mov    $0x4,%ebp
mov    %r15,0x10(%rsp)
xor    %eax,%eax
mov    %rbx,0x18(%rsp)
mov    0x10(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %rax,%rbx
mov    (%r15),%rdi
add    $0x1,%rax
mov    %rax,0x20(%rsp)
mov    %ebp,%esi
call   1050 <realloc@plt>
mov    %rax,%r12
mov    %rax,(%r15)
mov    %r14,%rdi
call   1030 <atof@plt>
mov    %eax,(%r12,%rbx,4)
mov    0x18(%rsp),%rbx
mov    (%rbx),%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1040 <strtok_r@plt>
mov    %rax,%r14
mov    0x20(%rsp),%rax
add    $0x4,%ebp
test   %r14,%r14
jne    1180 <str2intlist+0x50>
mov    0x8(%rsp),%rbp
jmp    11d4 <str2intlist+0xa4>
xor    %eax,%eax
mov    %rbp,(%rbx)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @str2intlist(i8** %0, i8* nocapture %1, i32** nocapture %2) {
%4 = load i8*, i8** %0
%5 = tail call i8* @strtok_r(i8* %4, i8* %1, i8** %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %23, label %7
7: ; preds = %3, %7
%8 = phi i64 [ %11, %7 ], [ 0, %3 ]
%9 = phi i8* [ %19, %7 ], [ %5, %3 ]
%10 = load i32*, i32** %2
%11 = add nuw i64 %8, 1
%12 = trunc i64 %11 to i32
%13 = shl i32 %12, 2
%14 = tail call i64 @realloc(i32* %10, i32 %13)
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %2
%16 = tail call i32 @atof(i8* %9)
%17 = getelementptr inbounds i32, i32* %15, i64 %8
store i32 %16, i32* %17
%18 = load i8*, i8** %0
%19 = tail call i8* @strtok_r(i8* %18, i8* %1, i8** %0)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %7
21: ; preds = %7
%22 = trunc i64 %11 to i32
br label %23
23: ; preds = %21, %3
%24 = phi i32 [ 0, %3 ], [ %22, %21 ]
store i8* %4, i8** %0
ret i32 %24
}