#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 */
struct stat {
  int /*<<< orphan*/ st_ino;
};
typedef int /*<<< orphan*/ ino_t;

/* Variables and functions */
int PATH_MAX;
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ realpath(char const *, char *);
ino_t symlnkpath(const char *path, const char *parentpath) {
  char rlpath[PATH_MAX];
  struct stat estat;
  if (!realpath(path, rlpath)) {
    goto sys_error;
  }
  if (lstat(rlpath, &estat) == 0) {
    return estat.st_ino;
  }
sys_error:
  return 0;
}


x86 assembly (clang, -O0):
<symlnkpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2eb9(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%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,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <realpath@plt>
cmp    $0x0,%eax
jne    1173 <symlnkpath+0x53>
jmp    11a1 <symlnkpath+0x81>
mov    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <lstat@plt>
cmp    $0x0,%rax
jne    119c <symlnkpath+0x7c>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    11af <symlnkpath+0x8f>
jmp    11a1 <symlnkpath+0x81>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<symlnkpath>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ebe(%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>
xor    %r14d,%r14d
test   %eax,%eax
je     1169 <symlnkpath+0x49>
lea    -0x18(%rbp),%rsi
mov    %rbx,%rdi
call   1030 <lstat@plt>
test   %rax,%rax
jne    1169 <symlnkpath+0x49>
mov    -0x18(%rbp),%r14d
mov    %r14d,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
define i32 @symlnkpath(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.stat
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8, i64 %11
store i64 %11, i64* %7
%14 = load i8*, i8** %4
%15 = call i32 @realpath(i8* %14, i8* %13)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %2
br label %25
18: ; preds = %2
%19 = call i64 @lstat(i8* %13, %struct.stat* %8)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%23 = load i32, i32* %22
store i32 %23, i32* %3
store i32 1, i32* %9
br label %26
24: ; preds = %18
br label %25
25: ; preds = %24, %17
store i32 0, i32* %3
store i32 1, i32* %9
br label %26
26: ; preds = %25, %21
%27 = load i8*, i8** %6
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
define i32 @symlnkpath(i8* nocapture %0, i8* nocapture readnone %1) {
%3 = alloca %struct.stat
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast %struct.stat* %3 to i8*
%8 = call i32 @realpath(i8* %0, i8* %6)
%9 = icmp eq i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = call i64 @lstat(i8* %6, %struct.stat* %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%15 = load i32, i32* %14
br label %16
16: ; preds = %2, %10, %13
%17 = phi i32 [ %15, %13 ], [ 0, %10 ], [ 0, %2 ]
ret i32 %17
}