#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 *);
scalar_t__ 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 *wp[200] = {0};
  unsigned int freeCount = 0;
  if (p_str == NULL)
    return 0;
  token = strtok_s(p_str, " \n\r", &nextContext);
  while (token != NULL) {
    if (dup_word(wp, token) == 0) {
      wp[cnt] = _strdup(token);
      cnt++;
    }
    token = strtok_s(NULL, " \n\r", &nextContext);
  }
  for (freeCount = 0; freeCount < 200; freeCount++) {
    if (wp[freeCount] != NULL) {
      free(wp[freeCount]);
      wp[freeCount]++;
    }
  }
  return cnt;
}


x86 assembly (clang, -O0):
<get_word_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x680,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x670(%rbp),%rdi
xor    %esi,%esi
mov    $0x640,%edx
call   1040 <memset@plt>
movl   $0x0,-0x674(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11aa <get_word_count+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    12a0 <get_word_count+0x150>
mov    -0x10(%rbp),%rdi
lea    0xe4b(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <strtok_s@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1225 <get_word_count+0xd5>
lea    -0x670(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <dup_word@plt>
cmp    $0x0,%rax
jne    1208 <get_word_count+0xb8>
mov    -0x20(%rbp),%rdi
call   1070 <_strdup@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
mov    %rcx,-0x670(%rbp,%rax,8)
ff
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xded(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1050 <strtok_s@plt>
mov    %rax,-0x20(%rbp)
jmp    11c2 <get_word_count+0x72>
movl   $0x0,-0x674(%rbp)
cmpl   $0xc8,-0x674(%rbp)
jae    129a <get_word_count+0x14a>
mov    -0x674(%rbp),%eax
cmpq   $0x0,-0x670(%rbp,%rax,8)
je     1281 <get_word_count+0x131>
mov    -0x674(%rbp),%eax
mov    -0x670(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x674(%rbp),%eax
mov    -0x670(%rbp,%rax,8),%rcx
ff
add    $0x1,%rcx
mov    %rcx,-0x670(%rbp,%rax,8)
ff
jmp    1286 <get_word_count+0x136>
mov    -0x674(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x674(%rbp)
jmp    122f <get_word_count+0xdf>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x680,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_word_count>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x650,%rsp
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rdi
xor    %r13d,%r13d
mov    $0x640,%edx
xor    %esi,%esi
call   1040 <memset@plt>
test   %rbx,%rbx
je     1234 <get_word_count+0xe4>
lea    0xe70(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <strtok_s@plt>
test   %rax,%rax
je     11fb <get_word_count+0xab>
mov    %rax,%rbx
xor    %r13d,%r13d
lea    0x10(%rsp),%r14
lea    0xe4c(%rip),%r15
lea    0x8(%rsp),%r12
jmp    11d5 <get_word_count+0x85>
nopl   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     11fe <get_word_count+0xae>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <dup_word@plt>
test   %rax,%rax
jne    11c0 <get_word_count+0x70>
mov    %rbx,%rdi
call   1070 <_strdup@plt>
movslq %r13d,%r13
mov    %rax,0x10(%rsp,%r13,8)
add    $0x1,%r13d
jmp    11c0 <get_word_count+0x70>
xor    %r13d,%r13d
xor    %ebx,%ebx
jmp    121d <get_word_count+0xcd>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    $0xc8,%rbx
je     1234 <get_word_count+0xe4>
mov    0x10(%rsp,%rbx,8),%rdi
test   %rdi,%rdi
je     1210 <get_word_count+0xc0>
call   1030 <free@plt>
addq   $0x1,0x10(%rsp,%rbx,8)
jmp    1210 <get_word_count+0xc0>
mov    %r13d,%eax
add    $0x650,%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 i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [200 x i8*]
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
store i8* null, i8** %5
store i8* null, i8** %6
%9 = bitcast [200 x i8*]* %7 to i8*
store i32 0, i32* %8
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 0, i32* %2
br label %61
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i8* @strtok_s(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %6)
store i8* %15, i8** %5
br label %16
16: ; preds = %32, %13
%17 = load i8*, i8** %5
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %34
19: ; preds = %16
%20 = getelementptr inbounds [200 x i8*], [200 x i8*]* %7, i64 0, i64 0
%21 = load i8*, i8** %5
%22 = call i64 @dup_word(i8** %20, i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %19
%25 = load i8*, i8** %5
%26 = call i8* @_strdup(i8* %25)
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [200 x i8*], [200 x i8*]* %7, i64 0, i64 %28
store i8* %26, i8** %29
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %32
32: ; preds = %24, %19
%33 = call i8* @strtok_s(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %6)
store i8* %33, i8** %5
br label %16
34: ; preds = %16
store i32 0, i32* %8
br label %35
35: ; preds = %56, %34
%36 = load i32, i32* %8
%37 = icmp ult i32 %36, 200
br i1 %37, label %38, label %59
38: ; preds = %35
%39 = load i32, i32* %8
%40 = zext i32 %39 to i64
%41 = getelementptr inbounds [200 x i8*], [200 x i8*]* %7, i64 0, i64 %40
%42 = load i8*, i8** %41
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %55
44: ; preds = %38
%45 = load i32, i32* %8
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds [200 x i8*], [200 x i8*]* %7, i64 0, i64 %46
%48 = load i8*, i8** %47
%49 = call i32 @free(i8* %48)
%50 = load i32, i32* %8
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds [200 x i8*], [200 x i8*]* %7, i64 0, i64 %51
%53 = load i8*, i8** %52
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %52
br label %55
55: ; preds = %44, %38
br label %56
56: ; preds = %55
%57 = load i32, i32* %8
%58 = add i32 %57, 1
store i32 %58, i32* %8
br label %35
59: ; preds = %35
%60 = load i32, i32* %4
store i32 %60, i32* %2
br label %61
61: ; preds = %59, %12
%62 = load i32, i32* %2
ret i32 %62
}

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