#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*/ FREE(char *);
char *MALLOC(int);
char *STRDUP(char const *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *trim_spaces(char *);
void split2(const char *str_in, char sep, char **s1_out, char **s2_out) {
  char *str = STRDUP(str_in);
  char *s1 = MALLOC(sizeof(char) * (strlen(str) + 1));
  char *s2 = MALLOC(sizeof(char) * (strlen(str) + 1));
  char *p = strchr(str, sep);
  if (p) {
    *p = '\0';
    strcpy(s1, str);
    *p = sep;
    strcpy(s2, p + 1);
  } else {
    strcpy(s1, str);
    strcpy(s2, "");
  }
  *s1_out = trim_spaces(s1);
  *s2_out = trim_spaces(s2);
  FREE(s1);
  FREE(s2);
  FREE(str);
}


x86 assembly (clang, -O0):
<split2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <STRDUP@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <MALLOC@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <MALLOC@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1050 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1220 <split2+0xb0>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x9(%rbp),%cl
mov    -0x40(%rbp),%rax
mov    %cl,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
jmp    123d <split2+0xcd>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xdc8(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
call   1090 <trim_spaces@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
call   1090 <trim_spaces@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
call   1060 <FREE@plt>
mov    -0x38(%rbp),%rdi
call   1060 <FREE@plt>
mov    -0x28(%rbp),%rdi
call   1060 <FREE@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,(%rsp)
mov    %rdx,%r15
mov    %esi,%ebp
call   1080 <STRDUP@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <MALLOC@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <MALLOC@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11e1 <split2+0x71>
mov    %rax,%r14
movb   $0x0,(%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %bpl,(%r14)
add    $0x1,%r14
mov    %r13,%rdi
mov    %r14,%rsi
jmp    11f6 <split2+0x86>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe0d(%rip),%rsi
mov    %r13,%rdi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1090 <trim_spaces@plt>
mov    %rax,(%r15)
mov    %r13,%rdi
call   1090 <trim_spaces@plt>
mov    (%rsp),%rcx
mov    %rax,(%rcx)
mov    %r12,%rdi
call   1060 <FREE@plt>
mov    %r13,%rdi
call   1060 <FREE@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <FREE@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define void @split2(i8* %0, i8 signext %1, i8** %2, i8** %3) {
%5 = alloca i8*
%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** %5
store i8 %1, i8* %6
store i8** %2, i8*** %7
store i8** %3, i8*** %8
%13 = load i8*, i8** %5
%14 = call i8* @STRDUP(i8* %13)
store i8* %14, i8** %9
%15 = load i8*, i8** %9
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = mul i64 1, %18
%20 = trunc i64 %19 to i32
%21 = call i8* @MALLOC(i32 %20)
store i8* %21, i8** %10
%22 = load i8*, i8** %9
%23 = call i32 @strlen(i8* %22)
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = mul i64 1, %25
%27 = trunc i64 %26 to i32
%28 = call i8* @MALLOC(i32 %27)
store i8* %28, i8** %11
%29 = load i8*, i8** %9
%30 = load i8, i8* %6
%31 = call i8* @strchr(i8* %29, i8 signext %30)
store i8* %31, i8** %12
%32 = load i8*, i8** %12
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %45
34: ; preds = %4
%35 = load i8*, i8** %12
store i8 0, i8* %35
%36 = load i8*, i8** %10
%37 = load i8*, i8** %9
%38 = call i32 @strcpy(i8* %36, i8* %37)
%39 = load i8, i8* %6
%40 = load i8*, i8** %12
store i8 %39, i8* %40
%41 = load i8*, i8** %11
%42 = load i8*, i8** %12
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = call i32 @strcpy(i8* %41, i8* %43)
br label %51
45: ; preds = %4
%46 = load i8*, i8** %10
%47 = load i8*, i8** %9
%48 = call i32 @strcpy(i8* %46, i8* %47)
%49 = load i8*, i8** %11
%50 = call i32 @strcpy(i8* %49, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %51
51: ; preds = %45, %34
%52 = load i8*, i8** %10
%53 = call i8* @trim_spaces(i8* %52)
%54 = load i8**, i8*** %7
store i8* %53, i8** %54
%55 = load i8*, i8** %11
%56 = call i8* @trim_spaces(i8* %55)
%57 = load i8**, i8*** %8
store i8* %56, i8** %57
%58 = load i8*, i8** %10
%59 = call i32 @FREE(i8* %58)
%60 = load i8*, i8** %11
%61 = call i32 @FREE(i8* %60)
%62 = load i8*, i8** %9
%63 = call i32 @FREE(i8* %62)
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define void @split2(i8* %0, i8 signext %1, i8** nocapture writeonly %2, i8** nocapture writeonly %3) {
%5 = tail call i8* @STRDUP(i8* %0)
%6 = tail call i32 @strlen(i8* %5)
%7 = add nsw i32 %6, 1
%8 = tail call i8* @MALLOC(i32 %7)
%9 = tail call i32 @strlen(i8* %5)
%10 = add nsw i32 %9, 1
%11 = tail call i8* @MALLOC(i32 %10)
%12 = tail call i8* @strchr(i8* dereferenceable(1) %5, i8 signext %1)
%13 = icmp eq i8* %12, null
br i1 %13, label %18, label %14
14: ; preds = %4
store i8 0, i8* %12
%15 = tail call i32 @strcpy(i8* %8, i8* %5)
store i8 %1, i8* %12
%16 = getelementptr inbounds i8, i8* %12, i64 1
%17 = tail call i32 @strcpy(i8* %11, i8* %16)
br label %21
18: ; preds = %4
%19 = tail call i32 @strcpy(i8* %8, i8* %5)
%20 = tail call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %18, %14
%22 = tail call i8* @trim_spaces(i8* %8)
store i8* %22, i8** %2
%23 = tail call i8* @trim_spaces(i8* %11)
store i8* %23, i8** %3
%24 = tail call i32 @FREE(i8* %8)
%25 = tail call i32 @FREE(i8* %11)
%26 = tail call i32 @FREE(i8* %5)
ret void
}