#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 */
char *_strdup(char *);
int dup_word(char **, char *);
int /*<<< orphan*/ free(char *);
char *strtok_s(char *, char *, char **);
int get_word_count(char *p_str) {
  int cnt = 0;
  char *token = NULL, *nextContext = NULL;
  char *wordList[50] = {0}, i = 0;
  token = strtok_s(p_str, " \n\r", &nextContext);
  while (token != NULL) {
    if (dup_word(wordList, token) == 1) {
    } else {
      wordList[cnt++] = _strdup(token);
    }
    token = strtok_s(NULL, " \n\r", &nextContext);
  }
  for (i = 0; i < cnt; i++) {
    if (wordList[i] != NULL) {
      free(wordList[i]);
      wordList[i] = NULL;
    }
  }
  return cnt;
}


x86 assembly (clang, -O0):
<get_word_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x1b0(%rbp),%rdi
xor    %esi,%esi
mov    $0x190,%edx
call   1040 <memset@plt>
movb   $0x0,-0x1b1(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe65(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <strtok_s@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     120f <get_word_count+0xbf>
lea    -0x1b0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <dup_word@plt>
cmp    $0x1,%eax
jne    11d1 <get_word_count+0x81>
jmp    11f2 <get_word_count+0xa2>
mov    -0x18(%rbp),%rdi
call   1070 <_strdup@plt>
mov    %rax,%rcx
mov    -0xc(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
cltq
mov    %rcx,-0x1b0(%rbp,%rax,8)
ff
xor    %eax,%eax
mov    %eax,%edi
lea    0xe03(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <strtok_s@plt>
mov    %rax,-0x18(%rbp)
jmp    11a8 <get_word_count+0x58>
movb   $0x0,-0x1b1(%rbp)
movsbl -0x1b1(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    127e <get_word_count+0x12e>
movsbq -0x1b1(%rbp),%rax
ff
cmpq   $0x0,-0x1b0(%rbp,%rax,8)
je     1266 <get_word_count+0x116>
movsbq -0x1b1(%rbp),%rax
ff
mov    -0x1b0(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
movsbq -0x1b1(%rbp),%rax
ff
movq   $0x0,-0x1b0(%rbp,%rax,8)
jmp    126b <get_word_count+0x11b>
mov    -0x1b1(%rbp),%al
add    $0x1,%al
mov    %al,-0x1b1(%rbp)
jmp    1216 <get_word_count+0xc6>
mov    -0xc(%rbp),%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_word_count>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a0,%rsp
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rdi
xor    %r13d,%r13d
mov    $0x190,%edx
xor    %esi,%esi
call   1040 <memset@plt>
lea    0xe79(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <strtok_s@plt>
test   %rax,%rax
je     1239 <get_word_count+0xe9>
mov    %rax,%rbx
xor    %r13d,%r13d
lea    0x10(%rsp),%r14
lea    0xe51(%rip),%r15
lea    0x8(%rsp),%r12
jmp    11d5 <get_word_count+0x85>
cs nopw 0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <strtok_s@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11fb <get_word_count+0xab>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <dup_word@plt>
cmp    $0x1,%eax
je     11c0 <get_word_count+0x70>
mov    %rbx,%rdi
call   1070 <_strdup@plt>
movslq %r13d,%rcx
add    $0x1,%r13d
mov    %rax,0x10(%rsp,%rcx,8)
jmp    11c0 <get_word_count+0x70>
test   %r13d,%r13d
jle    1239 <get_word_count+0xe9>
xor    %ebx,%ebx
jmp    121b <get_word_count+0xcb>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%bl
movsbl %bl,%eax
cmp    %eax,%r13d
jle    1239 <get_word_count+0xe9>
movsbq %bl,%r14
mov    0x10(%rsp,%r14,8),%rdi
test   %rdi,%rdi
je     1210 <get_word_count+0xc0>
call   1030 <free@plt>
movq   $0x0,0x10(%rsp,%r14,8)
jmp    1210 <get_word_count+0xc0>
mov    %r13d,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c" \0A\0D\00"
define i32 @get_word_count(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [50 x i8*]
%7 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
store i8* null, i8** %4
store i8* null, i8** %5
%8 = bitcast [50 x i8*]* %6 to i8*
store i8 0, i8* %7
%9 = load i8*, i8** %2
%10 = call i8* @strtok_s(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %5)
store i8* %10, i8** %4
br label %11
11: ; preds = %27, %1
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = getelementptr inbounds [50 x i8*], [50 x i8*]* %6, i64 0, i64 0
%16 = load i8*, i8** %4
%17 = call i32 @dup_word(i8** %15, i8* %16)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %14
br label %27
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = call i8* @_strdup(i8* %21)
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds [50 x i8*], [50 x i8*]* %6, i64 0, i64 %25
store i8* %22, i8** %26
br label %27
27: ; preds = %20, %19
%28 = call i8* @strtok_s(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %5)
store i8* %28, i8** %4
br label %11
29: ; preds = %11
store i8 0, i8* %7
br label %30
30: ; preds = %51, %29
%31 = load i8, i8* %7
%32 = sext i8 %31 to i32
%33 = load i32, i32* %3
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %54
35: ; preds = %30
%36 = load i8, i8* %7
%37 = sext i8 %36 to i64
%38 = getelementptr inbounds [50 x i8*], [50 x i8*]* %6, i64 0, i64 %37
%39 = load i8*, i8** %38
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %50
41: ; preds = %35
%42 = load i8, i8* %7
%43 = sext i8 %42 to i64
%44 = getelementptr inbounds [50 x i8*], [50 x i8*]* %6, i64 0, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 @free(i8* %45)
%47 = load i8, i8* %7
%48 = sext i8 %47 to i64
%49 = getelementptr inbounds [50 x i8*], [50 x i8*]* %6, i64 0, i64 %48
store i8* null, i8** %49
br label %50
50: ; preds = %41, %35
br label %51
51: ; preds = %50
%52 = load i8, i8* %7
%53 = add i8 %52, 1
store i8 %53, i8* %7
br label %30
54: ; preds = %30
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [4 x i8] c" \0A\0D\00"
define i32 @get_word_count(i8* %0) {
%2 = alloca i8*
%3 = alloca [50 x i8*]
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast [50 x i8*]* %3 to i8*
%6 = call i8* @strtok_s(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %38, label %8
8: ; preds = %1
%9 = getelementptr inbounds [50 x i8*], [50 x i8*]* %3, i64 0, i64 0
br label %12
10: ; preds = %22
%11 = icmp sgt i32 %23, 0
br i1 %11, label %26, label %38
12: ; preds = %8, %22
%13 = phi i8* [ %6, %8 ], [ %24, %22 ]
%14 = phi i32 [ 0, %8 ], [ %23, %22 ]
%15 = call i32 @dup_word(i8** %9, i8* %13)
%16 = icmp eq i32 %15, 1
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = call i8* @_strdup(i8* %13)
%19 = add nsw i32 %14, 1
%20 = sext i32 %14 to i64
%21 = getelementptr inbounds [50 x i8*], [50 x i8*]* %3, i64 0, i64 %20
store i8* %18, i8** %21
br label %22
22: ; preds = %12, %17
%23 = phi i32 [ %14, %12 ], [ %19, %17 ]
%24 = call i8* @strtok_s(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %2)
%25 = icmp eq i8* %24, null
br i1 %25, label %10, label %12
26: ; preds = %10, %34
%27 = phi i8 [ %35, %34 ], [ 0, %10 ]
%28 = sext i8 %27 to i64
%29 = getelementptr inbounds [50 x i8*], [50 x i8*]* %3, i64 0, i64 %28
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %34, label %32
32: ; preds = %26
%33 = call i32 @free(i8* %30)
store i8* null, i8** %29
br label %34
34: ; preds = %26, %32
%35 = add i8 %27, 1
%36 = sext i8 %35 to i32
%37 = icmp sgt i32 %23, %36
br i1 %37, label %26, label %38
38: ; preds = %34, %1, %10
%39 = phi i32 [ %23, %10 ], [ 0, %1 ], [ %23, %34 ]
ret i32 %39
}