#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);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *, char const *);
scalar_t__ strlen(char const *);
char *xmalloc(scalar_t__);
extern 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++;
  outbuf = xmalloc(strlen(path) + strlen(filename) + 1 + (lc == NULL));
  sprintf(outbuf, "%s%s%s", path, (lc == NULL) ? "/" : "", filename);
  return outbuf;
}


x86 assembly (clang, -O0):
<concat_path_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1166 <concat_path_file+0x26>
lea    0xea6(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <last_char_is@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1199 <concat_path_file+0x59>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1178 <concat_path_file+0x38>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
cmpq   $0x0,-0x20(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
cltq
add    %rax,%rdi
call   1040 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rsi
lea    0xe20(%rip),%rcx
lea    0xe18(%rip),%rax
cmp    $0x0,%rsi
cmove  %rax,%rcx
mov    -0x10(%rbp),%r8
lea    0xdfe(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat_path_file>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rdi,%rdi
lea    0xeaf(%rip),%r15
cmove  %r15,%r14
mov    %r14,%rdi
mov    $0x2f,%esi
call   1050 <last_char_is@plt>
mov    %rax,%r12
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0x2f,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     1180 <concat_path_file+0x40>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %ecx,%ecx
test   %r12,%r12
sete   %cl
lea    0xe5b(%rip),%rdx
cmove  %rdx,%r15
add    %r13,%rcx
lea    (%rax,%rcx,1),%rdi
add    $0x1,%rdi
call   1040 <xmalloc@plt>
mov    %rax,%r12
lea    0xe36(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
call   1060 <sprintf@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
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 = call i64 @strlen(i8* %22)
%24 = load i8*, i8** %4
%25 = call i64 @strlen(i8* %24)
%26 = add nsw i64 %23, %25
%27 = add nsw i64 %26, 1
%28 = load i8*, i8** %6
%29 = icmp eq i8* %28, null
%30 = zext i1 %29 to i32
%31 = sext i32 %30 to i64
%32 = add nsw i64 %27, %31
%33 = call i8* @xmalloc(i64 %32)
store i8* %33, i8** %5
%34 = load i8*, i8** %5
%35 = load i8*, i8** %3
%36 = load i8*, i8** %6
%37 = icmp eq i8* %36, null
%38 = zext i1 %37 to i64
%39 = select i1 %37, 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)
%40 = load i8*, i8** %4
%41 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %35, i8* %39, i8* %40)
%42 = load i8*, i8** %5
ret i8* %42
}

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 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%13 = tail call i64 @strlen(i8* %7)
%14 = icmp eq i8* %5, null
%15 = select i1 %14, i64 2, i64 1
%16 = add i64 %15, %12
%17 = add i64 %16, %13
%18 = tail call i8* @xmalloc(i64 %17)
%19 = 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)
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %18, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %19, i8* %7)
ret i8* %18
}