#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 */
scalar_t__ asprintf(char **, char *, char const *, char *, char const *);
int /*<<< orphan*/ die(int, char *);
int strlen(char const *);
char *merge_paths(const char *base_path, const char *rel_path) {
  char *path;
  if (asprintf(&path, "%s%s%s", base_path,
               (base_path[strlen(base_path) - 1] == '/' ? "" : "/"),
               rel_path) < 0)
    die(1, "allocating merge path buffer");
  return path;
}


x86 assembly (clang, -O0):
<merge_paths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe93(%rip),%rcx
lea    0xe8d(%rip),%rax
cmp    $0x2f,%esi
cmove  %rax,%rcx
mov    -0x10(%rbp),%r8
lea    -0x18(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1040 <asprintf@plt>
cmp    $0x0,%rax
jge    11b1 <merge_paths+0x81>
mov    $0x1,%edi
lea    0xe5d(%rip),%rsi
call   1050 <die@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_paths>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
lea    0xebb(%rip),%rax
lea    0xeb3(%rip),%rcx
cmove  %rax,%rcx
lea    0xea1(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
mov    %r14,%r8
call   1040 <asprintf@plt>
test   %rax,%rax
jns    1183 <merge_paths+0x53>
lea    0xe90(%rip),%rsi
mov    $0x1,%edi
call   1050 <die@plt>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s%s%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [29 x i8] c"allocating merge path buffer\00"
define i8* @merge_paths(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 = load i8*, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = sub nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 47
%16 = zext i1 %15 to i64
%17 = select i1 %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%18 = load i8*, i8** %4
%19 = call i64 @asprintf(i8** %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %17, i8* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @die(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %2
%24 = load i8*, i8** %5
ret i8* %24
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s%s%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [29 x i8] c"allocating merge path buffer\00"
define i8* @merge_paths(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 47
%11 = select i1 %10, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%12 = call i64 @asprintf(i8** %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %11, i8* %1)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @die(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = load i8*, i8** %3
ret i8* %17
}