#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 *fp_join(char *, char const *);
int /*<<< orphan*/ getcwd(char *, int);
char *strdup(char const *);
scalar_t__ strlen(char const *);
char *fp_abs(const char *path) {
  char __cwd[4096] = {}, *abs = NULL;
  getcwd(__cwd, 4096);
  if (strlen(path) == 0)
    return strdup(__cwd);
  if (path[0] == '/')
    return strdup(path);
  abs = fp_join(__cwd, path);
  return abs;
}


x86 assembly (clang, -O0):
<fp_abs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x1010(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
movq   $0x0,-0x1018(%rbp)
lea    -0x1010(%rbp),%rdi
mov    $0x1000,%esi
call   1060 <getcwd@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    11b6 <fp_abs+0x66>
lea    -0x1010(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11fa <fp_abs+0xaa>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11d8 <fp_abs+0x88>
mov    -0x10(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11fa <fp_abs+0xaa>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <fp_join@plt>
mov    %rax,-0x1018(%rbp)
mov    -0x1018(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp_abs>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rdi,%rbx
mov    %rsp,%r14
mov    $0x1000,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r14,%rdi
mov    $0x1000,%esi
call   1050 <getcwd@plt>
mov    (%rbx),%al
cmp    $0x2f,%al
je     1180 <fp_abs+0x40>
mov    %rsp,%rdi
test   %al,%al
jne    118a <fp_abs+0x4a>
call   1060 <strdup@plt>
jmp    1192 <fp_abs+0x52>
mov    %rbx,%rdi
call   1060 <strdup@plt>
jmp    1192 <fp_abs+0x52>
mov    %rbx,%rsi
call   1030 <fp_join@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @fp_abs(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [4096 x i8]
%5 = alloca i8*
store i8* %0, i8** %3
%6 = bitcast [4096 x i8]* %4 to i8*
store i8* null, i8** %5
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%8 = call i32 @getcwd(i8* %7, i32 4096)
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%14 = call i8* @strdup(i8* %13)
store i8* %14, i8** %2
br label %29
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 47
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i8*, i8** %3
%23 = call i8* @strdup(i8* %22)
store i8* %23, i8** %2
br label %29
24: ; preds = %15
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%26 = load i8*, i8** %3
%27 = call i8* @fp_join(i8* %25, i8* %26)
store i8* %27, i8** %5
%28 = load i8*, i8** %5
store i8* %28, i8** %2
br label %29
29: ; preds = %24, %21, %12
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
define i8* @fp_abs(i8* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = call i32 @getcwd(i8* %3, i32 4096)
%5 = load i8, i8* %0
switch i8 %5, label %10 [
i8 0, label %6
i8 47, label %8
]
6: ; preds = %1
%7 = call i8* @strdup(i8* %3)
br label %12
8: ; preds = %1
%9 = call i8* @strdup(i8* %0)
br label %12
10: ; preds = %1
%11 = call i8* @fp_join(i8* %3, i8* %0)
br label %12
12: ; preds = %10, %8, %6
%13 = phi i8* [ %7, %6 ], [ %9, %8 ], [ %11, %10 ]
ret i8* %13
}