#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 */
scalar_t__ strtok(char *, char *);
int tokenizeFnames(char *list, char **fnames) {
  int nbFiles = 0;
  char *fname = (char *)strtok(list, ",");
  while (fname != NULL) {
    fnames[nbFiles++] = fname;
    fname = (char *)strtok(NULL, ",");
  }
  return nbFiles;
}


x86 assembly (clang, -O0):
<tokenizeFnames>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xece(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1179 <tokenizeFnames+0x69>
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe95(%rip),%rsi
call   1030 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    113b <tokenizeFnames+0x2b>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenizeFnames>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xee1(%rip),%rsi
call   1030 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1157 <tokenizeFnames+0x47>
lea    0xece(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r15,%rsi
call   1030 <strtok@plt>
test   %rax,%rax
jne    1140 <tokenizeFnames+0x30>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
define i32 @tokenizeFnames(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = call i64 @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %6
br label %10
10: ; preds = %13, %2
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %22
13: ; preds = %10
%14 = load i8*, i8** %6
%15 = load i8**, i8*** %4
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
store i32 %17, i32* %5
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds i8*, i8** %15, i64 %18
store i8* %14, i8** %19
%20 = call i64 @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %6
br label %10
22: ; preds = %10
%23 = load i32, i32* %5
ret i32 %23
}

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