#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  char **we_wordv;
};
typedef TYPE_1__ wordexp_t;

/* Variables and functions */
char *appendCwd(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
char *realpath(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ wordexp(char *, TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ wordfree(TYPE_1__ *);
char *abspath(char *file_name) {
  char *path;
  wordexp_t p;
  if (wordexp(file_name, &p, 0) == 0) {
    path = appendCwd(p.we_wordv[0]);
    wordfree(&p);
  } else {
    path = appendCwd(file_name);
  }
  char *resolved = realpath(path, NULL);
  if (!resolved) {
    perror(0);
    fprintf(stderr, "unable to canonicalize %s\n", file_name);
  }
  return resolved;
}


x86 assembly (clang, -O0):
<abspath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1080 <wordexp@plt>
cmp    $0x0,%rax
jne    11a3 <abspath+0x43>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <appendCwd@plt>
mov    %rax,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <wordfree@plt>
jmp    11b0 <abspath+0x50>
mov    -0x8(%rbp),%rdi
call   1030 <appendCwd@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <realpath@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ec <abspath+0x8c>
xor    %edi,%edi
call   1060 <perror@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe19(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abspath>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsp,%rsi
xor    %edx,%edx
call   1080 <wordexp@plt>
test   %rax,%rax
je     1183 <abspath+0x23>
mov    %r14,%rdi
call   1030 <appendCwd@plt>
mov    %rax,%rbx
jmp    119a <abspath+0x3a>
mov    (%rsp),%rax
mov    (%rax),%rdi
call   1030 <appendCwd@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
call   1070 <wordfree@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <realpath@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11cb <abspath+0x6b>
xor    %edi,%edi
call   1060 <perror@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i8** }
@stderr = global i32 0
@.str = [27 x i8] c"unable to canonicalize %s\0A\00"
define i8* @abspath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.TYPE_4__
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @wordexp(i8* %6, %struct.TYPE_4__* %4, i32 0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %4, i32 0, i32 0
%11 = load i8**, i8*** %10
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i8* @appendCwd(i8* %13)
store i8* %14, i8** %3
%15 = call i32 @wordfree(%struct.TYPE_4__* %4)
br label %19
16: ; preds = %1
%17 = load i8*, i8** %2
%18 = call i8* @appendCwd(i8* %17)
store i8* %18, i8** %3
br label %19
19: ; preds = %16, %9
%20 = load i8*, i8** %3
%21 = call i8* @realpath(i8* %20, i32* null)
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = icmp ne i8* %22, null
br i1 %23, label %29, label %24
24: ; preds = %19
%25 = call i32 @perror(i32 0)
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %2
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %24, %19
%30 = load i8*, i8** %5
ret i8* %30
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i8** }
@stderr = global i32 0
@.str = [27 x i8] c"unable to canonicalize %s\0A\00"
define i8* @abspath(i8* %0) {
%2 = alloca %struct.TYPE_4__
%3 = bitcast %struct.TYPE_4__* %2 to i8*
%4 = call i64 @wordexp(i8* %0, %struct.TYPE_4__* %2, i32 0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %1
%7 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%8 = load i8**, i8*** %7
%9 = load i8*, i8** %8
%10 = call i8* @appendCwd(i8* %9)
%11 = call i32 @wordfree(%struct.TYPE_4__* %2)
br label %14
12: ; preds = %1
%13 = call i8* @appendCwd(i8* %0)
br label %14
14: ; preds = %12, %6
%15 = phi i8* [ %10, %6 ], [ %13, %12 ]
%16 = call i8* @realpath(i8* %15, i32* null)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = call i32 @perror(i32 0)
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %22
22: ; preds = %18, %14
ret i8* %16
}