#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 *, int);
char *cstring_split_at_char(char *str, char **next, int ch) {
  char *end;
  if ((end = strchr(str, ch)) != 0) {
    *end++ = 0;
  } else {
    end = strchr(str, 0);
  }
  if (next != 0) {
    *next = end;
  }
  return str;
}


x86 assembly (clang, -O0):
<cstring_split_at_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1154 <cstring_split_at_char+0x44>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
jmp    1163 <cstring_split_at_char+0x53>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1179 <cstring_split_at_char+0x69>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cstring_split_at_char>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1153 <cstring_split_at_char+0x33>
mov    %rax,%rcx
add    $0x1,%rax
movb   $0x0,(%rcx)
test   %r14,%r14
je     1148 <cstring_split_at_char+0x28>
mov    %rax,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    %rbx,%rax
test   %r14,%r14
jne    1145 <cstring_split_at_char+0x25>
jmp    1148 <cstring_split_at_char+0x28>

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

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