#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 */
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void str_char_split(char *str, char *a, char *b, char c) {
  char *p = str;
  if (str == NULL)
    return;
  while (*p) {
    if (*p == c)
      break;
    p++;
  }
  if (*p == '\0') {
    strcpy(a, str);
    return;
  } else {
    strncpy(a, str, p - str);
    strcpy(b, p + 1);
  }
}


x86 assembly (clang, -O0):
<str_char_split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1151 <str_char_split+0x31>
jmp    11d9 <str_char_split+0xb9>
jmp    1156 <str_char_split+0x36>
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     118c <str_char_split+0x6c>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jne    117b <str_char_split+0x5b>
jmp    118c <str_char_split+0x6c>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1156 <str_char_split+0x36>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ae <str_char_split+0x8e>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    11d9 <str_char_split+0xb9>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
call   1040 <strcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_char_split>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1173 <str_char_split+0x53>
mov    %rdx,%r14
mov    %rdi,%r8
mov    $0xffffffff,%edx
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
add    $0x1,%rbx
add    $0x1,%edx
test   %al,%al
je     1152 <str_char_split+0x32>
cmp    %cl,%al
jne    1140 <str_char_split+0x20>
mov    %rsi,%rdi
mov    %r8,%rsi
test   %al,%al
je     1167 <str_char_split+0x47>
call   1030 <strncpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @str_char_split(i8* %0, i8* %1, i8* %2, i8 signext %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8 %3, i8* %8
%10 = load i8*, i8** %5
store i8* %10, i8** %9
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %4
br label %53
14: ; preds = %4
br label %15
15: ; preds = %27, %14
%16 = load i8*, i8** %9
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = load i8*, i8** %9
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = load i8, i8* %8
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %27
26: ; preds = %19
br label %30
27: ; preds = %19
%28 = load i8*, i8** %9
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %9
br label %15
30: ; preds = %26, %15
%31 = load i8*, i8** %9
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = load i8*, i8** %5
%38 = call i32 @strcpy(i8* %36, i8* %37)
br label %53
39: ; preds = %30
%40 = load i8*, i8** %6
%41 = load i8*, i8** %5
%42 = load i8*, i8** %9
%43 = load i8*, i8** %5
%44 = ptrtoint i8* %42 to i64
%45 = ptrtoint i8* %43 to i64
%46 = sub i64 %44, %45
%47 = trunc i64 %46 to i32
%48 = call i32 @strncpy(i8* %40, i8* %41, i32 %47)
%49 = load i8*, i8** %7
%50 = load i8*, i8** %9
%51 = getelementptr inbounds i8, i8* %50, i64 1
%52 = call i32 @strcpy(i8* %49, i8* %51)
br label %53
53: ; preds = %13, %35, %39
ret void
}

LLVM IR (-O2):
define void @str_char_split(i8* %0, i8* %1, i8* %2, i8 signext %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %23, label %6
6: ; preds = %4, %6
%7 = phi i8* [ %12, %6 ], [ %0, %4 ]
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
%10 = icmp eq i8 %8, %3
%11 = or i1 %9, %10
%12 = getelementptr inbounds i8, i8* %7, i64 1
br i1 %11, label %13, label %6
13: ; preds = %6
br i1 %9, label %14, label %16
14: ; preds = %13
%15 = tail call i32 @strcpy(i8* %1, i8* %0)
br label %23
16: ; preds = %13
%17 = ptrtoint i8* %7 to i64
%18 = ptrtoint i8* %0 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
%21 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %20)
%22 = tail call i32 @strcpy(i8* %2, i8* %12)
br label %23
23: ; preds = %4, %16, %14
ret void
}