#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*/ free(char *);
int /*<<< orphan*/ ft_fs_isdotordotdot(char const *);
scalar_t__ ft_fs_path_isvalid(char const *);
char *ft_strdup(char const *);
char *ft_strjoin(char *, char const *);
char *ft_strjoinwithglue(char *, char const *, char);
int ft_strlen(char *);
char *ft_fs_path_join(const char *prefix, const char *path) {
  char *temp_pref;
  char *res;
  int size;
  temp_pref = NULL;
  if (ft_fs_path_isvalid(path) && !ft_fs_isdotordotdot(path))
    return (ft_strdup(path));
  if (!ft_fs_path_isvalid(prefix))
    temp_pref = ft_strjoinwithglue(".", prefix, '/');
  else
    temp_pref = ft_strdup(prefix);
  size = ft_strlen(temp_pref);
  if (size > 0 && temp_pref[size - 1] == '/')
    res = ft_strjoin(temp_pref, path);
  else
    res = ft_strjoinwithglue(temp_pref, path, '/');
  free(temp_pref);
  return (res);
}


x86 assembly (clang, -O0):
<ft_fs_path_join>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ft_fs_path_isvalid@plt>
cmp    $0x0,%rax
je     11bf <ft_fs_path_join+0x4f>
mov    -0x18(%rbp),%rdi
call   1060 <ft_fs_isdotordotdot@plt>
cmp    $0x0,%eax
jne    11bf <ft_fs_path_join+0x4f>
mov    -0x18(%rbp),%rdi
call   1070 <ft_strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    126a <ft_fs_path_join+0xfa>
mov    -0x10(%rbp),%rdi
call   1030 <ft_fs_path_isvalid@plt>
cmp    $0x0,%rax
jne    11f0 <ft_fs_path_join+0x80>
mov    -0x10(%rbp),%rsi
lea    0xe23(%rip),%rdi
mov    $0x2f,%edx
call   1090 <ft_strjoinwithglue@plt>
mov    %rax,-0x20(%rbp)
jmp    11fd <ft_fs_path_join+0x8d>
mov    -0x10(%rbp),%rdi
call   1070 <ft_strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <ft_strlen@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    1243 <ft_fs_path_join+0xd3>
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1243 <ft_fs_path_join+0xd3>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <ft_strjoin@plt>
mov    %rax,-0x28(%rbp)
jmp    1259 <ft_fs_path_join+0xe9>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x2f,%edx
call   1090 <ft_strjoinwithglue@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_fs_path_join>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <ft_fs_path_isvalid@plt>
test   %rax,%rax
je     1193 <ft_fs_path_join+0x23>
mov    %r14,%rdi
call   1060 <ft_fs_isdotordotdot@plt>
test   %eax,%eax
je     1209 <ft_fs_path_join+0x99>
mov    %rbx,%rdi
call   1030 <ft_fs_path_isvalid@plt>
test   %rax,%rax
je     11aa <ft_fs_path_join+0x3a>
mov    %rbx,%rdi
call   1070 <ft_strdup@plt>
jmp    11be <ft_fs_path_join+0x4e>
lea    0xe4f(%rip),%rdi
mov    %rbx,%rsi
mov    $0x2f,%edx
call   1090 <ft_strjoinwithglue@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <ft_strlen@plt>
test   %eax,%eax
jle    11e3 <ft_fs_path_join+0x73>
add    $0xffffffff,%eax
cmpb   $0x2f,(%rbx,%rax,1)
jne    11e3 <ft_fs_path_join+0x73>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <ft_strjoin@plt>
jmp    11f3 <ft_fs_path_join+0x83>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2f,%edx
call   1090 <ft_strjoinwithglue@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <ft_strdup@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i8* @ft_fs_path_join(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
%9 = load i8*, i8** %5
%10 = call i64 @ft_fs_path_isvalid(i8* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = call i32 @ft_fs_isdotordotdot(i8* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = call i8* @ft_strdup(i8* %17)
store i8* %18, i8** %3
br label %55
19: ; preds = %12, %2
%20 = load i8*, i8** %4
%21 = call i64 @ft_fs_path_isvalid(i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = call i8* @ft_strjoinwithglue(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %24, i8 signext 47)
store i8* %25, i8** %6
br label %29
26: ; preds = %19
%27 = load i8*, i8** %4
%28 = call i8* @ft_strdup(i8* %27)
store i8* %28, i8** %6
br label %29
29: ; preds = %26, %23
%30 = load i8*, i8** %6
%31 = call i32 @ft_strlen(i8* %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %47
34: ; preds = %29
%35 = load i8*, i8** %6
%36 = load i32, i32* %8
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 47
br i1 %42, label %43, label %47
43: ; preds = %34
%44 = load i8*, i8** %6
%45 = load i8*, i8** %5
%46 = call i8* @ft_strjoin(i8* %44, i8* %45)
store i8* %46, i8** %7
br label %51
47: ; preds = %34, %29
%48 = load i8*, i8** %6
%49 = load i8*, i8** %5
%50 = call i8* @ft_strjoinwithglue(i8* %48, i8* %49, i8 signext 47)
store i8* %50, i8** %7
br label %51
51: ; preds = %47, %43
%52 = load i8*, i8** %6
%53 = call i32 @free(i8* %52)
%54 = load i8*, i8** %7
store i8* %54, i8** %3
br label %55
55: ; preds = %51, %16
%56 = load i8*, i8** %3
ret i8* %56
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i8* @ft_fs_path_join(i8* %0, i8* %1) {
%3 = tail call i64 @ft_fs_path_isvalid(i8* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i32 @ft_fs_isdotordotdot(i8* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i8* @ft_strdup(i8* %1)
br label %34
10: ; preds = %5, %2
%11 = tail call i64 @ft_fs_path_isvalid(i8* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i8* @ft_strjoinwithglue(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %0, i8 signext 47)
br label %17
15: ; preds = %10
%16 = tail call i8* @ft_strdup(i8* %0)
br label %17
17: ; preds = %15, %13
%18 = phi i8* [ %16, %15 ], [ %14, %13 ]
%19 = tail call i32 @ft_strlen(i8* %18)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = add nsw i32 %19, -1
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %18, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 47
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = tail call i8* @ft_strjoin(i8* %18, i8* %1)
br label %31
29: ; preds = %21, %17
%30 = tail call i8* @ft_strjoinwithglue(i8* %18, i8* %1, i8 signext 47)
br label %31
31: ; preds = %29, %27
%32 = phi i8* [ %28, %27 ], [ %30, %29 ]
%33 = tail call i32 @free(i8* %18)
br label %34
34: ; preds = %31, %8
%35 = phi i8* [ %32, %31 ], [ %9, %8 ]
ret i8* %35
}