#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*/ printf(char *, ...);
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) {
    printf("%s string delim subdelim \n", argv[0]);
    goto out;
  }
  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);
    }
  }
out:
  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)
cmpl   $0x4,-0x8(%rbp)
je     115a <main+0x3a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121b <main+0xfb>
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    1196 <main+0x76>
jmp    1216 <main+0xf6>
mov    -0x44(%rbp),%esi
mov    -0x28(%rbp),%rdx
lea    0xe77(%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    11dc <main+0xbc>
jmp    11fb <main+0xdb>
mov    -0x30(%rbp),%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x20(%rbp)
jmp    11b3 <main+0x93>
jmp    1200 <main+0xe0>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
movq   $0x0,-0x18(%rbp)
jmp    116d <main+0x4d>
jmp    121b <main+0xfb>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

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    11e2 <main+0xc2>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
lea    0x8(%rsp),%rdx
call   1040 <strtok_r@plt>
test   %rax,%rax
je     11f3 <main+0xd3>
mov    %rax,%r14
mov    $0x1,%r15d
lea    0x10(%rsp),%rbp
lea    0x8(%rsp),%r12
lea    0xeb5(%rip),%r13
jmp    119a <main+0x7a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
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     11f3 <main+0xd3>
lea    0xe7a(%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     1180 <main+0x60>
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x18(%rbx),%rsi
xor    %edi,%edi
jmp    11c0 <main+0xa0>
mov    (%rbx),%rsi
lea    0xe14(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"%s string delim subdelim \0A\00"
@.str.1 = [9 x i8] c"%d : %s\0A\00"
@.str.2 = [8 x i8] c"--> %s\0A\00"
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 %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %56
20: ; preds = %2
store i32 1, i32* %12
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
store i8* %23, i8** %6
br label %24
24: ; preds = %52, %20
%25 = load i8*, i8** %6
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i8* @strtok_r(i8* %25, i8* %28, i8** %10)
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %24
br label %55
33: ; preds = %24
%34 = load i32, i32* %12
%35 = load i8*, i8** %8
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %34, i8* %35)
%37 = load i8*, i8** %8
store i8* %37, i8** %7
br label %38
38: ; preds = %50, %33
%39 = load i8*, i8** %7
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 3
%42 = load i8*, i8** %41
%43 = call i8* @strtok_r(i8* %39, i8* %42, i8** %11)
store i8* %43, i8** %9
%44 = load i8*, i8** %9
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %47
46: ; preds = %38
br label %51
47: ; preds = %38
%48 = load i8*, i8** %9
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %47
store i8* null, i8** %7
br label %38
51: ; preds = %46
br label %52
52: ; preds = %51
%53 = load i32, i32* %12
%54 = add nsw i32 %53, 1
store i32 %54, i32* %12
store i8* null, i8** %6
br label %24
55: ; preds = %32
br label %56
56: ; preds = %55, %15
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"%s string delim subdelim \0A\00"
@.str.1 = [9 x i8] c"%d : %s\0A\00"
@.str.2 = [8 x i8] c"--> %s\0A\00"
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 %11, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %38
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = call i8* @strtok_r(i8* %13, i8* %15, i8** %3)
%17 = icmp eq i8* %16, null
br i1 %17, label %38, label %18
18: ; preds = %11
%19 = getelementptr inbounds i8*, i8** %1, i64 3
br label %20
20: ; preds = %18, %33
%21 = phi i8* [ %16, %18 ], [ %36, %33 ]
%22 = phi i32 [ 1, %18 ], [ %34, %33 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %22, i8* %21)
%24 = load i8*, i8** %19
%25 = call i8* @strtok_r(i8* %21, i8* %24, i8** %4)
%26 = icmp eq i8* %25, null
br i1 %26, label %33, label %27
27: ; preds = %20, %27
%28 = phi i8* [ %31, %27 ], [ %25, %20 ]
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = load i8*, i8** %19
%31 = call i8* @strtok_r(i8* null, i8* %30, i8** %4)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %27
33: ; preds = %27, %20
%34 = add nuw nsw i32 %22, 1
%35 = load i8*, i8** %14
%36 = call i8* @strtok_r(i8* null, i8* %35, i8** %3)
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %20
38: ; preds = %33, %11, %8
ret i32 0
}