#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__ endwith(char *, char *);
int /*<<< orphan*/ *getenv(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char const *);
int strlen(char *);
char *join_path(char *path, const char *path_later) {
  if (!endwith(path, "/"))
    strcat(path, "/");
  strcat(path, path_later);
  if (endwith(path, "/"))
    path[strlen(path) - 1] = '\0';
  do {
    if (getenv("DEBUG") != NULL)
      printf("%-30s'%s'\n", "[join_path]", path);
  } while (0);
  return path;
}


x86 assembly (clang, -O0):
<join_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <endwith@plt>
cmp    $0x0,%rax
jne    118a <join_path+0x3a>
mov    -0x8(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1060 <endwith@plt>
cmp    $0x0,%rax
je     11d2 <join_path+0x82>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11d7 <join_path+0x87>
lea    0xe24(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1204 <join_path+0xb4>
mov    -0x8(%rbp),%rdx
lea    0xe10(%rip),%rdi
lea    0xe14(%rip),%rsi
call   1050 <printf@plt>
jmp    1209 <join_path+0xb9>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<join_path>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe9f(%rip),%rsi
call   1060 <endwith@plt>
test   %rax,%rax
jne    117a <join_path+0x2a>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
lea    0xe74(%rip),%rsi
mov    %rbx,%rdi
call   1060 <endwith@plt>
test   %rax,%rax
je     11a8 <join_path+0x58>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xe53(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11cf <join_path+0x7f>
lea    0xe48(%rip),%rdi
lea    0xe4c(%rip),%rsi
mov    %rbx,%rdx
call   1050 <printf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [6 x i8] c"DEBUG\00"
@.str.2 = [11 x i8] c"%-30s'%s'\0A\00"
@.str.3 = [12 x i8] c"[join_path]\00"
define i8* @join_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %3
%6 = call i64 @endwith(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp ne i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %8, %2
%12 = load i8*, i8** %3
%13 = load i8*, i8** %4
%14 = call i32 @strcat(i8* %12, i8* %13)
%15 = load i8*, i8** %3
%16 = call i64 @endwith(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %11
%19 = load i8*, i8** %3
%20 = load i8*, i8** %3
%21 = call i32 @strlen(i8* %20)
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %19, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %18, %11
br label %26
26: ; preds = %25
%27 = call i32* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i8*, i8** %3
%31 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %29, %26
br label %33
33: ; preds = %32
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [6 x i8] c"DEBUG\00"
@.str.2 = [11 x i8] c"%-30s'%s'\0A\00"
@.str.3 = [12 x i8] c"[join_path]\00"
define i8* @join_path(i8* returned %0, i8* %1) {
%3 = tail call i64 @endwith(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
%8 = tail call i32 @strcat(i8* %0, i8* %1)
%9 = tail call i64 @endwith(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = tail call i32 @strlen(i8* %0)
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %7, %11
%17 = tail call i32* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %21
21: ; preds = %16, %19
ret i8* %0
}