#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 *asprintf(char *, char const *, char const *);
char *astrcat(char const *, char const *);
int strlen(char const *);
char *buildPath(const char *path1, const char *path2) {
  if (path1[strlen(path1) - 1] == '/') {
    return astrcat(path1, path2);
  } else {
    return asprintf("%s/%s", path1, path2);
  }
}


x86 assembly (clang, -O0):
<buildPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1180 <buildPath+0x50>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <astrcat@plt>
mov    %rax,-0x8(%rbp)
jmp    1198 <buildPath+0x68>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe71(%rip),%rdi
call   1040 <asprintf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buildPath>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    115a <buildPath+0x2a>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <astrcat@plt>
lea    0xe9f(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <asprintf@plt>

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

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