#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 *malloc(int);
char *strchr(char const *, char const);
char *strdup(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int strpchrsplit(const char *str, const char *pos, const char sep,
                 char **former_result, char **latter_result) {
  char *split;
  char *former, *latter;
  split = strchr(pos, sep);
  if (!split) {
    return 1;
  }
  former = malloc(split - str + 1);
  if (!former) {
    return 1;
  }
  strncpy(former, str, split - str);
  former[split - str] = '\0';
  latter = strdup(split + 1);
  *former_result = former;
  *latter_result = latter;
  return 0;
}


x86 assembly (clang, -O0):
<strpchrsplit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
movsbl -0x19(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1185 <strpchrsplit+0x45>
movl   $0x1,-0x4(%rbp)
jmp    1211 <strpchrsplit+0xd1>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11b6 <strpchrsplit+0x76>
movl   $0x1,-0x4(%rbp)
jmp    1211 <strpchrsplit+0xd1>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1060 <strdup@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strpchrsplit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%rbx
mov    %rcx,%r15
mov    %rdi,%r12
mov    %rsi,%rdi
mov    %edx,%esi
call   1040 <strchr@plt>
mov    $0x1,%r13d
test   %rax,%rax
je     11b1 <strpchrsplit+0x71>
mov    %rax,%rbp
mov    %rbx,(%rsp)
mov    %rax,%rbx
sub    %r12,%rbx
lea    0x1(%rbx),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11b1 <strpchrsplit+0x71>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%rbx,1)
add    $0x1,%rbp
mov    %rbp,%rdi
call   1060 <strdup@plt>
mov    %r14,(%r15)
mov    (%rsp),%rcx
mov    %rax,(%rcx)
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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