#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 *calloc(size_t, int);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
char *strchr(char *, char);
size_t strlen(char *);
char *parse_slice(char *buf, char sep) {
  char *pr, *part;
  size_t plen;
  pr = strchr(buf, sep);
  if (pr == NULL)
    return NULL;
  plen = strlen(pr);
  part = calloc(plen + 1, sizeof(*part));
  if (part == NULL)
    return NULL;
  memcpy(part, pr + 1, plen);
  part[plen] = '\0';
  *pr = '\0';
  return part;
}


x86 assembly (clang, -O0):
<parse_slice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117b <parse_slice+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    11e6 <parse_slice+0xa6>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b6 <parse_slice+0x76>
movq   $0x0,-0x8(%rbp)
jmp    11e6 <parse_slice+0xa6>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x30(%rbp),%rdx
call   1060 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_slice>:
push   %r15
push   %r14
push   %rbx
call   1040 <strchr@plt>
test   %rax,%rax
je     1190 <parse_slice+0x50>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     1190 <parse_slice+0x50>
mov    %rax,%rbx
mov    %r14,%rsi
add    $0x1,%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   1060 <memcpy@plt>
movb   $0x0,(%rbx,%r15,1)
movb   $0x0,(%r14)
jmp    1192 <parse_slice+0x52>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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