#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 *concat_strings(char *, char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *concat_path(char *d, char *f) {
  if ((d == NULL) || (strlen(d) == 0) || (strcmp(d, "/") == 0)) {
    return concat_strings("/", f);
  } else if ((f == NULL) || (strlen(f) == 0)) {
    return d;
  } else {
    char *path = (char *)malloc(strlen(d) + strlen(f) + 2);
    strcpy(path, d);
    strcat(path, "/");
    strcat(path, f);
    return path;
  }
}


x86 assembly (clang, -O0):
<concat_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a8 <concat_path+0x48>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     11a8 <concat_path+0x48>
mov    -0x10(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11c1 <concat_path+0x61>
mov    -0x18(%rbp),%rsi
lea    0xe4d(%rip),%rdi
call   1060 <concat_strings@plt>
mov    %rax,-0x8(%rbp)
jmp    1248 <concat_path+0xe8>
cmpq   $0x0,-0x18(%rbp)
je     11df <concat_path+0x7f>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    11ec <concat_path+0x8c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1248 <concat_path+0xe8>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xdd2(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concat_path>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     11e7 <concat_path+0x87>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     11e7 <concat_path+0x87>
lea    0xe84(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11e7 <concat_path+0x87>
test   %r14,%r14
je     11de <concat_path+0x7e>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     11de <concat_path+0x7e>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe38(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %r15,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe12(%rip),%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <concat_strings@plt>

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 i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %17, label %9
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13, %9, %2
%18 = load i8*, i8** %5
%19 = call i8* @concat_strings(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %18)
store i8* %19, i8** %3
br label %47
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = icmp eq i8* %21, null
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = load i8*, i8** %5
%25 = call i64 @strlen(i8* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23, %20
%28 = load i8*, i8** %4
store i8* %28, i8** %3
br label %47
29: ; preds = %23
%30 = load i8*, i8** %4
%31 = call i64 @strlen(i8* %30)
%32 = load i8*, i8** %5
%33 = call i64 @strlen(i8* %32)
%34 = add nsw i64 %31, %33
%35 = add nsw i64 %34, 2
%36 = call i64 @malloc(i64 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %6
%38 = load i8*, i8** %6
%39 = load i8*, i8** %4
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = load i8*, i8** %6
%42 = call i32 @strcat(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%43 = load i8*, i8** %6
%44 = load i8*, i8** %5
%45 = call i32 @strcat(i8* %43, i8* %44)
%46 = load i8*, i8** %6
store i8* %46, i8** %3
br label %47
47: ; preds = %29, %27, %17
%48 = load i8*, i8** %3
ret i8* %48
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @concat_path(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7, %4, %2
%11 = tail call i8* @concat_strings(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %26
12: ; preds = %7
%13 = icmp eq i8* %1, null
br i1 %13, label %26, label %14
14: ; preds = %12
%15 = tail call i64 @strlen(i8* %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %14
%18 = tail call i64 @strlen(i8* %0)
%19 = add i64 %15, 2
%20 = add i64 %19, %18
%21 = tail call i64 @malloc(i64 %20)
%22 = inttoptr i64 %21 to i8*
%23 = tail call i32 @strcpy(i8* %22, i8* %0)
%24 = tail call i32 @strcat(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 @strcat(i8* %22, i8* %1)
br label %26
26: ; preds = %12, %14, %17, %10
%27 = phi i8* [ %11, %10 ], [ %22, %17 ], [ %0, %14 ], [ %0, %12 ]
ret i8* %27
}