#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);
char *strsep2(char **s, char c) {
  char *t = *s, *k;
  if (*s == NULL)
    return NULL;
  k = strchr(*s, c);
  if (k == NULL)
    *s = NULL;
  else
    k[0] = '\0', *s = k + 1;
  return t;
}


x86 assembly (clang, -O0):
<strsep2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1148 <strsep2+0x38>
movq   $0x0,-0x8(%rbp)
jmp    1195 <strsep2+0x85>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1177 <strsep2+0x67>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
jmp    118d <strsep2+0x7d>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strsep2>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%rbx
test   %rbx,%rbx
je     113e <strsep2+0x2e>
mov    %rdi,%r14
movsbl %sil,%esi
mov    %rbx,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     1139 <strsep2+0x29>
movb   $0x0,(%rax)
add    $0x1,%rax
jmp    113b <strsep2+0x2b>
xor    %eax,%eax
mov    %rax,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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