long RB_VerifyLinkReference(void *pbUserData, unsigned short *pLinkName,
                            unsigned short *pReferenceFileName) {
  int ret = 0;
  char path[1024] = {'\0'};
  char linkedpath[1024] = {'\0'};
  char refPath[1024] = {'\0'};
  printf("%s \n", __func__);
  unicode_to_char(pLinkName, path);
  unicode_to_char(pReferenceFileName, refPath);
  ret = readlink(path, linkedpath, 1024);
  if (ret < 0) {
    printf(" readlink failed with return value: %d\n", ret);
    return (long)(((unsigned long)((1)) << 31) | (0));
  }
  if ((memcmp(&linkedpath, &refPath, ret)) != 0) {
    printf(" not same linked path - linkedpath[%s] pReferenceFileName[%s]\n",
           linkedpath, refPath);
    return (long)(((unsigned long)((1)) << 31) | (0));
  }
  printf(" same linked path\n");
  return (long)(((unsigned long)((0)) << 31) | (0));
}


x86 assembly (clang, -O0):
<RB_VerifyLinkReference>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x830(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0xc30(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    0xe52(%rip),%rdi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    $0x0,%al
call   1040 <unicode_to_char@plt>
mov    -0x20(%rbp),%rdi
lea    -0xc30(%rbp),%rsi
mov    $0x0,%al
call   1040 <unicode_to_char@plt>
lea    -0x430(%rbp),%rdi
lea    -0x830(%rbp),%rsi
mov    $0x400,%edx
mov    $0x0,%al
call   1030 <readlink@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1226 <RB_VerifyLinkReference+0xd6>
mov    -0x24(%rbp),%esi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x80000000,%eax
mov    %rax,-0x8(%rbp)
jmp    1286 <RB_VerifyLinkReference+0x136>
lea    -0x830(%rbp),%rdi
lea    -0xc30(%rbp),%rsi
movslq -0x24(%rbp),%rdx
call   1070 <memcmp@plt>
cmp    $0x0,%eax
je     1270 <RB_VerifyLinkReference+0x120>
lea    -0x830(%rbp),%rsi
lea    -0xc30(%rbp),%rdx
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x80000000,%eax
mov    %rax,-0x8(%rbp)
jmp    1286 <RB_VerifyLinkReference+0x136>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RB_VerifyLinkReference>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc00,%rsp
mov    %rdx,%r12
mov    %rsi,%rbx
lea    0x800(%rsp),%r14
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
lea    0x400(%rsp),%r15
mov    $0x400,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %rsp,%r13
mov    $0x400,%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
lea    0xe43(%rip),%rdi
lea    0xe41(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <unicode_to_char@plt>
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <unicode_to_char@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x400,%edx
xor    %eax,%eax
call   1040 <readlink@plt>
test   %eax,%eax
js     1231 <RB_VerifyLinkReference+0xd1>
mov    %eax,%edx
lea    0x400(%rsp),%rdi
mov    %rsp,%rsi
call   1080 <bcmp@plt>
test   %eax,%eax
je     1248 <RB_VerifyLinkReference+0xe8>
mov    $0x80000000,%ebx
lea    0xe27(%rip),%rdi
lea    0x400(%rsp),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1256 <RB_VerifyLinkReference+0xf6>
mov    $0x80000000,%ebx
lea    0xddf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1256 <RB_VerifyLinkReference+0xf6>
lea    0xe34(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0xc00,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s \0A\00"
@__func__.RB_VerifyLinkReference = [23 x i8] c"RB_VerifyLinkReference\00"
@.str.1 = [40 x i8] c" readlink failed with return value: %d\0A\00"
@.str.2 = [63 x i8] c" not same linked path - linkedpath[%s] pReferenceFileName[%s]\0A\00"
@.str.3 = [19 x i8] c" same linked path\0A\00"
define i64 @RB_VerifyLinkReference(i8* %0, i16* %1, i16* %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i16*
%7 = alloca i16*
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
%11 = alloca [1024 x i8]
store i8* %0, i8** %5
store i16* %1, i16** %6
store i16* %2, i16** %7
store i32 0, i32* %8
%12 = bitcast [1024 x i8]* %9 to i8*
%13 = bitcast [1024 x i8]* %10 to i8*
%14 = bitcast [1024 x i8]* %11 to i8*
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @__func__.RB_VerifyLinkReference, i64 0, i64 0))
%16 = load i16*, i16** %6
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%18 = call i32 (i16*, i8*, ...) bitcast (i32 (...)* @unicode_to_char to i32 (i16*, i8*, ...)*)(i16* %16, i8* %17)
%19 = load i16*, i16** %7
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%21 = call i32 (i16*, i8*, ...) bitcast (i32 (...)* @unicode_to_char to i32 (i16*, i8*, ...)*)(i16* %19, i8* %20)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%24 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @readlink to i32 (i8*, i8*, i32, ...)*)(i8* %22, i8* %23, i32 1024)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %3
%28 = load i32, i32* %8
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %28)
store i64 2147483648, i64* %4
br label %43
30: ; preds = %3
%31 = bitcast [1024 x i8]* %10 to i8*
%32 = bitcast [1024 x i8]* %11 to i8*
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = call i32 @memcmp(i8* %31, i8* %32, i64 %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %30
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0), i8* %38, i8* %39)
store i64 2147483648, i64* %4
br label %43
41: ; preds = %30
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i64 0, i64* %4
br label %43
43: ; preds = %41, %37, %27
%44 = load i64, i64* %4
ret i64 %44
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s \0A\00"
@__func__.RB_VerifyLinkReference = [23 x i8] c"RB_VerifyLinkReference\00"
@.str.1 = [40 x i8] c" readlink failed with return value: %d\0A\00"
@.str.2 = [63 x i8] c" not same linked path - linkedpath[%s] pReferenceFileName[%s]\0A\00"
@str = [18 x i8] c" same linked path\00"
define i64 @RB_VerifyLinkReference(i8* nocapture readnone %0, i16* %1, i16* %2) {
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @__func__.RB_VerifyLinkReference, i64 0, i64 0))
%11 = call i32 (i16*, i8*, ...) bitcast (i32 (...)* @unicode_to_char to i32 (i16*, i8*, ...)*)(i16* %1, i8* %7)
%12 = call i32 (i16*, i8*, ...) bitcast (i32 (...)* @unicode_to_char to i32 (i16*, i8*, ...)*)(i16* %2, i8* %9)
%13 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @readlink to i32 (i8*, i8*, i32, ...)*)(i8* %7, i8* %8, i32 1024)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %25
17: ; preds = %3
%18 = zext i32 %13 to i64
%19 = call i32 @bcmp(i8* %8, i8* %9, i64 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %9)
br label %25
23: ; preds = %17
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %25
25: ; preds = %23, %21, %15
%26 = phi i64 [ 2147483648, %15 ], [ 2147483648, %21 ], [ 0, %23 ]
ret i64 %26
}