#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 *);
scalar_t__ strtok(char *, char const *);
void tokenizeInts(char *list, const char *sep, int *tokens) {
  int nbTokens = 0;
  char *elem;
  elem = (char *)strtok(list, sep);
  while (elem) {
    tokens[++nbTokens] = atoi(elem);
    elem = (char *)strtok(NULL, sep);
  }
  tokens[0] = nbTokens;
}


x86 assembly (clang, -O0):
<tokenizeInts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     118b <tokenizeInts+0x6b>
mov    -0x28(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1030 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    114c <tokenizeInts+0x2c>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenizeInts>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
call   1030 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1160 <tokenizeInts+0x40>
nopw   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1040 <atoi@plt>
mov    %eax,0x4(%r14,%rbx,4)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r15,%rsi
call   1030 <strtok@plt>
test   %rax,%rax
jne    1140 <tokenizeInts+0x20>
mov    %ebx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @tokenizeInts(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
store i32 0, i32* %7
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i64 @strtok(i8* %9, i8* %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %8
br label %13
13: ; preds = %16, %3
%14 = load i8*, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = load i8*, i8** %8
%18 = call i32 @atoi(i8* %17)
%19 = load i32*, i32** %6
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
store i32 %21, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %19, i64 %22
store i32 %18, i32* %23
%24 = load i8*, i8** %5
%25 = call i64 @strtok(i8* null, i8* %24)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %8
br label %13
27: ; preds = %13
%28 = load i32, i32* %7
%29 = load i32*, i32** %6
%30 = getelementptr inbounds i32, i32* %29, i64 0
store i32 %28, i32* %30
ret void
}

LLVM IR (-O2):
define void @tokenizeInts(i8* %0, i8* nocapture %1, i32* nocapture writeonly %2) {
%4 = tail call i64 @strtok(i8* %0, i8* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %3, %6
%7 = phi i64 [ %11, %6 ], [ 0, %3 ]
%8 = phi i64 [ %13, %6 ], [ %4, %3 ]
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @atoi(i8* %9)
%11 = add nuw nsw i64 %7, 1
%12 = getelementptr inbounds i32, i32* %2, i64 %11
store i32 %10, i32* %12
%13 = tail call i64 @strtok(i8* null, i8* %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = trunc i64 %11 to i32
br label %17
17: ; preds = %15, %3
%18 = phi i32 [ 0, %3 ], [ %16, %15 ]
store i32 %18, i32* %2
ret void
}