#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 *);
char *get_current_dir_name();
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
scalar_t__ path_is_absolute(char const *);
char *realloc(char *, size_t);
char *strdup(char const *);
size_t strlen(char const *);
char *path_make_absolute_cwd(const char *p) {
  char *cwd, *r;
  size_t plen;
  size_t cwdlen;
  if (path_is_absolute(p))
    return strdup(p);
  cwd = get_current_dir_name();
  if (cwd == NULL)
    return NULL;
  plen = strlen(p);
  cwdlen = strlen(cwd);
  r = realloc(cwd, cwdlen + 1 + plen + 1);
  if (r == NULL) {
    free(cwd);
    return NULL;
  }
  r[cwdlen] = '/';
  memcpy(&r[cwdlen + 1], p, plen + 1);
  return r;
}


x86 assembly (clang, -O0):
<path_make_absolute_cwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <path_is_absolute@plt>
cmp    $0x0,%rax
je     11a1 <path_make_absolute_cwd+0x31>
mov    -0x10(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1250 <path_make_absolute_cwd+0xe0>
mov    $0x0,%al
call   1070 <get_current_dir_name@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c4 <path_make_absolute_cwd+0x54>
movq   $0x0,-0x8(%rbp)
jmp    1250 <path_make_absolute_cwd+0xe0>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
add    $0x1,%rsi
add    -0x28(%rbp),%rsi
add    $0x1,%rsi
call   1080 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121c <path_make_absolute_cwd+0xac>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1250 <path_make_absolute_cwd+0xe0>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rax
add    $0x1,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
add    $0x1,%rdx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_make_absolute_cwd>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%rbx
call   1060 <path_is_absolute@plt>
test   %rax,%rax
je     1197 <path_make_absolute_cwd+0x27>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1090 <strdup@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <get_current_dir_name@plt>
test   %rax,%rax
je     1202 <path_make_absolute_cwd+0x92>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
lea    (%r15,%rax,1),%rsi
add    $0x2,%rsi
mov    %r12,%rdi
call   1080 <realloc@plt>
test   %rax,%rax
je     11f7 <path_make_absolute_cwd+0x87>
mov    %rax,%r14
mov    %r13,%rdi
add    $0x1,%rdi
add    $0x1,%r15
movb   $0x2f,(%rax,%r13,1)
add    %rax,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
jmp    1202 <path_make_absolute_cwd+0x92>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @path_make_absolute_cwd(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @path_is_absolute(i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %2
br label %49
14: ; preds = %1
%15 = call i8* (...) @get_current_dir_name()
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %14
store i8* null, i8** %2
br label %49
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = call i64 @strlen(i8* %20)
store i64 %21, i64* %6
%22 = load i8*, i8** %4
%23 = call i64 @strlen(i8* %22)
store i64 %23, i64* %7
%24 = load i8*, i8** %4
%25 = load i64, i64* %7
%26 = add i64 %25, 1
%27 = load i64, i64* %6
%28 = add i64 %26, %27
%29 = add i64 %28, 1
%30 = call i8* @realloc(i8* %24, i64 %29)
store i8* %30, i8** %5
%31 = load i8*, i8** %5
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %36
33: ; preds = %19
%34 = load i8*, i8** %4
%35 = call i32 @free(i8* %34)
store i8* null, i8** %2
br label %49
36: ; preds = %19
%37 = load i8*, i8** %5
%38 = load i64, i64* %7
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8 47, i8* %39
%40 = load i8*, i8** %5
%41 = load i64, i64* %7
%42 = add i64 %41, 1
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8*, i8** %3
%45 = load i64, i64* %6
%46 = add i64 %45, 1
%47 = call i32 @memcpy(i8* %43, i8* %44, i64 %46)
%48 = load i8*, i8** %5
store i8* %48, i8** %2
br label %49
49: ; preds = %36, %33, %18, %11
%50 = load i8*, i8** %2
ret i8* %50
}

LLVM IR (-O2):
define i8* @path_make_absolute_cwd(i8* %0) {
%2 = tail call i64 @path_is_absolute(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i8* @strdup(i8* %0)
br label %23
6: ; preds = %1
%7 = tail call i8* (...) @get_current_dir_name()
%8 = icmp eq i8* %7, null
br i1 %8, label %23, label %9
9: ; preds = %6
%10 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%11 = tail call i64 @strlen(i8* %7)
%12 = add i64 %11, 1
%13 = add i64 %10, 1
%14 = add i64 %13, %12
%15 = tail call i8* @realloc(i8* %7, i64 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = tail call i32 @free(i8* %7)
br label %23
19: ; preds = %9
%20 = getelementptr inbounds i8, i8* %15, i64 %11
store i8 47, i8* %20
%21 = getelementptr inbounds i8, i8* %15, i64 %12
%22 = tail call i32 @memcpy(i8* %21, i8* %0, i64 %13)
br label %23
23: ; preds = %6, %19, %17, %4
%24 = phi i8* [ %5, %4 ], [ null, %17 ], [ %15, %19 ], [ null, %6 ]
ret i8* %24
}