#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*/ strcpy(char *, char const *);
char *strtok(char *, char const *);
int count_tokens(const char *text, const char *tokens) {
  char _text[64];
  strcpy(_text, text);
  int count = 0;
  char *pch = strtok(_text, tokens);
  while (pch != NULL) {
    pch = strtok(NULL, tokens);
    count++;
  }
  return count;
}


x86 assembly (clang, -O0):
<count_tokens>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     117f <count_tokens+0x5f>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x60(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1155 <count_tokens+0x35>
mov    -0x54(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_tokens>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1162 <count_tokens+0x42>
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    1150 <count_tokens+0x30>
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @count_tokens(i8* %0, i8* nocapture %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* %0)
%6 = call i8* @strtok(i8* %4, i8* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %13, label %8
8: ; preds = %2, %8
%9 = phi i32 [ %11, %8 ], [ 0, %2 ]
%10 = call i8* @strtok(i8* null, i8* %1)
%11 = add nuw nsw i32 %9, 1
%12 = icmp eq i8* %10, null
br i1 %12, label %13, label %8
13: ; preds = %8, %2
%14 = phi i32 [ 0, %2 ], [ %11, %8 ]
ret i32 %14
}