#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 */
struct dirent {
  int /*<<< orphan*/ d_name;
};

/* Variables and functions */
scalar_t__ asprintf(char **, char *, char const *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
char *realpath(char *, int /*<<< orphan*/ *);
char *create_full_path(const char *dir_path, struct dirent *entry) {
  char *path = NULL;
  char *absolute_path = NULL;
  if (entry) {
    if (asprintf(&path, "%s/%s", dir_path, entry->d_name) < 0) {
      return NULL;
    }
  }
  absolute_path = realpath(path ? path : dir_path, NULL);
  errno = 0;
  if (path) {
    free(path);
  }
  return absolute_path;
}


x86 assembly (clang, -O0):
<create_full_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1191 <create_full_path+0x61>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
lea    -0x20(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1050 <asprintf@plt>
cmp    $0x0,%rax
jge    118c <create_full_path+0x5c>
movq   $0x0,-0x8(%rbp)
jmp    11ec <create_full_path+0xbc>
jmp    1191 <create_full_path+0x61>
cmpq   $0x0,-0x20(%rbp)
je     11a9 <create_full_path+0x79>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11b1 <create_full_path+0x81>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <realpath@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e17(%rip),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     11e4 <create_full_path+0xb4>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_full_path>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
test   %rsi,%rsi
je     1168 <create_full_path+0x38>
mov    (%rsi),%ecx
lea    0xeb1(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rbx,%rdx
call   1050 <asprintf@plt>
test   %rax,%rax
js     119d <create_full_path+0x6d>
mov    0x8(%rsp),%rax
jmp    116a <create_full_path+0x3a>
xor    %eax,%eax
test   %rax,%rax
cmovne %rax,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <realpath@plt>
mov    %rax,%rbx
mov    0x2e5b(%rip),%rax
movq   $0x0,(%rax)
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     119f <create_full_path+0x6f>
call   1030 <free@plt>
jmp    119f <create_full_path+0x6f>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [6 x i8] c"%s/%s\00"
@errno = global i64 0
define i8* @create_full_path(i8* %0, %struct.dirent* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.dirent*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store %struct.dirent* %1, %struct.dirent** %5
store i8* null, i8** %6
store i8* null, i8** %7
%8 = load %struct.dirent*, %struct.dirent** %5
%9 = icmp ne %struct.dirent* %8, null
br i1 %9, label %10, label %19
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load %struct.dirent*, %struct.dirent** %5
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @asprintf(i8** %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %10
store i8* null, i8** %3
br label %36
18: ; preds = %10
br label %19
19: ; preds = %18, %2
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load i8*, i8** %6
br label %26
24: ; preds = %19
%25 = load i8*, i8** %4
br label %26
26: ; preds = %24, %22
%27 = phi i8* [ %23, %22 ], [ %25, %24 ]
%28 = call i8* @realpath(i8* %27, i32* null)
store i8* %28, i8** %7
store i64 0, i64* @errno
%29 = load i8*, i8** %6
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i8*, i8** %6
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %31, %26
%35 = load i8*, i8** %7
store i8* %35, i8** %3
br label %36
36: ; preds = %34, %17
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [6 x i8] c"%s/%s\00"
@errno = global i64 0
define i8* @create_full_path(i8* %0, %struct.dirent* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = icmp eq %struct.dirent* %1, null
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = getelementptr inbounds %struct.dirent, %struct.dirent* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = call i64 @asprintf(i8** %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %6
%12 = load i8*, i8** %3
br label %13
13: ; preds = %11, %2
%14 = phi i8* [ %12, %11 ], [ null, %2 ]
%15 = icmp eq i8* %14, null
%16 = select i1 %15, i8* %0, i8* %14
%17 = call i8* @realpath(i8* %16, i32* null)
store i64 0, i64* @errno
%18 = load i8*, i8** %3
%19 = icmp eq i8* %18, null
br i1 %19, label %22, label %20
20: ; preds = %13
%21 = call i32 @free(i8* %18)
br label %22
22: ; preds = %13, %20, %6
%23 = phi i8* [ null, %6 ], [ %17, %20 ], [ %17, %13 ]
ret i8* %23
}