#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 EINVAL;
int /*<<< orphan*/ assert(int);
int errno;
char *realpath(char const *const, int /*<<< orphan*/ *);
char *strdup(char const *const);
char *xrealpath(const char *const path) {
  assert(path != NULL);
  char *rp = NULL;
  int _errno = errno;
  if ((rp = realpath(path, NULL)) == NULL) {
    assert(errno != EINVAL);
    rp = strdup(path);
  }
  errno = _errno;
  return (rp);
}


x86 assembly (clang, -O0):
<xrealpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movq   $0x0,-0x10(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <realpath@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a9 <xrealpath+0x79>
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%ecx
mov    0x2e2d(%rip),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrealpath>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
mov    0x2e94(%rip),%r14
mov    (%r14),%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <realpath@plt>
test   %rax,%rax
jne    117d <xrealpath+0x4d>
mov    (%r14),%eax
mov    0x2e70(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%eax
setne  %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
call   1050 <strdup@plt>
mov    %ebp,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@EINVAL = global i32 0
define i8* @xrealpath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
store i8* null, i8** %3
%9 = load i32, i32* @errno
store i32 %9, i32* %4
%10 = load i8*, i8** %2
%11 = call i8* @realpath(i8* %10, i32* null)
store i8* %11, i8** %3
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %21
13: ; preds = %1
%14 = load i32, i32* @errno
%15 = load i32, i32* @EINVAL
%16 = icmp ne i32 %14, %15
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i8*, i8** %2
%20 = call i8* @strdup(i8* %19)
store i8* %20, i8** %3
br label %21
21: ; preds = %13, %1
%22 = load i32, i32* %4
store i32 %22, i32* @errno
%23 = load i8*, i8** %3
ret i8* %23
}

LLVM IR (-O2):
@errno = global i32 0
@EINVAL = global i32 0
define i8* @xrealpath(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = load i32, i32* @errno
%6 = tail call i8* @realpath(i8* %0, i32* null)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = load i32, i32* @EINVAL
%11 = icmp ne i32 %9, %10
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i8* @strdup(i8* %0)
br label %15
15: ; preds = %8, %1
%16 = phi i8* [ %14, %8 ], [ %6, %1 ]
store i32 %5, i32* @errno
ret i8* %16
}