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


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,-0x18(%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),%rsi
mov    -0x18(%rbp),%rcx
lea    0xe80(%rip),%rdx
lea    0xe78(%rip),%rax
cmp    $0x0,%rcx
cmove  %rax,%rdx
mov    -0x10(%rbp),%rcx
lea    0xe5e(%rip),%rdi
call   1030 <xasprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat_path_file>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rdi,%rdi
lea    0xed3(%rip),%r15
cmove  %r15,%r14
mov    %r14,%rdi
mov    $0x2f,%esi
call   1040 <last_char_is@plt>
add    $0xffffffffffffffff,%rbx
nopw   0x0(%rax,%rax,1)
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),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <xasprintf@plt>

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*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %9
9: ; preds = %8, %2
%10 = load i8*, i8** %3
%11 = call i8* @last_char_is(i8* %10, i8 signext 47)
store i8* %11, i8** %5
br label %12
12: ; preds = %17, %9
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 47
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %4
br label %12
20: ; preds = %12
%21 = load i8*, i8** %3
%22 = load i8*, i8** %5
%23 = icmp eq i8* %22, null
%24 = zext i1 %23 to i64
%25 = select i1 %23, 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)
%26 = load i8*, i8** %4
%27 = call i8* @xasprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %25, i8* %26)
ret i8* %27
}

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 = icmp eq i8* %0, null
%4 = select i1 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
%5 = tail call i8* @last_char_is(i8* %4, i8 signext 47)
br label %6
6: ; preds = %6, %2
%7 = phi i8* [ %1, %2 ], [ %10, %6 ]
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
%10 = getelementptr inbounds i8, i8* %7, i64 1
br i1 %9, label %6, label %11
11: ; preds = %6
%12 = icmp eq i8* %5, null
%13 = select i1 %12, 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)
%14 = tail call i8* @xasprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %13, i8* %7)
ret i8* %14
}