#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 *strchr(char *, char);
extern char *x_strtok(char **a, char **z, char delim) {
  char *r = *a;
  if (*a == NULL)
    return r;
  *z = strchr(*a, delim);
  if (*z == NULL) {
    *a = NULL;
    return r;
  }
  **z = '\0';
  *a = ++(*z);
  return r;
}


x86 assembly (clang, -O0):
<x_strtok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    114b <x_strtok+0x3b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b2 <x_strtok+0xa2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
movsbl -0x19(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    118b <x_strtok+0x7b>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b2 <x_strtok+0xa2>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<x_strtok>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%rbx
test   %rbx,%rbx
je     114a <x_strtok+0x3a>
mov    %rsi,%r15
mov    %rdi,%r14
movsbl %dl,%esi
mov    %rbx,%rdi
call   1030 <strchr@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1145 <x_strtok+0x35>
movb   $0x0,(%rax)
mov    (%r15),%rax
add    $0x1,%rax
mov    %rax,(%r15)
jmp    1147 <x_strtok+0x37>
xor    %eax,%eax
mov    %rax,(%r14)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @x_strtok(i8** %0, i8** %1, i8 signext %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 = load i8*, i8** %9
store i8* %10, i8** %8
%11 = load i8**, i8*** %5
%12 = load i8*, i8** %11
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = load i8*, i8** %8
store i8* %15, i8** %4
br label %36
16: ; preds = %3
%17 = load i8**, i8*** %5
%18 = load i8*, i8** %17
%19 = load i8, i8* %7
%20 = call i8* @strchr(i8* %18, i8 signext %19)
%21 = load i8**, i8*** %6
store i8* %20, i8** %21
%22 = load i8**, i8*** %6
%23 = load i8*, i8** %22
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = load i8**, i8*** %5
store i8* null, i8** %26
%27 = load i8*, i8** %8
store i8* %27, i8** %4
br label %36
28: ; preds = %16
%29 = load i8**, i8*** %6
%30 = load i8*, i8** %29
store i8 0, i8* %30
%31 = load i8**, i8*** %6
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %31
%34 = load i8**, i8*** %5
store i8* %33, i8** %34
%35 = load i8*, i8** %8
store i8* %35, i8** %4
br label %36
36: ; preds = %28, %25, %14
%37 = load i8*, i8** %4
ret i8* %37
}

LLVM IR (-O2):
define i8* @x_strtok(i8** nocapture %0, i8** nocapture %1, i8 signext %2) {
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %14, label %6
6: ; preds = %3
%7 = tail call i8* @strchr(i8* %4, i8 signext %2)
store i8* %7, i8** %1
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %6
store i8 0, i8* %7
%10 = load i8*, i8** %1
%11 = getelementptr inbounds i8, i8* %10, i64 1
store i8* %11, i8** %1
br label %12
12: ; preds = %6, %9
%13 = phi i8* [ %11, %9 ], [ null, %6 ]
store i8* %13, i8** %0
br label %14
14: ; preds = %12, %3
ret i8* %4
}