#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*/ assert(int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ splitStringIntoArray(char *, char **, char const *);
char *strcpy(char *, char *);
int strlen(char *);
int wordCount(char *, char const *);
int main() {
  char originalstr[] = "USA,Canada,Mexico,Bermuda,Grenada,Belize";
  char *string9 = malloc((strlen(originalstr) + 1) * sizeof(char));
  string9 = strcpy(string9, originalstr);
  const char *delimiter = ",";
  int ct = wordCount(string9, delimiter);
  assert(ct > 0);
  char *resultarr[ct];
  string9 = strcpy(string9, originalstr);
  splitStringIntoArray(string9, resultarr, delimiter);
  printf("\nAnswer #9 is\n");
  for (int i = 0; i < ct; i++) {
    printf("Token %d is %s\n", i, resultarr[i]);
  }
  free(string9);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movups 0xe83(%rip),%xmm0
movups %xmm0,-0x17(%rbp)
movaps 0xe6f(%rip),%xmm0
movaps %xmm0,-0x20(%rbp)
movaps 0xe54(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
lea    -0x30(%rbp),%rdi
mov    %rdi,-0x70(%rbp)
call   1060 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   10a0 <malloc@plt>
mov    -0x70(%rbp),%rsi
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strcpy@plt>
mov    %rax,-0x38(%rbp)
lea    0xe46(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1080 <wordCount@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
test   %eax,%eax
setg   %al
movzbl %al,%edi
call   1090 <assert@plt>
mov    -0x44(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x68(%rbp),%rsi
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rdx
call   1050 <splitStringIntoArray@plt>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    129c <main+0x11c>
mov    -0x68(%rbp),%rax
mov    -0x5c(%rbp),%esi
movslq -0x5c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1265 <main+0xe5>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movups 0xe71(%rip),%xmm0
movups %xmm0,-0x57(%rbp)
movaps 0xe5d(%rip),%xmm0
movaps %xmm0,-0x60(%rbp)
movaps 0xe42(%rip),%xmm0
movaps %xmm0,-0x70(%rbp)
lea    -0x70(%rbp),%r15
mov    %r15,%rdi
call   1070 <strlen@plt>
lea    0x1(%rax),%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdi
call   1090 <wordCount@plt>
mov    %eax,%r12d
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   10a0 <assert@plt>
mov    %rsp,-0x30(%rbp)
mov    %r12d,%r14d
lea    0xf(,%r14,8),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %rbx,-0x38(%rbp)
mov    %rbx,%rdi
mov    %r13,%rsi
lea    0xdee(%rip),%rdx
call   1050 <splitStringIntoArray@plt>
lea    0xdf4(%rip),%rdi
call   1060 <puts@plt>
test   %r12d,%r12d
jle    127a <main+0xea>
lea    0xdd3(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,8),%rdx
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1080 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1260 <main+0xd0>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.originalstr = [41 x i8] c"USA,Canada,Mexico,Bermuda,Grenada,Belize\00"
@.str = [2 x i8] c",\00"
@.str.1 = [15 x i8] c"\0AAnswer is\0A\00"
@.str.2 = [16 x i8] c"Token %d is %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [41 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [41 x i8]* %2 to i8*
%10 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%19 = call i8* @strcpy(i8* %17, i8* %18)
store i8* %19, i8** %3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4
%20 = load i8*, i8** %3
%21 = load i8*, i8** %4
%22 = call i32 @wordCount(i8* %20, i8* %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = icmp sgt i32 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i32, i32* %5
%28 = zext i32 %27 to i64
%29 = call i8* @llvm.stacksave()
store i8* %29, i8** %6
%30 = alloca i8*, i64 %28
store i64 %28, i64* %7
%31 = load i8*, i8** %3
%32 = getelementptr inbounds [41 x i8], [41 x i8]* %2, i64 0, i64 0
%33 = call i8* @strcpy(i8* %31, i8* %32)
store i8* %33, i8** %3
%34 = load i8*, i8** %3
%35 = load i8*, i8** %4
%36 = call i32 @splitStringIntoArray(i8* %34, i8** %30, i8* %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %8
br label %38
38: ; preds = %49, %0
%39 = load i32, i32* %8
%40 = load i32, i32* %5
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %52
42: ; preds = %38
%43 = load i32, i32* %8
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %30, i64 %45
%47 = load i8*, i8** %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %43, i8* %47)
br label %49
49: ; preds = %42
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %38
52: ; preds = %38
%53 = load i8*, i8** %3
%54 = call i32 @free(i8* %53)
store i32 0, i32* %1
%55 = load i8*, i8** %6
%56 = load i32, i32* %1
ret i32 %56
}

LLVM IR (-O2):
@__const.main.originalstr = [41 x i8] c"USA,Canada,Mexico,Bermuda,Grenada,Belize\00"
@.str = [2 x i8] c",\00"
@.str.2 = [16 x i8] c"Token %d is %s\0A\00"
@str = [14 x i8] c"\0AAnswer is\00"
define i32 @main() {
%1 = alloca [41 x i8]
%2 = getelementptr inbounds [41 x i8], [41 x i8]* %1, i64 0, i64 0
%3 = call i32 @strlen(i8* %2)
%4 = add nsw i32 %3, 1
%5 = call i8* @malloc(i32 %4)
%6 = call i8* @strcpy(i8* dereferenceable(1) %5, i8* %2)
%7 = call i32 @wordCount(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp sgt i32 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = zext i32 %7 to i64
%12 = call i8* @llvm.stacksave()
%13 = alloca i8*, i64 %11
%14 = call i8* @strcpy(i8* dereferenceable(1) %5, i8* %2)
%15 = call i32 @splitStringIntoArray(i8* %5, i8** %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br i1 %8, label %19, label %17
17: ; preds = %19, %0
%18 = call i32 @free(i8* %5)
ret i32 0
19: ; preds = %0, %19
%20 = phi i64 [ %25, %19 ], [ 0, %0 ]
%21 = getelementptr inbounds i8*, i8** %13, i64 %20
%22 = load i8*, i8** %21
%23 = trunc i64 %20 to i32
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %23, i8* %22)
%25 = add nuw nsw i64 %20, 1
%26 = icmp eq i64 %25, %11
br i1 %26, label %17, label %19
}