#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 omp_get_thread_num();
int /*<<< orphan*/ printf(char *, int, ...);
char *strtok_r(char *, char *, char **);
void Tokenize(char *lines[], int line_count, int thread_count) {
  int my_rank, i, j;
  char *my_token, *saveptr;
#pragma omp parallel num_threads(thread_count) default(none) private(          \
    my_rank, i, j, my_token, saveptr) shared(lines, line_count)
  {
    my_rank = omp_get_thread_num();
#pragma omp for schedule(static, 1)
    for (i = 0; i < line_count; i++) {
      printf("Thread %d > line %d = %s", my_rank, i, lines[i]);
      j = 0;
      my_token = strtok_r(lines[i], " \t\n", &saveptr);
      while (my_token != NULL) {
        printf("Thread %d > token %d = %s\n", my_rank, j, my_token);
        my_token = strtok_r(NULL, " \t\n", &saveptr);
        j++;
      }
      if (lines[i] != NULL)
        printf("Thread %d > After tokenizing, my line = %s\n", my_rank,
               lines[i]);
    }
  }
}


x86 assembly (clang, -O0):
<Tokenize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    $0x0,%al
call   1030 <omp_get_thread_num@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1232 <Tokenize+0x102>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe80(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ef <Tokenize+0xbf>
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe45(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a6 <Tokenize+0x76>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     121f <Tokenize+0xef>
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1224 <Tokenize+0xf4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1153 <Tokenize+0x23>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Tokenize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <omp_get_thread_num@plt>
test   %ebx,%ebx
jle    120b <Tokenize+0xdb>
mov    %eax,%ebp
mov    %ebx,%eax
mov    %rax,(%rsp)
lea    0xeb8(%rip),%r12
lea    0x10(%rsp),%rbx
lea    0xeb0(%rip),%r13
xor    %r14d,%r14d
mov    %r15,0x8(%rsp)
jmp    118e <Tokenize+0x5e>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    (%rsp),%r14
je     120b <Tokenize+0xdb>
mov    (%r15,%r14,8),%rcx
lea    0xe67(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15,%r14,8),%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <strtok_r@plt>
test   %rax,%rax
je     11e8 <Tokenize+0xb8>
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <strtok_r@plt>
add    $0x1,%r15d
test   %rax,%rax
jne    11c0 <Tokenize+0x90>
mov    0x8(%rsp),%r15
mov    (%r15,%r14,8),%rdx
test   %rdx,%rdx
je     1180 <Tokenize+0x50>
lea    0xe3b(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1180 <Tokenize+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Thread %d > line %d = %s\00"
@.str.1 = [4 x i8] c" \09\0A\00"
@.str.2 = [27 x i8] c"Thread %d > token %d = %s\0A\00"
@.str.3 = [44 x i8] c"Thread %d > After tokenizing, my line = %s\0A\00"
define void @Tokenize(i8** %0, i32 %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = call i32 (...) @omp_get_thread_num()
store i32 %12, i32* %7
store i32 0, i32* %8
br label %13
13: ; preds = %59, %3
%14 = load i32, i32* %8
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %62
17: ; preds = %13
%18 = load i32, i32* %7
%19 = load i32, i32* %8
%20 = load i8**, i8*** %4
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19, i8* %24)
store i32 0, i32* %9
%26 = load i8**, i8*** %4
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i8* @strtok_r(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %11)
store i8* %31, i8** %10
br label %32
32: ; preds = %35, %17
%33 = load i8*, i8** %10
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %43
35: ; preds = %32
%36 = load i32, i32* %7
%37 = load i32, i32* %9
%38 = load i8*, i8** %10
%39 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %37, i8* %38)
%40 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %11)
store i8* %40, i8** %10
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %32
43: ; preds = %32
%44 = load i8**, i8*** %4
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %58
50: ; preds = %43
%51 = load i32, i32* %7
%52 = load i8**, i8*** %4
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %51, i8* %56)
br label %58
58: ; preds = %50, %43
br label %59
59: ; preds = %58
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %13
62: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"Thread %d > line %d = %s\00"
@.str.1 = [4 x i8] c" \09\0A\00"
@.str.2 = [27 x i8] c"Thread %d > token %d = %s\0A\00"
@.str.3 = [44 x i8] c"Thread %d > After tokenizing, my line = %s\0A\00"
define void @Tokenize(i8** nocapture %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i32 (...) @omp_get_thread_num()
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %34
8: ; preds = %3
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %31
%11 = phi i64 [ 0, %8 ], [ %32, %31 ]
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
%13 = load i8*, i8** %12
%14 = trunc i64 %11 to i32
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %14, i8* %13)
%16 = load i8*, i8** %12
%17 = call i8* @strtok_r(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %4)
%18 = icmp eq i8* %17, null
br i1 %18, label %26, label %19
19: ; preds = %10, %19
%20 = phi i8* [ %23, %19 ], [ %17, %10 ]
%21 = phi i32 [ %24, %19 ], [ 0, %10 ]
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %6, i32 %21, i8* %20)
%23 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %4)
%24 = add nuw nsw i32 %21, 1
%25 = icmp eq i8* %23, null
br i1 %25, label %26, label %19
26: ; preds = %19, %10
%27 = load i8*, i8** %12
%28 = icmp eq i8* %27, null
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %6, i8* %27)
br label %31
31: ; preds = %26, %29
%32 = add nuw nsw i64 %11, 1
%33 = icmp eq i64 %32, %9
br i1 %33, label %34, label %10
34: ; preds = %31, %3
ret void
}