#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 */
char *strsep(char **, char const *);
char *strtok_r(char *restrict string, const char *restrict delimiters,
               char **restrict state) {
  char *r;
  if (string == NULL)
    *state = string;
  for (;;) {
    r = strsep(state, delimiters);
    if (r == NULL)
      return NULL;
    if (*r)
      return r;
  }
}


x86 assembly (clang, -O0):
<strtok_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    113a <strtok_r+0x2a>
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
jmp    113f <strtok_r+0x2f>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strsep@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1168 <strtok_r+0x58>
movq   $0x0,-0x8(%rbp)
jmp    1187 <strtok_r+0x77>
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     1182 <strtok_r+0x72>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1187 <strtok_r+0x77>
jmp    113f <strtok_r+0x2f>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtok_r>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
test   %rdi,%rdi
jne    1130 <strtok_r+0x20>
movq   $0x0,(%rbx)
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strsep@plt>
test   %rax,%rax
je     1145 <strtok_r+0x35>
cmpb   $0x0,(%rax)
je     1130 <strtok_r+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @strtok_r(i8* noalias %0, i8* noalias %1, i8** noalias %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = load i8**, i8*** %7
store i8* %12, i8** %13
br label %14
14: ; preds = %11, %3
br label %15
15: ; preds = %28, %14
%16 = load i8**, i8*** %7
%17 = load i8*, i8** %6
%18 = call i8* @strsep(i8** %16, i8* %17)
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %15
store i8* null, i8** %4
br label %29
22: ; preds = %15
%23 = load i8*, i8** %8
%24 = load i8, i8* %23
%25 = icmp ne i8 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = load i8*, i8** %8
store i8* %27, i8** %4
br label %29
28: ; preds = %22
br label %15
29: ; preds = %26, %21
%30 = load i8*, i8** %4
ret i8* %30
}

LLVM IR (-O2):
define i8* @strtok_r(i8* noalias readnone %0, i8* noalias %1, i8** noalias %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %6
5: ; preds = %3
store i8* null, i8** %2
br label %6
6: ; preds = %5, %3
br label %7
7: ; preds = %6, %10
%8 = tail call i8* @strsep(i8** %2, i8* %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i8, i8* %8
%12 = icmp eq i8 %11, 0
br i1 %12, label %7, label %13
13: ; preds = %10, %7
ret i8* %8
}