#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 *strdup(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char const *, char const);
int strrchrsplit(const char *str, const char sep, char **former_result,
                 char **latter_result) {
  char *split;
  char *former, *latter;
  split = strrchr(str, 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):
<strrchrsplit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1040 <strrchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1182 <strrchrsplit+0x42>
movl   $0x1,-0x4(%rbp)
jmp    120e <strrchrsplit+0xce>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11b3 <strrchrsplit+0x73>
movl   $0x1,-0x4(%rbp)
jmp    120e <strrchrsplit+0xce>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1060 <strdup@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrchrsplit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rdi,%r12
call   1040 <strrchr@plt>
mov    $0x1,%r13d
test   %rax,%rax
je     11ac <strrchrsplit+0x6c>
mov    %rax,%rbp
mov    %rbx,(%rsp)
mov    %rax,%rbx
sub    %r12,%rbx
lea    0x1(%rbx),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11ac <strrchrsplit+0x6c>
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 @strrchrsplit(i8* %0, i8 signext %1, i8** %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %6
store i8 %1, i8* %7
store i8** %2, i8*** %8
store i8** %3, i8*** %9
%13 = load i8*, i8** %6
%14 = load i8, i8* %7
%15 = call i8* @strrchr(i8* %13, i8 signext %14)
store i8* %15, i8** %10
%16 = load i8*, i8** %10
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %4
store i32 1, i32* %5
br label %55
19: ; preds = %4
%20 = load i8*, i8** %10
%21 = load i8*, i8** %6
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = add nsw i64 %24, 1
%26 = trunc i64 %25 to i32
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %11
%28 = load i8*, i8** %11
%29 = icmp ne i8* %28, null
br i1 %29, label %31, label %30
30: ; preds = %19
store i32 1, i32* %5
br label %55
31: ; preds = %19
%32 = load i8*, i8** %11
%33 = load i8*, i8** %6
%34 = load i8*, i8** %10
%35 = load i8*, i8** %6
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = trunc i64 %38 to i32
%40 = call i32 @strncpy(i8* %32, i8* %33, i32 %39)
%41 = load i8*, i8** %11
%42 = load i8*, i8** %10
%43 = load i8*, i8** %6
%44 = ptrtoint i8* %42 to i64
%45 = ptrtoint i8* %43 to i64
%46 = sub i64 %44, %45
%47 = getelementptr inbounds i8, i8* %41, i64 %46
store i8 0, i8* %47
%48 = load i8*, i8** %10
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = call i8* @strdup(i8* %49)
store i8* %50, i8** %12
%51 = load i8*, i8** %11
%52 = load i8**, i8*** %8
store i8* %51, i8** %52
%53 = load i8*, i8** %12
%54 = load i8**, i8*** %9
store i8* %53, i8** %54
store i32 0, i32* %5
br label %55
55: ; preds = %31, %30, %18
%56 = load i32, i32* %5
ret i32 %56
}

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