#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_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
char *strtok_r(char *, char *, char **);
int main(int argc, char *argv[]) {
  char *str1, *str2, *token, *subtoken;
  char *saveptr1, *saveptr2;
  int j;
  if (argc != 4) {
    fprintf(stderr, "Usage: %s string delim subdelim\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  for (j = 1, str1 = argv[1];; j++, str1 = NULL) {
    token = strtok_r(str1, argv[2], &saveptr1);
    if (token == NULL)
      break;
    printf("%d: %s\n", j, token);
    for (str2 = token;; str2 = NULL) {
      subtoken = strtok_r(str2, argv[3], &saveptr2);
      if (subtoken == NULL)
        break;
      printf(" --> %s\n", subtoken);
    }
  }
  exit(EXIT_SUCCESS);
}


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)
cmpl   $0x4,-0x8(%rbp)
je     118a <main+0x4a>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
movl   $0x1,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x38(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c6 <main+0x86>
jmp    1246 <main+0x106>
mov    -0x44(%rbp),%esi
mov    -0x28(%rbp),%rdx
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    -0x40(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    120c <main+0xcc>
jmp    122b <main+0xeb>
mov    -0x30(%rbp),%rsi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x20(%rbp)
jmp    11e3 <main+0xa3>
jmp    1230 <main+0xf0>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
movq   $0x0,-0x18(%rbp)
jmp    119d <main+0x5d>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    117b <main+0x3b>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
lea    0x8(%rsp),%rdx
call   1040 <strtok_r@plt>
test   %rax,%rax
jne    11a1 <main+0x61>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe72(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    %rax,%r14
mov    $0x1,%r15d
lea    0x10(%rsp),%rbp
lea    0x8(%rsp),%r12
lea    0xe6e(%rip),%r13
jmp    11da <main+0x9a>
nopl   (%rax)
add    $0x1,%r15d
mov    0x10(%rbx),%rsi
xor    %edi,%edi
mov    %r12,%rdx
call   1040 <strtok_r@plt>
mov    %rax,%r14
test   %rax,%rax
je     116d <main+0x2d>
lea    0xe40(%rip),%rdi
mov    %r15d,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x18(%rbx),%rsi
mov    %r14,%rdi
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdx
call   1040 <strtok_r@plt>
test   %rax,%rax
je     11c0 <main+0x80>
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x18(%rbx),%rsi
xor    %edi,%edi
jmp    1200 <main+0xc0>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s string delim subdelim\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [8 x i8] c"%d: %s\0A\00"
@.str.2 = [9 x i8] c" --> %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 4
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
store i32 1, i32* %12
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %6
br label %27
27: ; preds = %55, %23
%28 = load i8*, i8** %6
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i8* @strtok_r(i8* %28, i8* %31, i8** %10)
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %36
35: ; preds = %27
br label %58
36: ; preds = %27
%37 = load i32, i32* %12
%38 = load i8*, i8** %8
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %37, i8* %38)
%40 = load i8*, i8** %8
store i8* %40, i8** %7
br label %41
41: ; preds = %53, %36
%42 = load i8*, i8** %7
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 3
%45 = load i8*, i8** %44
%46 = call i8* @strtok_r(i8* %42, i8* %45, i8** %11)
store i8* %46, i8** %9
%47 = load i8*, i8** %9
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %50
49: ; preds = %41
br label %54
50: ; preds = %41
%51 = load i8*, i8** %9
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %50
store i8* null, i8** %7
br label %41
54: ; preds = %49
br label %55
55: ; preds = %54
%56 = load i32, i32* %12
%57 = add nsw i32 %56, 1
store i32 %57, i32* %12
store i8* null, i8** %6
br label %27
58: ; preds = %35
%59 = load i32, i32* @EXIT_SUCCESS
%60 = call i32 @exit(i32 %59)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Usage: %s string delim subdelim\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [8 x i8] c"%d: %s\0A\00"
@.str.2 = [9 x i8] c" --> %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = icmp eq i32 %0, 4
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = call i8* @strtok_r(i8* %16, i8* %18, i8** %3)
%20 = icmp eq i8* %19, null
br i1 %20, label %41, label %21
21: ; preds = %14
%22 = getelementptr inbounds i8*, i8** %1, i64 3
br label %23
23: ; preds = %21, %36
%24 = phi i8* [ %19, %21 ], [ %39, %36 ]
%25 = phi i32 [ 1, %21 ], [ %37, %36 ]
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %25, i8* %24)
%27 = load i8*, i8** %22
%28 = call i8* @strtok_r(i8* %24, i8* %27, i8** %4)
%29 = icmp eq i8* %28, null
br i1 %29, label %36, label %30
30: ; preds = %23, %30
%31 = phi i8* [ %34, %30 ], [ %28, %23 ]
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %22
%34 = call i8* @strtok_r(i8* null, i8* %33, i8** %4)
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %30
36: ; preds = %30, %23
%37 = add nuw nsw i32 %25, 1
%38 = load i8*, i8** %17
%39 = call i8* @strtok_r(i8* null, i8* %38, i8** %3)
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %23
41: ; preds = %36, %14
%42 = load i32, i32* @EXIT_SUCCESS
%43 = call i32 @exit(i32 %42)
unreachable
}