#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 *concat(int, char *, char *, int /*<<< orphan*/);
char *dirname(char *);
int /*<<< orphan*/ free(char *);
char *realpath(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ xbasename(char const *);
char *xstrdup(char const *);
char *xrealpath(const char *path) {
  char *dirc = xstrdup(path);
  char *dname = dirname(dirc);
  char *absdir = realpath(dname, NULL);
  char *abstarget = NULL;
  if (absdir)
    abstarget = concat(3, absdir, "/", xbasename(path));
  free(dirc);
  free(absdir);
  return abstarget;
}


x86 assembly (clang, -O0):
<xrealpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <xstrdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <dirname@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <realpath@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d6 <xrealpath+0x76>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <xbasename@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%ecx
mov    $0x3,%edi
lea    0xe33(%rip),%rdx
call   1060 <concat@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrealpath>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1070 <xstrdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <dirname@plt>
xor    %r12d,%r12d
mov    %rax,%rdi
xor    %esi,%esi
call   1080 <realpath@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11b1 <xrealpath+0x51>
mov    %r15,%rdi
call   1040 <xbasename@plt>
lea    0xe61(%rip),%rdx
mov    $0x3,%edi
mov    %rbx,%rsi
mov    %eax,%ecx
call   1060 <concat@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @xrealpath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @xstrdup(i8* %7)
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = call i8* @dirname(i8* %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = call i8* @realpath(i8* %11, i32* null)
store i8* %12, i8** %5
store i8* null, i8** %6
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %20
15: ; preds = %1
%16 = load i8*, i8** %5
%17 = load i8*, i8** %2
%18 = call i32 @xbasename(i8* %17)
%19 = call i8* @concat(i32 3, i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %18)
store i8* %19, i8** %6
br label %20
20: ; preds = %15, %1
%21 = load i8*, i8** %3
%22 = call i32 @free(i8* %21)
%23 = load i8*, i8** %5
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %6
ret i8* %25
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @xrealpath(i8* %0) {
%2 = tail call i8* @xstrdup(i8* %0)
%3 = tail call i8* @dirname(i8* %2)
%4 = tail call i8* @realpath(i8* %3, i32* null)
%5 = icmp eq i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = tail call i32 @xbasename(i8* %0)
%8 = tail call i8* @concat(i32 3, i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %6, %1
%10 = phi i8* [ %8, %6 ], [ null, %1 ]
%11 = tail call i32 @free(i8* %2)
%12 = tail call i32 @free(i8* %4)
ret i8* %10
}