#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*/ util_alloc_file_components(char const *,
                                              int /*<<< orphan*/ *, char **,
                                              char **);
char *util_alloc_filename(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ util_safe_free(char *);
char *util_split_alloc_filename(const char *input_path) {
  char *filename = NULL;
  {
    char *basename;
    char *extension;
    util_alloc_file_components(input_path, NULL, &basename, &extension);
    if (basename)
      filename = util_alloc_filename(NULL, basename, extension);
    util_safe_free(basename);
    util_safe_free(extension);
  }
  return filename;
}


x86 assembly (clang, -O0):
<util_split_alloc_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1030 <util_alloc_file_components@plt>
cmpq   $0x0,-0x18(%rbp)
je     1179 <util_split_alloc_filename+0x49>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
call   1050 <util_alloc_filename@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <util_safe_free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <util_safe_free@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_split_alloc_filename>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %r14d,%r14d
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
xor    %esi,%esi
call   1030 <util_alloc_file_components@plt>
mov    0x10(%rsp),%rsi
mov    $0x0,%ebx
test   %rsi,%rsi
je     116e <util_split_alloc_filename+0x3e>
mov    0x8(%rsp),%rdx
xor    %edi,%edi
call   1050 <util_alloc_filename@plt>
mov    %rax,%rbx
mov    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <util_safe_free@plt>
mov    0x8(%rsp),%rdi
call   1040 <util_safe_free@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @util_split_alloc_filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%6 = load i8*, i8** %2
%7 = call i32 @util_alloc_file_components(i8* %6, i32* null, i8** %4, i8** %5)
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i8* @util_alloc_filename(i32* null, i8* %11, i8* %12)
store i8* %13, i8** %3
br label %14
14: ; preds = %10, %1
%15 = load i8*, i8** %4
%16 = call i32 @util_safe_free(i8* %15)
%17 = load i8*, i8** %5
%18 = call i32 @util_safe_free(i8* %17)
%19 = load i8*, i8** %3
ret i8* %19
}

LLVM IR (-O2):
define i8* @util_split_alloc_filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = bitcast i8** %2 to i8*
%5 = bitcast i8** %3 to i8*
%6 = call i32 @util_alloc_file_components(i8* %0, i32* null, i8** %2, i8** %3)
%7 = load i8*, i8** %2
%8 = icmp eq i8* %7, null
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i8* @util_alloc_filename(i32* null, i8* %7, i8* %10)
%12 = load i8*, i8** %2
br label %13
13: ; preds = %9, %1
%14 = phi i8* [ %12, %9 ], [ null, %1 ]
%15 = phi i8* [ %11, %9 ], [ null, %1 ]
%16 = call i32 @util_safe_free(i8* %14)
%17 = load i8*, i8** %3
%18 = call i32 @util_safe_free(i8* %17)
ret i8* %15
}