#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 */
scalar_t__ calloc(unsigned int, int);
unsigned int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, unsigned int);
char *strrchr(char *, char);
int split_root_suffix(char *input, char **root, char **suffix) {
  char *sptr = NULL;
  unsigned int len, rootlen = 0, suffixlen = 0;
  len = strlen(input);
  sptr = strrchr(input, '.');
  if (sptr == NULL) {
    *root = (char *)calloc(len + 1, sizeof(char));
    strncpy(*root, input, len);
    return 0;
  } else {
    rootlen = sptr - input;
    *root = (char *)calloc(rootlen + 1, sizeof(char));
    strncpy(*root, input, rootlen);
    suffixlen = len - rootlen - 1;
    *suffix = (char *)calloc(suffixlen + 1, sizeof(char));
    strncpy(*suffix, sptr + 1, suffixlen);
    return 1;
  }
}


x86 assembly (clang, -O0):
<split_root_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11cc <split_root_suffix+0x8c>
mov    -0x2c(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    124b <split_root_suffix+0x10b>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x2c(%rbp),%eax
sub    -0x30(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
mov    -0x34(%rbp),%edx
call   1030 <strncpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_root_suffix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r13
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r13,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11cc <split_root_suffix+0x8c>
mov    %rax,%r14
mov    %rbx,(%rsp)
mov    %r14d,%ebx
sub    %r13d,%ebx
lea    0x1(%rbx),%edi
mov    $0x1,%ebp
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,(%r12)
mov    %rax,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
sub    %ebx,%r15d
lea    -0x1(%r15),%ebx
mov    %r15d,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    (%rsp),%rcx
mov    %rax,(%rcx)
add    $0x1,%r14
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
jmp    11f0 <split_root_suffix+0xb0>
mov    %r15d,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,(%r12)
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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