#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 *split_comma(char *str) {
  if (str == NULL || *str == '\0')
    return NULL;
  char *ptr = strchr(str, ',');
  if (!ptr)
    return NULL;
  *ptr = '\0';
  ptr++;
  if (*ptr == '\0')
    return NULL;
  return ptr;
}


x86 assembly (clang, -O0):
<split_comma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1137 <split_comma+0x27>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1144 <split_comma+0x34>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <split_comma+0x96>
mov    -0x10(%rbp),%rdi
mov    $0x2c,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116e <split_comma+0x5e>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <split_comma+0x96>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    119e <split_comma+0x8e>
movq   $0x0,-0x8(%rbp)
jmp    11a6 <split_comma+0x96>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_comma>:
push   %rax
test   %rdi,%rdi
je     1143 <split_comma+0x33>
cmpb   $0x0,(%rdi)
je     1143 <split_comma+0x33>
mov    $0x2c,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1143 <split_comma+0x33>
mov    %rax,%rcx
movb   $0x0,(%rax)
mov    %rax,%rdx
add    $0x1,%rdx
xor    %eax,%eax
cmpb   $0x0,0x1(%rcx)
cmovne %rdx,%rax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

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

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