#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*/ bb_xasprintf(char **, char *, char const *, char *,
                                char const *);
char *last_char_is(char const *, char);
char *concat_path_file(const char *path, const char *filename) {
  char *outbuf;
  char *lc;
  if (!path)
    path = "";
  lc = last_char_is(path, '/');
  while (*filename == '/')
    filename++;
  bb_xasprintf(&outbuf, "%s%s%s", path, (lc == NULL ? "/" : ""), filename);
  return outbuf;
}


x86 assembly (clang, -O0):
<concat_path_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1146 <concat_path_file+0x26>
lea    0xec6(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <last_char_is@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1179 <concat_path_file+0x59>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1158 <concat_path_file+0x38>
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rsi
lea    0xe80(%rip),%rcx
lea    0xe78(%rip),%rax
cmp    $0x0,%rsi
cmove  %rax,%rcx
mov    -0x10(%rbp),%r8
lea    -0x18(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1030 <bb_xasprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat_path_file>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rdi,%rdi
lea    0xecf(%rip),%r15
cmove  %r15,%r14
mov    %r14,%rdi
mov    $0x2f,%esi
call   1040 <last_char_is@plt>
add    $0xffffffffffffffff,%rbx
xchg   %ax,%ax
cmpb   $0x2f,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     1150 <concat_path_file+0x30>
test   %rax,%rax
lea    0xea3(%rip),%rax
cmove  %rax,%r15
lea    0xe91(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
call   1030 <bb_xasprintf@plt>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [7 x i8] c"%s%s%s\00"
@.str.2 = [2 x i8] c"/\00"
define i8* @concat_path_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %10
10: ; preds = %9, %2
%11 = load i8*, i8** %3
%12 = call i8* @last_char_is(i8* %11, i8 signext 47)
store i8* %12, i8** %6
br label %13
13: ; preds = %18, %10
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 47
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
br label %13
21: ; preds = %13
%22 = load i8*, i8** %3
%23 = load i8*, i8** %6
%24 = icmp eq i8* %23, null
%25 = zext i1 %24 to i64
%26 = select i1 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
%27 = load i8*, i8** %4
%28 = call i32 @bb_xasprintf(i8** %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %26, i8* %27)
%29 = load i8*, i8** %5
ret i8* %29
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [7 x i8] c"%s%s%s\00"
@.str.2 = [2 x i8] c"/\00"
define i8* @concat_path_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i8* %0, null
%6 = select i1 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
%7 = tail call i8* @last_char_is(i8* %6, i8 signext 47)
br label %8
8: ; preds = %8, %2
%9 = phi i8* [ %1, %2 ], [ %12, %8 ]
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 47
%12 = getelementptr inbounds i8, i8* %9, i64 1
br i1 %11, label %8, label %13
13: ; preds = %8
%14 = icmp eq i8* %7, null
%15 = select i1 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
%16 = call i32 @bb_xasprintf(i8** %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %15, i8* %9)
%17 = load i8*, i8** %3
ret i8* %17
}