#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*/ chdir(char *);
int /*<<< orphan*/ error_log(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                             int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ getcwd(char *, int);
char *getenv(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void retrieve_full_path(char *path, const char *temp_path) {
  int a = 0, b = 0;
  path[0] = 0;
  char *old_dir, *current_dir;
  if (temp_path[0] == '~') {
    strcpy(path, getenv("HOME"));
    b = strlen(path);
    a = 1;
  } else if (temp_path[0] == '.' && temp_path[1] == '.') {
    old_dir = getenv("PWD");
    chdir("..");
    current_dir = (char *)malloc(1024);
    if (!current_dir)
      error_log(-9, NULL, NULL, NULL, "Malloc Failed!");
    getcwd(current_dir, 1024);
    strcpy(path, current_dir);
    b = strlen(path);
    a = 2;
    chdir(old_dir);
  } else if (temp_path[0] == '.') {
    strcpy(path, getenv("PWD"));
    b = strlen(path);
    a = 1;
  } else if (temp_path[0] != '/') {
    strcpy(path, getenv("PWD"));
    strcat(path, "/");
    b = strlen(path);
    a = 0;
  }
  strcat(path + b, temp_path + a);
  return;
}


x86 assembly (clang, -O0):
<retrieve_full_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    11ed <retrieve_full_path+0x6d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe3c(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    1344 <retrieve_full_path+0x1c4>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    129a <retrieve_full_path+0x11a>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    129a <retrieve_full_path+0x11a>
lea    0xdf0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
lea    0xde4(%rip),%rdi
call   1060 <chdir@plt>
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    125e <retrieve_full_path+0xde>
mov    $0xfffffff7,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    0xdb9(%rip),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1090 <error_log@plt>
mov    -0x28(%rbp),%rdi
mov    $0x400,%esi
call   1070 <getcwd@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x2,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <chdir@plt>
jmp    133f <retrieve_full_path+0x1bf>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    12e2 <retrieve_full_path+0x162>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xd4c(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x14(%rbp)
jmp    133a <retrieve_full_path+0x1ba>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1335 <retrieve_full_path+0x1b5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xd04(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    0xcfe(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    133a <retrieve_full_path+0x1ba>
jmp    133f <retrieve_full_path+0x1bf>
jmp    1344 <retrieve_full_path+0x1c4>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
call   10a0 <strcat@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<retrieve_full_path>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movb   $0x0,(%rdi)
mov    (%rsi),%al
cmp    $0x2e,%al
je     11be <retrieve_full_path+0x3e>
cmp    $0x2f,%al
je     1242 <retrieve_full_path+0xc2>
cmp    $0x7e,%al
jne    1247 <retrieve_full_path+0xc7>
lea    0xe52(%rip),%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
jmp    1282 <retrieve_full_path+0x102>
mov    0x1(%r14),%bpl
lea    0xe3c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r15
cmp    $0x2e,%bpl
jne    127c <retrieve_full_path+0xfc>
lea    0xe27(%rip),%rdi
call   1060 <chdir@plt>
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1210 <retrieve_full_path+0x90>
lea    0xe0c(%rip),%r8
mov    $0xfffffff7,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1090 <error_log@plt>
mov    %r12,%rdi
mov    $0x400,%esi
call   1070 <getcwd@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1060 <chdir@plt>
mov    $0x2,%eax
jmp    1297 <retrieve_full_path+0x117>
xor    %r12d,%r12d
jmp    1278 <retrieve_full_path+0xf8>
lea    0xdb7(%rip),%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    0xdb6(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
xor    %eax,%eax
jmp    1297 <retrieve_full_path+0x117>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    $0x1,%eax
movslq %r12d,%rcx
add    %rcx,%rbx
add    %rax,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <strcat@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [4 x i8] c"PWD\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [15 x i8] c"Malloc Failed!\00"
@.str.4 = [2 x i8] c"/\00"
define void @retrieve_full_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
store i8 0, i8* %10
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 126
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = load i8*, i8** %3
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %6
store i32 1, i32* %5
br label %82
22: ; preds = %2
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 46
br i1 %27, label %28, label %53
28: ; preds = %22
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 46
br i1 %33, label %34, label %53
34: ; preds = %28
%35 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %35, i8** %7
%36 = call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%37 = call i64 @malloc(i32 1024)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %8
%39 = load i8*, i8** %8
%40 = icmp ne i8* %39, null
br i1 %40, label %43, label %41
41: ; preds = %34
%42 = call i32 @error_log(i32 -9, i32* null, i32* null, i32* null, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %41, %34
%44 = load i8*, i8** %8
%45 = call i32 @getcwd(i8* %44, i32 1024)
%46 = load i8*, i8** %3
%47 = load i8*, i8** %8
%48 = call i32 @strcpy(i8* %46, i8* %47)
%49 = load i8*, i8** %3
%50 = call i32 @strlen(i8* %49)
store i32 %50, i32* %6
store i32 2, i32* %5
%51 = load i8*, i8** %7
%52 = call i32 @chdir(i8* %51)
br label %81
53: ; preds = %28, %22
%54 = load i8*, i8** %4
%55 = getelementptr inbounds i8, i8* %54, i64 0
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 46
br i1 %58, label %59, label %65
59: ; preds = %53
%60 = load i8*, i8** %3
%61 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%62 = call i32 @strcpy(i8* %60, i8* %61)
%63 = load i8*, i8** %3
%64 = call i32 @strlen(i8* %63)
store i32 %64, i32* %6
store i32 1, i32* %5
br label %80
65: ; preds = %53
%66 = load i8*, i8** %4
%67 = getelementptr inbounds i8, i8* %66, i64 0
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp ne i32 %69, 47
br i1 %70, label %71, label %79
71: ; preds = %65
%72 = load i8*, i8** %3
%73 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%74 = call i32 @strcpy(i8* %72, i8* %73)
%75 = load i8*, i8** %3
%76 = call i32 @strcat(i8* %75, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%77 = load i8*, i8** %3
%78 = call i32 @strlen(i8* %77)
store i32 %78, i32* %6
store i32 0, i32* %5
br label %79
79: ; preds = %71, %65
br label %80
80: ; preds = %79, %59
br label %81
81: ; preds = %80, %43
br label %82
82: ; preds = %81, %16
%83 = load i8*, i8** %3
%84 = load i32, i32* %6
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
%87 = load i8*, i8** %4
%88 = load i32, i32* %5
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8, i8* %87, i64 %89
%91 = call i32 @strcat(i8* %86, i8* %90)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [4 x i8] c"PWD\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [15 x i8] c"Malloc Failed!\00"
@.str.4 = [2 x i8] c"/\00"
define void @retrieve_full_path(i8* %0, i8* %1) {
store i8 0, i8* %0
%3 = load i8, i8* %1
switch i8 %3, label %28 [
i8 126, label %4
i8 46, label %8
i8 47, label %33
]
4: ; preds = %2
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @strcpy(i8* %0, i8* %5)
%7 = tail call i32 @strlen(i8* %0)
br label %33
8: ; preds = %2
%9 = getelementptr inbounds i8, i8* %1, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 46
%12 = tail call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br i1 %11, label %13, label %25
13: ; preds = %8
%14 = tail call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i64 @malloc(i32 1024)
%16 = inttoptr i64 %15 to i8*
%17 = icmp eq i64 %15, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @error_log(i32 -9, i32* null, i32* null, i32* null, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = tail call i32 @getcwd(i8* %16, i32 1024)
%22 = tail call i32 @strcpy(i8* %0, i8* %16)
%23 = tail call i32 @strlen(i8* %0)
%24 = tail call i32 @chdir(i8* %12)
br label %33
25: ; preds = %8
%26 = tail call i32 @strcpy(i8* %0, i8* %12)
%27 = tail call i32 @strlen(i8* %0)
br label %33
28: ; preds = %2
%29 = tail call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 @strcpy(i8* %0, i8* %29)
%31 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%32 = tail call i32 @strlen(i8* %0)
br label %33
33: ; preds = %2, %20, %28, %25, %4
%34 = phi i32 [ %7, %4 ], [ %23, %20 ], [ %27, %25 ], [ %32, %28 ], [ 0, %2 ]
%35 = phi i64 [ 1, %4 ], [ 2, %20 ], [ 1, %25 ], [ 0, %28 ], [ 0, %2 ]
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %0, i64 %36
%38 = getelementptr inbounds i8, i8* %1, i64 %35
%39 = tail call i32 @strcat(i8* %37, i8* %38)
ret void
}