#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 *EINVAL;
int /*<<< orphan*/ Error_write(int, char *, int, char *, char *, ...);
int MAXPATHLEN;
scalar_t__ chdir(char *);
char *errno;
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ *realpath(char *, char *);
int FileUtil_getRealPath(char *FNIn, char *Path) {
  char CurDir[MAXPATHLEN];
  if (getcwd(CurDir, MAXPATHLEN) == NULL) {
    Error_write(307, "FileUtil_getRealPath", 2, "errno = %d\n", errno);
    return 0;
  }
  if (errno) {
    Error_write(307, "FileUtil_getRealPath", 2, "errno = %d\n", errno);
    return 0;
  }
  if (realpath(FNIn, Path) == NULL) {
    Error_write(308, "FileUtil_getRealPath", 2,
                "realpath returned NULL. File = %s Path = %s.\n", FNIn, Path);
  }
  if (errno && errno != EINVAL) {
    Error_write(308, "FileUtil_getRealPath", 2,
                "File = %s Path = %s. errno = %d\n", FNIn, Path, errno);
    return 0;
  }
  if (chdir(CurDir)) {
    Error_write(309, "FileUtil_getRealPath", 2, "CurDir = %s. errno = %d\n",
                CurDir, errno);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<FileUtil_getRealPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
call   1050 <getcwd@plt>
cmp    $0x0,%rax
jne    11d0 <FileUtil_getRealPath+0x90>
mov    0x2e3d(%rip),%rax
mov    (%rax),%r8
mov    $0x133,%edi
lea    0xe56(%rip),%rsi
mov    $0x2,%edx
lea    0xea2(%rip),%rcx
mov    $0x0,%al
call   1040 <Error_write@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1337 <FileUtil_getRealPath+0x1f7>
mov    0x2e01(%rip),%rax
cmpq   $0x0,(%rax)
je     121d <FileUtil_getRealPath+0xdd>
mov    0x2df0(%rip),%rax
mov    (%rax),%r8
mov    $0x133,%edi
lea    0xe09(%rip),%rsi
mov    $0x2,%edx
lea    0xe55(%rip),%rcx
mov    $0x0,%al
call   1040 <Error_write@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1337 <FileUtil_getRealPath+0x1f7>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <realpath@plt>
cmp    $0x0,%rax
jne    125b <FileUtil_getRealPath+0x11b>
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    $0x134,%edi
lea    0xdb8(%rip),%rsi
mov    $0x2,%edx
lea    0xdc1(%rip),%rcx
mov    $0x0,%al
call   1040 <Error_write@plt>
mov    0x2d76(%rip),%rax
cmpq   $0x0,(%rax)
je     12d6 <FileUtil_getRealPath+0x196>
mov    0x2d65(%rip),%rax
mov    (%rax),%rax
mov    0x2d53(%rip),%rcx
cmp    (%rcx),%rax
je     12d6 <FileUtil_getRealPath+0x196>
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    0x2d43(%rip),%rax
mov    (%rax),%rax
mov    $0x134,%edi
lea    0xd5c(%rip),%rsi
mov    $0x2,%edx
lea    0xd93(%rip),%rcx
sub    $0x10,%rsp
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <Error_write@plt>
add    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1337 <FileUtil_getRealPath+0x1f7>
mov    -0x38(%rbp),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
je     1329 <FileUtil_getRealPath+0x1e9>
mov    -0x38(%rbp),%r8
mov    0x2ce4(%rip),%rax
mov    (%rax),%r9
mov    $0x135,%edi
lea    0xcfd(%rip),%rsi
mov    $0x2,%edx
lea    0xd55(%rip),%rcx
mov    $0x0,%al
call   1040 <Error_write@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1337 <FileUtil_getRealPath+0x1f7>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileUtil_getRealPath>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1050 <getcwd@plt>
mov    0x2e5b(%rip),%r12
mov    (%r12),%r8
test   %rax,%rax
je     118b <FileUtil_getRealPath+0x4b>
test   %r8,%r8
je     11bd <FileUtil_getRealPath+0x7d>
lea    0xe6e(%rip),%rsi
lea    0xebf(%rip),%rcx
xor    %r12d,%r12d
mov    $0x133,%edi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <Error_write@plt>
mov    %r12d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <realpath@plt>
test   %rax,%rax
jne    11f2 <FileUtil_getRealPath+0xb2>
lea    0xe2c(%rip),%rsi
lea    0xe3a(%rip),%rcx
mov    $0x134,%edi
mov    $0x2,%edx
mov    %r15,%r8
mov    %r14,%r9
xor    %eax,%eax
call   1040 <Error_write@plt>
mov    (%r12),%r10
test   %r10,%r10
je     123e <FileUtil_getRealPath+0xfe>
mov    0x2dce(%rip),%rax
cmp    (%rax),%r10
je     123e <FileUtil_getRealPath+0xfe>
sub    $0x8,%rsp
lea    0xdee(%rip),%rsi
lea    0xe2a(%rip),%rcx
xor    %r12d,%r12d
mov    $0x134,%edi
mov    $0x2,%edx
mov    %r15,%r8
mov    %r14,%r9
xor    %eax,%eax
push   %r10
call   1040 <Error_write@plt>
add    $0x10,%rsp
jmp    11ad <FileUtil_getRealPath+0x6d>
mov    %rbx,%rdi
call   1030 <chdir@plt>
test   %rax,%rax
je     1279 <FileUtil_getRealPath+0x139>
mov    (%r12),%r9
lea    0xdaa(%rip),%rsi
lea    0xe07(%rip),%rcx
xor    %r12d,%r12d
mov    $0x135,%edi
mov    $0x2,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1040 <Error_write@plt>
jmp    11ad <FileUtil_getRealPath+0x6d>
mov    $0x1,%r12d
jmp    11ad <FileUtil_getRealPath+0x6d>

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@.str = [21 x i8] c"FileUtil_getRealPath\00"
@.str.1 = [12 x i8] c"errno = %d\0A\00"
@errno = global i8* null
@.str.2 = [46 x i8] c"realpath returned NULL. File = %s Path = %s.\0A\00"
@EINVAL = global i8* null
@.str.3 = [33 x i8] c"File = %s Path = %s. errno = %d\0A\00"
@.str.4 = [25 x i8] c"CurDir = %s. errno = %d\0A\00"
define i32 @FileUtil_getRealPath(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i32, i32* @MAXPATHLEN
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i32, i32* @MAXPATHLEN
%14 = call i32* @getcwd(i8* %12, i32 %13)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i8*, i8** @errno
%18 = call i32 (i32, i8*, i32, i8*, i8*, ...) @Error_write(i32 307, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 0, i32* %3
store i32 1, i32* %8
br label %53
19: ; preds = %2
%20 = load i8*, i8** @errno
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** @errno
%24 = call i32 (i32, i8*, i32, i8*, i8*, ...) @Error_write(i32 307, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %23)
store i32 0, i32* %3
store i32 1, i32* %8
br label %53
25: ; preds = %19
%26 = load i8*, i8** %4
%27 = load i8*, i8** %5
%28 = call i32* @realpath(i8* %26, i8* %27)
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i8*, i8** %4
%32 = load i8*, i8** %5
%33 = call i32 (i32, i8*, i32, i8*, i8*, ...) @Error_write(i32 308, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %32)
br label %34
34: ; preds = %30, %25
%35 = load i8*, i8** @errno
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = load i8*, i8** @errno
%39 = load i8*, i8** @EINVAL
%40 = icmp ne i8* %38, %39
br i1 %40, label %41, label %46
41: ; preds = %37
%42 = load i8*, i8** %4
%43 = load i8*, i8** %5
%44 = load i8*, i8** @errno
%45 = call i32 (i32, i8*, i32, i8*, i8*, ...) @Error_write(i32 308, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %42, i8* %43, i8* %44)
store i32 0, i32* %3
store i32 1, i32* %8
br label %53
46: ; preds = %37, %34
%47 = call i64 @chdir(i8* %12)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i8*, i8** @errno
%51 = call i32 (i32, i8*, i32, i8*, i8*, ...) @Error_write(i32 309, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %12, i8* %50)
store i32 0, i32* %3
store i32 1, i32* %8
br label %53
52: ; preds = %46
store i32 1, i32* %3
store i32 1, i32* %8
br label %53
53: ; preds = %52, %49, %41, %22, %16
%54 = load i8*, i8** %6
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@.str = [21 x i8] c"FileUtil_getRealPath\00"
@.str.1 = [12 x i8] c"errno = %d\0A\00"
@errno = global i8* null
@.str.2 = [46 x i8] c"realpath returned NULL. File = %s Path = %s.\0A\00"
@EINVAL = global i8* null
@.str.3 = [33 x i8] c"File = %s Path = %s. errno = %d\0A\00"
@.str.4 = [25 x i8] c"CurDir = %s. errno = %d\0A\00"
define i32 @FileUtil_getRealPath(i8* %0, i8* %1) {
%3 = load i32, i32* @MAXPATHLEN
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32* @getcwd(i8* %5, i32 %3)
%7 = icmp eq i32* %6, null
%8 = load i8*, i8** @errno
br i1 %7, label %9, label %11
9: ; preds = %2
%10 = call i32 (i32, i8*, i32, i8*, i8*, ...) @Error_write(i32 307, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %34
11: ; preds = %2
%12 = icmp eq i8* %8, null
br i1 %12, label %15, label %13
13: ; preds = %11
%14 = call i32 (i32, i8*, i32, i8*, i8*, ...) @Error_write(i32 307, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %34
15: ; preds = %11
%16 = call i32* @realpath(i8* %0, i8* %1)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i32, i8*, i32, i8*, i8*, ...) @Error_write(i32 308, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1)
br label %20
20: ; preds = %18, %15
%21 = load i8*, i8** @errno
%22 = icmp eq i8* %21, null
%23 = load i8*, i8** @EINVAL
%24 = icmp eq i8* %21, %23
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = call i32 (i32, i8*, i32, i8*, i8*, ...) @Error_write(i32 308, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %1, i8* %21)
br label %34
28: ; preds = %20
%29 = call i64 @chdir(i8* %5)
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i8*, i8** @errno
%33 = call i32 (i32, i8*, i32, i8*, i8*, ...) @Error_write(i32 309, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %5, i8* %32)
br label %34
34: ; preds = %28, %31, %26, %13, %9
%35 = phi i32 [ 0, %9 ], [ 0, %13 ], [ 0, %26 ], [ 0, %31 ], [ 1, %28 ]
ret i32 %35
}