#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*/ strcat(char *, char *);
int strlen(char *);
char *concat_path(char *base_path, char *name) {
  char full_path[1024] = "";
  strcat(full_path, base_path);
  if ('/' != base_path[strlen(base_path) - 1]) {
    strcat(full_path, "/");
  }
  strcat(full_path, name);
}


x86 assembly (clang, -O0):
<concat_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x428(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x2f,%eax
cmp    %ecx,%eax
je     11ad <concat_path+0x7d>
lea    -0x420(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1050 <strcat@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat_path>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%r15
mov    $0x400,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
je     117f <concat_path+0x4f>
lea    0xe89(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strcat@plt>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @concat_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = bitcast [1024 x i8]* %6 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = call i32 @strcat(i8* %8, i8* %9)
%11 = load i8*, i8** %4
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %11, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 47, %18
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%22 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %20, %2
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%25 = load i8*, i8** %5
%26 = call i32 @strcat(i8* %24, i8* %25)
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define noalias i8* @concat_path(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcat(i8* %4, i8* %0)
%6 = call i32 @strlen(i8* %0)
%7 = add nsw i32 %6, -1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 47
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = call i32 @strcat(i8* %4, i8* %1)
ret i8* undef
}