#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
char *strtok(char *, char *);
int main(int argc, char *argv[]) {
  int x = 1;
  char str[] = "this is a test of string tokenizing";
  char *str1;
  printf("String: %s\n", str);
  str1 = strtok(str, " ");
  printf("%i: %s\n", x, str1);
  while (1) {
    str1 = strtok(NULL, " ");
    if (str1 == NULL) {
      printf("Tokenizing complete\n");
      exit(0);
    }
    printf("%i: %s\n", x, str1);
    x++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe98(%rip),%rsi
mov    $0x24,%edx
call   1040 <memcpy@plt>
lea    -0x40(%rbp),%rsi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x48(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x48(%rbp),%rdx
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe78(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11e1 <main+0xa1>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%esi
mov    -0x48(%rbp),%rdx
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ad <main+0x6d>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
movaps 0xec0(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xea4(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x676e69,0x20(%rsp)
lea    0xeb5(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xead(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strtok@plt>
lea    0xe9d(%rip),%rdi
mov    $0x1,%ebx
mov    $0x1,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
je     11f1 <main+0xb1>
lea    0xe73(%rip),%r14
lea    0xe6a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    11d0 <main+0x90>
lea    0xe42(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@__const.main.str = [36 x i8] c"this is a test of string tokenizing\00"
@.str = [12 x i8] c"String: %s\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [8 x i8] c"%i: %s\0A\00"
@.str.3 = [21 x i8] c"Tokenizing complete\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [36 x i8]
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
%9 = bitcast [36 x i8]* %7 to i8*
%10 = getelementptr inbounds [36 x i8], [36 x i8]* %7, i64 0, i64 0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [36 x i8], [36 x i8]* %7, i64 0, i64 0
%13 = call i8* @strtok(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %8
%14 = load i32, i32* %6
%15 = load i8*, i8** %8
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %14, i8* %15)
br label %17
17: ; preds = %2, %24
%18 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %17
%25 = load i32, i32* %6
%26 = load i8*, i8** %8
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %25, i8* %26)
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %17
}

LLVM IR (-O2):
@__const.main.str = [36 x i8] c"this is a test of string tokenizing\00"
@.str = [12 x i8] c"String: %s\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [8 x i8] c"%i: %s\0A\00"
@str = [20 x i8] c"Tokenizing complete\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [36 x i8]
%4 = getelementptr inbounds [36 x i8], [36 x i8]* %3, i64 0, i64 0
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 1, i8* %6)
%8 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %13, %2
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %2, %13
%14 = phi i8* [ %18, %13 ], [ %8, %2 ]
%15 = phi i32 [ %17, %13 ], [ 1, %2 ]
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %15, i8* %14)
%17 = add nuw nsw i32 %15, 1
%18 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %10, label %13
}