#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*/ free(char *);
char *strdup(char *);
char *strtok(char *, char *);
int num_words_with_delimiter(char *input, char *delimiters) {
  char *input_copy = strdup(input);
  int count = 0;
  char *word = strtok(input_copy, delimiters);
  while (word != NULL) {
    word = strtok(NULL, delimiters);
    count++;
  }
  free(input_copy);
  return count;
}


x86 assembly (clang, -O0):
<num_words_with_delimiter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     118f <num_words_with_delimiter+0x5f>
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1165 <num_words_with_delimiter+0x35>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_words_with_delimiter>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
call   1050 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1172 <num_words_with_delimiter+0x42>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
add    $0x1,%ebx
test   %rax,%rax
jne    1160 <num_words_with_delimiter+0x30>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @num_words_with_delimiter(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i8* @strdup(i8* %0)
%4 = tail call i8* @strtok(i8* %3, i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %11, label %6
6: ; preds = %2, %6
%7 = phi i32 [ %9, %6 ], [ 0, %2 ]
%8 = tail call i8* @strtok(i8* null, i8* %1)
%9 = add nuw nsw i32 %7, 1
%10 = icmp eq i8* %8, null
br i1 %10, label %11, label %6
11: ; preds = %6, %2
%12 = phi i32 [ 0, %2 ], [ %9, %6 ]
%13 = tail call i32 @free(i8* %3)
ret i32 %12
}