#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 *malloc(int);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strcut(char *, int, int);
int strlen(char *);
char *parse_slice(char *buf, int len, char sep) {
  char *pr = strchr(buf, sep);
  if (pr == NULL)
    return pr;
  int plen = strlen(pr);
  int size = sizeof(*pr) * plen;
  char *cache[size];
  strcpy((char *)cache, buf);
  strcut((char *)cache, 0, strlen(buf) - plen + 1);
  char *part = malloc(size);
  strcpy(part, (char *)cache);
  int offset = strlen(buf) - strlen(pr);
  strcut(buf, offset, len);
  return part;
}


x86 assembly (clang, -O0):
<parse_slice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x15(%rbp),%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118d <parse_slice+0x3d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1249 <parse_slice+0xf9>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,8),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%edx
sub    -0x24(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1070 <strcut@plt>
mov    -0x28(%rbp),%edi
call   1060 <malloc@plt>
mov    -0x50(%rbp),%rsi
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x44(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1070 <strcut@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_slice>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r13
mov    %edx,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11fd <parse_slice+0xad>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %rsp,-0x30(%rbp)
mov    %eax,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
sub    %r12d,%eax
lea    0x1(%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <strcut@plt>
mov    %r12d,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebx
mov    %r13,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   1070 <strcut@plt>
mov    -0x30(%rbp),%rsp
jmp    1200 <parse_slice+0xb0>
xor    %r12d,%r12d
mov    %r12,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @parse_slice(i8* %0, i32 %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8 %2, i8* %7
%15 = load i8*, i8** %5
%16 = load i8, i8* %7
%17 = call i8* @strchr(i8* %15, i8 signext %16)
store i8* %17, i8** %8
%18 = load i8*, i8** %8
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = load i8*, i8** %8
store i8* %21, i8** %4
br label %59
22: ; preds = %3
%23 = load i8*, i8** %8
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = mul i64 1, %26
%28 = trunc i64 %27 to i32
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = zext i32 %29 to i64
%31 = call i8* @llvm.stacksave()
store i8* %31, i8** %11
%32 = alloca i8*, i64 %30
store i64 %30, i64* %12
%33 = bitcast i8** %32 to i8*
%34 = load i8*, i8** %5
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = bitcast i8** %32 to i8*
%37 = load i8*, i8** %5
%38 = call i32 @strlen(i8* %37)
%39 = load i32, i32* %9
%40 = sub nsw i32 %38, %39
%41 = add nsw i32 %40, 1
%42 = call i32 @strcut(i8* %36, i32 0, i32 %41)
%43 = load i32, i32* %10
%44 = call i8* @malloc(i32 %43)
store i8* %44, i8** %13
%45 = load i8*, i8** %13
%46 = bitcast i8** %32 to i8*
%47 = call i32 @strcpy(i8* %45, i8* %46)
%48 = load i8*, i8** %5
%49 = call i32 @strlen(i8* %48)
%50 = load i8*, i8** %8
%51 = call i32 @strlen(i8* %50)
%52 = sub nsw i32 %49, %51
store i32 %52, i32* %14
%53 = load i8*, i8** %5
%54 = load i32, i32* %14
%55 = load i32, i32* %6
%56 = call i32 @strcut(i8* %53, i32 %54, i32 %55)
%57 = load i8*, i8** %13
store i8* %57, i8** %4
%58 = load i8*, i8** %11
br label %59
59: ; preds = %22, %20
%60 = load i8*, i8** %4
ret i8* %60
}

LLVM IR (-O2):
define i8* @parse_slice(i8* %0, i32 %1, i8 signext %2) {
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %23, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %4)
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8*, i64 %8
%11 = bitcast i8** %10 to i8*
%12 = call i32 @strcpy(i8* %11, i8* %0)
%13 = call i32 @strlen(i8* %0)
%14 = sub i32 1, %7
%15 = add i32 %14, %13
%16 = call i32 @strcut(i8* %11, i32 0, i32 %15)
%17 = call i8* @malloc(i32 %7)
%18 = call i32 @strcpy(i8* %17, i8* %11)
%19 = call i32 @strlen(i8* %0)
%20 = call i32 @strlen(i8* %4)
%21 = sub nsw i32 %19, %20
%22 = call i32 @strcut(i8* %0, i32 %21, i32 %1)
br label %23
23: ; preds = %3, %6
%24 = phi i8* [ %17, %6 ], [ null, %3 ]
ret i8* %24
}