#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 token_count(const char *expression, const char *delim) {
  int count;
  char copy[81];
  char *token;
  strcpy(copy, expression);
  token = strtok(copy, delim);
  for (count = 0; NULL != token; count++) {
    token = strtok(NULL, delim);
  }
  return count;
}


x86 assembly (clang, -O0):
<token_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x78(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x78(%rbp),%rax
je     1183 <token_count+0x63>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x78(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1158 <token_count+0x38>
mov    -0x14(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<token_count>:
push   %r14
push   %rbx
sub    $0x58,%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 <token_count+0x42>
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <strtok@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    1150 <token_count+0x30>
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @token_count(i8* %0, i8* nocapture %1) {
%3 = alloca [81 x i8]
%4 = getelementptr inbounds [81 x i8], [81 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
}