#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*/ free(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
char *readline_with_prompt(char *);
char *strtok(char *, char *);
int main(void) {
  char *line = readline_with_prompt("Enter string to parse");
  printf("String entered: '%s'\n", line);
  int i = 0;
  char *separators = " \t";
  char *token = strtok(line, separators);
  while (token != 0) {
    printf("%2d '%s'\n", i++, token);
    token = strtok(NULL, separators);
  }
  free(line);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1060 <readline_with_prompt@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
lea    0xead(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11d5 <main+0x95>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
movslq %eax,%rsi
mov    -0x28(%rbp),%rdx
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1194 <main+0x54>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeb1(%rip),%rdi
call   1060 <readline_with_prompt@plt>
mov    %rax,%r14
lea    0xeb8(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebd(%rip),%rsi
mov    %r14,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11b3 <main+0x73>
lea    0xeac(%rip),%r15
lea    0xea2(%rip),%r12
xor    %esi,%esi
nopl   0x0(%rax)
lea    0x1(%rsi),%rbx
mov    %r15,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   1050 <strtok@plt>
mov    %rbx,%rsi
test   %rax,%rax
jne    1190 <main+0x50>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Enter string to parse\00"
@.str.1 = [22 x i8] c"String entered: '%s'\0A\00"
@.str.2 = [3 x i8] c" \09\00"
@.str.3 = [10 x i8] c"%2d '%s'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i8* @readline_with_prompt(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %7)
store i32 0, i32* %3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %4
%9 = load i8*, i8** %2
%10 = load i8*, i8** %4
%11 = call i8* @strtok(i8* %9, i8* %10)
store i8* %11, i8** %5
br label %12
12: ; preds = %15, %0
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
%18 = sext i32 %16 to i64
%19 = inttoptr i64 %18 to i8*
%20 = load i8*, i8** %5
%21 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %19, i8* %20)
%22 = load i8*, i8** %4
%23 = call i8* @strtok(i8* null, i8* %22)
store i8* %23, i8** %5
br label %12
24: ; preds = %12
%25 = load i8*, i8** %2
%26 = call i32 @free(i8* %25)
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [22 x i8] c"Enter string to parse\00"
@.str.1 = [22 x i8] c"String entered: '%s'\0A\00"
@.str.2 = [3 x i8] c" \09\00"
@.str.3 = [10 x i8] c"%2d '%s'\0A\00"
define i32 @main() {
%1 = tail call i8* @readline_with_prompt(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%3 = tail call i8* @strtok(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %13, label %5
5: ; preds = %0, %5
%6 = phi i64 [ %8, %5 ], [ 0, %0 ]
%7 = phi i8* [ %11, %5 ], [ %3, %0 ]
%8 = add nuw i64 %6, 1
%9 = inttoptr i64 %6 to i8*
%10 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %9, i8* %7)
%11 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %5
13: ; preds = %5, %0
%14 = tail call i32 @free(i8* %1)
ret i32 0
}