#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 strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strstr(char const *, char const *);
int strstrsplit(const char *str, const char *sep, char **former_result,
                char **latter_result) {
  char *split;
  char *former, *latter;
  split = strstr(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 + strlen(sep));
  *former_result = former;
  *latter_result = latter;
  return 0;
}


x86 assembly (clang, -O0):
<strstrsplit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1190 <strstrsplit+0x40>
movl   $0x1,-0x4(%rbp)
jmp    122e <strstrsplit+0xde>
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    11c1 <strstrsplit+0x71>
movl   $0x1,-0x4(%rbp)
jmp    122e <strstrsplit+0xde>
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),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
cltq
add    %rax,%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    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstrsplit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r13
call   1070 <strstr@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     11d7 <strstrsplit+0x87>
mov    %rax,%r15
mov    %rbp,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %rax,%rbx
sub    %r13,%rbx
lea    0x1(%rbx),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11d7 <strstrsplit+0x87>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x0(%rbp,%rbx,1)
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r15
mov    %r15,%rdi
call   1060 <strdup@plt>
mov    0x8(%rsp),%rcx
mov    %rbp,(%rcx)
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @strstrsplit(i8* %0, i8* %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* @strstr(i8* %13, i8* %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 %58
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 %58
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 = load i8*, i8** %7
%50 = call i32 @strlen(i8* %49)
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
%53 = call i8* @strdup(i8* %52)
store i8* %53, i8** %12
%54 = load i8*, i8** %11
%55 = load i8**, i8*** %8
store i8* %54, i8** %55
%56 = load i8*, i8** %12
%57 = load i8**, i8*** %9
store i8* %56, i8** %57
store i32 0, i32* %5
br label %58
58: ; preds = %31, %30, %18
%59 = load i32, i32* %5
ret i32 %59
}

LLVM IR (-O2):
define i32 @strstrsplit(i8* %0, i8* %1, i8** nocapture writeonly %2, i8** nocapture writeonly %3) {
%5 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %22, 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 %22, 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 = tail call i32 @strlen(i8* %1)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %5, i64 %19
%21 = tail call i8* @strdup(i8* %20)
store i8* %13, i8** %2
store i8* %21, i8** %3
br label %22
22: ; preds = %7, %4, %15
%23 = phi i32 [ 0, %15 ], [ 1, %4 ], [ 1, %7 ]
ret i32 %23
}