#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 PATH_MAX;
int /*<<< orphan*/ asprintf(char **, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ perror(char *);
char *realpath(char *, char *);
char *strdup(char *);
char *file_get_path(char *path) {
  char resolved_path[PATH_MAX];
  char *result;
  char *err_string;
  result = realpath(path, resolved_path);
  if (result == NULL) {
    asprintf(&err_string, "Unable to get realpath '%s'", path);
    perror(err_string);
    free(err_string);
    return NULL;
  }
  return strdup(resolved_path);
}


x86 assembly (clang, -O0):
<file_get_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x40(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <realpath@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11da <file_get_path+0x8a>
mov    -0x10(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1050 <asprintf@plt>
mov    -0x30(%rbp),%rdi
call   1060 <perror@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    11ee <file_get_path+0x9e>
mov    -0x40(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_get_path>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rsi
call   1040 <realpath@plt>
test   %rax,%rax
je     1196 <file_get_path+0x46>
mov    %rbx,%rdi
call   1070 <strdup@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe63(%rip),%rsi
lea    -0x18(%rbp),%rdi
mov    %r14,%rdx
call   1050 <asprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    118d <file_get_path+0x3d>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [28 x i8] c"Unable to get realpath '%s'\00"
define i8* @file_get_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
%13 = load i8*, i8** %3
%14 = call i8* @realpath(i8* %13, i8* %12)
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %24
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = call i32 @asprintf(i8** %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %7
%21 = call i32 @perror(i8* %20)
%22 = load i8*, i8** %7
%23 = call i32 @free(i8* %22)
store i8* null, i8** %2
store i32 1, i32* %8
br label %26
24: ; preds = %1
%25 = call i8* @strdup(i8* %12)
store i8* %25, i8** %2
store i32 1, i32* %8
br label %26
26: ; preds = %24, %17
%27 = load i8*, i8** %4
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [28 x i8] c"Unable to get realpath '%s'\00"
define noalias i8* @file_get_path(i8* %0) {
%2 = alloca i8*
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = bitcast i8** %2 to i8*
%7 = call i8* @realpath(i8* %0, i8* %5)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = load i8*, i8** %2
%12 = call i32 @perror(i8* %11)
%13 = load i8*, i8** %2
%14 = call i32 @free(i8* %13)
br label %17
15: ; preds = %1
%16 = call i8* @strdup(i8* %5)
br label %17
17: ; preds = %15, %9
%18 = phi i8* [ null, %9 ], [ %16, %15 ]
ret i8* %18
}