#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*/ printf(char *, ...);
int CountWords(char *sentence_array, int count, int start, int maxSize) {
  if (count < 0) {
    printf("ERROR: count needs to be greater than 0.\n");
    return 1;
  }
  if (sentence_array == NULL) {
    printf("ERROR: array entered was null.\n");
    return 1;
  }
  if (start > maxSize) {
    printf("ERROR: the start point was greater than the max size.\n");
    return 1;
  }
  if (start < 0 || maxSize < 0) {
    printf("ERROR: the start point or the max size were set less than zero.\n");
    return 1;
  }
  if (sentence_array[0] == ' ') {
    printf("ERROR: the first character in the array was empty. Please start "
           "your sentence from the beginning.\n");
    return 1;
  }
  int a = 0;
  while (sentence_array[a] != '\0') {
    a++;
  }
  maxSize = a;
  if (sentence_array[start] == ' ' && sentence_array[start - 1] != ' ' &&
      start != (maxSize - 1)) {
    count = count + 1;
  }
  if (start != maxSize) {
    count = CountWords(sentence_array, count, (start + 1), maxSize);
  }
  if (start == maxSize) {
    count++;
    printf("number of words: %d\n", count);
    return count;
  }
  return count;
}


x86 assembly (clang, -O0):
<CountWords>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1159 <CountWords+0x39>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d0 <CountWords+0x1b0>
cmpq   $0x0,-0x10(%rbp)
jne    117e <CountWords+0x5e>
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d0 <CountWords+0x1b0>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    11a4 <CountWords+0x84>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d0 <CountWords+0x1b0>
cmpl   $0x0,-0x18(%rbp)
jl     11b8 <CountWords+0x98>
cmpl   $0x0,-0x1c(%rbp)
jge    11d2 <CountWords+0xb2>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d0 <CountWords+0x1b0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    11fc <CountWords+0xdc>
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d0 <CountWords+0x1b0>
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1226 <CountWords+0x106>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1203 <CountWords+0xe3>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    1275 <CountWords+0x155>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     1275 <CountWords+0x155>
mov    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1275 <CountWords+0x155>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     1299 <CountWords+0x179>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
mov    -0x1c(%rbp),%ecx
call   1030 <CountWords@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    12ca <CountWords+0x1aa>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12d0 <CountWords+0x1b0>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CountWords>:
push   %rbp
push   %rbx
push   %rax
test   %esi,%esi
js     11aa <CountWords+0x8a>
test   %rdi,%rdi
je     11b3 <CountWords+0x93>
mov    %esi,%ebp
movslq %edx,%rax
nopl   0x0(%rax)
movslq %ecx,%rdx
cmp    %rdx,%rax
jg     11bc <CountWords+0x9c>
or     %eax,%ecx
js     11c5 <CountWords+0xa5>
mov    (%rdi),%cl
test   %cl,%cl
je     11a0 <CountWords+0x80>
cmp    $0x20,%cl
je     11e3 <CountWords+0xc3>
xor    %edx,%edx
nopl   (%rax)
lea    0x1(%rdx),%rcx
cmpb   $0x0,0x1(%rdi,%rdx,1)
mov    %rcx,%rdx
jne    1160 <CountWords+0x40>
cmpb   $0x20,(%rdi,%rax,1)
jne    118b <CountWords+0x6b>
cmpb   $0x20,-0x1(%rax,%rdi,1)
setne  %dl
lea    -0x1(%rcx),%esi
cmp    %eax,%esi
setne  %bl
and    %dl,%bl
movzbl %bl,%edx
add    %edx,%ebp
cmp    %eax,%ecx
je     11ce <CountWords+0xae>
add    $0x1,%rax
test   %ebp,%ebp
jns    1140 <CountWords+0x20>
jmp    11aa <CountWords+0x8a>
nopl   0x0(%rax)
xor    %ecx,%ecx
cmpb   $0x20,(%rdi,%rax,1)
je     1174 <CountWords+0x54>
jmp    118b <CountWords+0x6b>
lea    0xf5b(%rip),%rdi
jmp    11ea <CountWords+0xca>
lea    0xf33(%rip),%rdi
jmp    11ea <CountWords+0xca>
lea    0xef4(%rip),%rdi
jmp    11ea <CountWords+0xca>
lea    0xeab(%rip),%rdi
jmp    11ea <CountWords+0xca>
add    $0x1,%ebp
lea    0xe28(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f4 <CountWords+0xd4>
lea    0xe2b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"ERROR: count needs to be greater than 0.\0A\00"
@.str.1 = [32 x i8] c"ERROR: array entered was null.\0A\00"
@.str.2 = [55 x i8] c"ERROR: the start point was greater than the max size.\0A\00"
@.str.3 = [65 x i8] c"ERROR: the start point or the max size were set less than zero.\0A\00"
@.str.4 = [99 x i8] c"ERROR: the first character in the array was empty. Please start your sentence from the beginning.\0A\00"
@.str.5 = [21 x i8] c"number of words: %d\0A\00"
define i32 @CountWords(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
br label %103
15: ; preds = %4
%16 = load i8*, i8** %6
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %5
br label %103
20: ; preds = %15
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = icmp sgt i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %5
br label %103
26: ; preds = %20
%27 = load i32, i32* %8
%28 = icmp slt i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* %9
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29, %26
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %5
br label %103
34: ; preds = %29
%35 = load i8*, i8** %6
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 32
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %5
br label %103
42: ; preds = %34
store i32 0, i32* %10
br label %43
43: ; preds = %51, %42
%44 = load i8*, i8** %6
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %43
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
br label %43
54: ; preds = %43
%55 = load i32, i32* %10
store i32 %55, i32* %9
%56 = load i8*, i8** %6
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 32
br i1 %62, label %63, label %80
63: ; preds = %54
%64 = load i8*, i8** %6
%65 = load i32, i32* %8
%66 = sub nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %64, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp ne i32 %70, 32
br i1 %71, label %72, label %80
72: ; preds = %63
%73 = load i32, i32* %8
%74 = load i32, i32* %9
%75 = sub nsw i32 %74, 1
%76 = icmp ne i32 %73, %75
br i1 %76, label %77, label %80
77: ; preds = %72
%78 = load i32, i32* %7
%79 = add nsw i32 %78, 1
store i32 %79, i32* %7
br label %80
80: ; preds = %77, %72, %63, %54
%81 = load i32, i32* %8
%82 = load i32, i32* %9
%83 = icmp ne i32 %81, %82
br i1 %83, label %84, label %91
84: ; preds = %80
%85 = load i8*, i8** %6
%86 = load i32, i32* %7
%87 = load i32, i32* %8
%88 = add nsw i32 %87, 1
%89 = load i32, i32* %9
%90 = call i32 @CountWords(i8* %85, i32 %86, i32 %88, i32 %89)
store i32 %90, i32* %7
br label %91
91: ; preds = %84, %80
%92 = load i32, i32* %8
%93 = load i32, i32* %9
%94 = icmp eq i32 %92, %93
br i1 %94, label %95, label %101
95: ; preds = %91
%96 = load i32, i32* %7
%97 = add nsw i32 %96, 1
store i32 %97, i32* %7
%98 = load i32, i32* %7
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %98)
%100 = load i32, i32* %7
store i32 %100, i32* %5
br label %103
101: ; preds = %91
%102 = load i32, i32* %7
store i32 %102, i32* %5
br label %103
103: ; preds = %101, %95, %40, %32, %24, %18, %13
%104 = load i32, i32* %5
ret i32 %104
}

LLVM IR (-O2):
@.str.5 = [21 x i8] c"number of words: %d\0A\00"
@str = [98 x i8] c"ERROR: the first character in the array was empty. Please start your sentence from the beginning.\00"
@str.6 = [64 x i8] c"ERROR: the start point or the max size were set less than zero.\00"
@str.7 = [54 x i8] c"ERROR: the start point was greater than the max size.\00"
@str.8 = [31 x i8] c"ERROR: array entered was null.\00"
@str.9 = [41 x i8] c"ERROR: count needs to be greater than 0.\00"
define i32 @CountWords(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp slt i32 %1, 0
br i1 %5, label %13, label %6
6: ; preds = %4
%7 = icmp eq i8* %0, null
br i1 %7, label %21, label %8
8: ; preds = %6
%9 = sext i32 %2 to i64
br label %15
10: ; preds = %57
%11 = add i64 %16, 1
%12 = icmp slt i32 %58, 0
br i1 %12, label %13, label %15
13: ; preds = %10, %4
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.9, i64 0, i64 0))
br label %63
15: ; preds = %8, %10
%16 = phi i64 [ %9, %8 ], [ %11, %10 ]
%17 = phi i32 [ %3, %8 ], [ %43, %10 ]
%18 = phi i32 [ %1, %8 ], [ %58, %10 ]
%19 = sext i32 %17 to i64
%20 = icmp sgt i64 %16, %19
br i1 %20, label %23, label %25
21: ; preds = %6
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.8, i64 0, i64 0))
br label %63
23: ; preds = %15
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.7, i64 0, i64 0))
br label %63
25: ; preds = %15
%26 = trunc i64 %16 to i32
%27 = or i32 %17, %26
%28 = icmp sgt i32 %27, -1
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.6, i64 0, i64 0))
br label %63
31: ; preds = %25
%32 = load i8, i8* %0
switch i8 %32, label %35 [
i8 32, label %33
i8 0, label %41
]
33: ; preds = %31
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([98 x i8], [98 x i8]* @str, i64 0, i64 0))
br label %63
35: ; preds = %31, %35
%36 = phi i64 [ %40, %35 ], [ 1, %31 ]
%37 = getelementptr inbounds i8, i8* %0, i64 %36
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 0
%40 = add nuw i64 %36, 1
br i1 %39, label %41, label %35
41: ; preds = %35, %31
%42 = phi i64 [ 0, %31 ], [ %36, %35 ]
%43 = trunc i64 %42 to i32
%44 = getelementptr inbounds i8, i8* %0, i64 %16
%45 = load i8, i8* %44
%46 = icmp eq i8 %45, 32
br i1 %46, label %47, label %57
47: ; preds = %41
%48 = add nsw i64 %16, -1
%49 = getelementptr inbounds i8, i8* %0, i64 %48
%50 = load i8, i8* %49
%51 = icmp ne i8 %50, 32
%52 = add nsw i32 %43, -1
%53 = icmp ne i32 %52, %26
%54 = select i1 %51, i1 %53, i1 false
%55 = zext i1 %54 to i32
%56 = add nsw i32 %18, %55
br label %57
57: ; preds = %47, %41
%58 = phi i32 [ %18, %41 ], [ %56, %47 ]
%59 = icmp eq i32 %43, %26
br i1 %59, label %60, label %10
60: ; preds = %57
%61 = add nsw i32 %58, 1
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %60, %33, %29, %23, %21, %13
%64 = phi i32 [ 1, %13 ], [ 1, %21 ], [ 1, %23 ], [ 1, %29 ], [ 1, %33 ], [ %61, %60 ]
ret i32 %64
}