#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(int, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *strchr(char *, char);
int strlen(char *);
char *parse_slice(char *buf, char sep) {
  char *pr, *part;
  int 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    11e2 <parse_slice+0xa2>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b3 <parse_slice+0x73>
movq   $0x0,-0x8(%rbp)
jmp    11e2 <parse_slice+0xa2>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x2c(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x2c(%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     1192 <parse_slice+0x52>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
lea    0x1(%r15),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     1192 <parse_slice+0x52>
mov    %rax,%rbx
mov    %r14,%rsi
add    $0x1,%rsi
mov    %rax,%rdi
mov    %r15d,%edx
call   1060 <memcpy@plt>
movslq %r15d,%rax
movb   $0x0,(%rbx,%rax,1)
movb   $0x0,(%r14)
jmp    1194 <parse_slice+0x54>
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 i32
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 %36
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = add nsw i32 %18, 1
%20 = call i8* @calloc(i32 %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 %36
24: ; preds = %15
%25 = load i8*, i8** %7
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i32, i32* %8
%29 = call i32 @memcpy(i8* %25, i8* %27, i32 %28)
%30 = load i8*, i8** %7
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
%34 = load i8*, i8** %6
store i8 0, i8* %34
%35 = load i8*, i8** %7
store i8* %35, i8** %3
br label %36
36: ; preds = %24, %23, %14
%37 = load i8*, i8** %3
ret i8* %37
}

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 %15, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %3)
%7 = add nsw i32 %6, 1
%8 = tail call i8* @calloc(i32 %7, i32 1)
%9 = icmp eq i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %3, i64 1
%12 = tail call i32 @memcpy(i8* %8, i8* %11, i32 %6)
%13 = sext i32 %6 to i64
%14 = getelementptr inbounds i8, i8* %8, i64 %13
store i8 0, i8* %14
store i8 0, i8* %3
br label %15
15: ; preds = %5, %2, %10
%16 = phi i8* [ %8, %10 ], [ null, %2 ], [ null, %5 ]
ret i8* %16
}