#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 */
scalar_t__ 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 = (char *)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 %37
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 i64 @calloc(i32 %19, i32 1)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %15
store i8* null, i8** %3
br label %37
25: ; preds = %15
%26 = load i8*, i8** %7
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i32, i32* %8
%30 = call i32 @memcpy(i8* %26, i8* %28, i32 %29)
%31 = load i8*, i8** %7
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
%35 = load i8*, i8** %6
store i8 0, i8* %35
%36 = load i8*, i8** %7
store i8* %36, i8** %3
br label %37
37: ; preds = %25, %24, %14
%38 = load i8*, i8** %3
ret i8* %38
}

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