#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 *strstr(char *, char const *);
char *strtok_ex(char *_Str, const char *_Delim, char **_Context) {
  char *temp;
  if (NULL == _Str) {
    return NULL;
  }
  temp = strstr(_Str, _Delim);
  if (NULL == temp) {
    *_Context = 0;
    return _Str;
  }
  *_Context = temp + 1;
  *temp = 0;
  return _Str;
}


x86 assembly (clang, -O0):
<strtok_ex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    113d <strtok_ex+0x2d>
movq   $0x0,-0x8(%rbp)
jmp    1190 <strtok_ex+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strstr@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    1172 <strtok_ex+0x62>
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1190 <strtok_ex+0x80>
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtok_ex>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %rdi,%rdi
je     1142 <strtok_ex+0x32>
mov    %rdx,%r14
mov    %rbx,%rdi
call   1030 <strstr@plt>
test   %rax,%rax
je     113b <strtok_ex+0x2b>
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,(%r14)
movb   $0x0,(%rax)
jmp    1142 <strtok_ex+0x32>
movq   $0x0,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @strtok_ex(i8* %0, i8* %1, i8** %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* null, %9
br i1 %10, label %11, label %12
11: ; preds = %3
store i8* null, i8** %4
br label %27
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i8*, i8** %6
%15 = call i8* @strstr(i8* %13, i8* %14)
store i8* %15, i8** %8
%16 = load i8*, i8** %8
%17 = icmp eq i8* null, %16
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i8**, i8*** %7
store i8* null, i8** %19
%20 = load i8*, i8** %5
store i8* %20, i8** %4
br label %27
21: ; preds = %12
%22 = load i8*, i8** %8
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = load i8**, i8*** %7
store i8* %23, i8** %24
%25 = load i8*, i8** %8
store i8 0, i8* %25
%26 = load i8*, i8** %5
store i8* %26, i8** %4
br label %27
27: ; preds = %21, %18, %11
%28 = load i8*, i8** %4
ret i8* %28
}

LLVM IR (-O2):
define i8* @strtok_ex(i8* %0, i8* nocapture %1, i8** nocapture writeonly %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %11, label %5
5: ; preds = %3
%6 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %5
store i8* null, i8** %2
br label %11
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %6, i64 1
store i8* %10, i8** %2
store i8 0, i8* %6
br label %11
11: ; preds = %3, %9, %8
ret i8* %0
}