#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 */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int readlink(char const *const, char *const, size_t const);
char *xrealpath(char const *const);
bool xlstat(const char *const path, char *const t, const size_t tlen,
            const char **const err_msg, char **const err_path) {
  assert(path != NULL);
  assert(t != NULL);
  assert(tlen > 0);
  assert(err_msg != NULL);
  assert(err_path != NULL);
  ssize_t llen = 0;
  if ((llen = readlink(path, t, tlen)) == -1) {
    *err_msg = "Cannot read link target";
    *err_path = xrealpath(path);
    return false;
  }
  assert(llen >= 0);
  if ((size_t)llen != tlen) {
    *err_msg = "Link target length does not match buffer length";
    *err_path = xrealpath(path);
    return false;
  }
  *(t + tlen + 1) = '\0';
  return true;
}


x86 assembly (clang, -O0):
<xlstat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x28(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x30(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <readlink@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
jne    11f7 <xlstat+0xc7>
mov    -0x28(%rbp),%rax
lea    0xe2b(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <xrealpath@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1257 <xlstat+0x127>
cmpl   $0x0,-0x34(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movslq -0x34(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1243 <xlstat+0x113>
mov    -0x28(%rbp),%rax
lea    0xdf7(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <xrealpath@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1257 <xlstat+0x127>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,0x1(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xlstat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r13
mov    %rdi,%r12
xor    %edi,%edi
test   %r12,%r12
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %r13,%r13
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1050 <assert@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1040 <readlink@plt>
cmp    $0xffffffff,%eax
je     11c6 <xlstat+0x96>
mov    %eax,%ebp
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1050 <assert@plt>
movslq %ebp,%rax
cmp    %rbx,%rax
jne    11cf <xlstat+0x9f>
movb   $0x0,0x1(%r13,%rbx,1)
mov    $0x1,%eax
jmp    11e6 <xlstat+0xb6>
lea    0xe33(%rip),%rax
jmp    11d6 <xlstat+0xa6>
lea    0xe42(%rip),%rax
mov    %rax,(%r15)
mov    %r12,%rdi
call   1030 <xrealpath@plt>
mov    %rax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Cannot read link target\00"
@.str.1 = [48 x i8] c"Link target length does not match buffer length\00"
define i32 @xlstat(i8* %0, i8* %1, i64 %2, i8** %3, i8** %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8**
%11 = alloca i8**
%12 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i8** %3, i8*** %10
store i8** %4, i8*** %11
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8*, i8** %8
%18 = icmp ne i8* %17, null
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i64, i64* %9
%22 = icmp ugt i64 %21, 0
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i8**, i8*** %10
%26 = icmp ne i8** %25, null
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i8**, i8*** %11
%30 = icmp ne i8** %29, null
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
store i32 0, i32* %12
%33 = load i8*, i8** %7
%34 = load i8*, i8** %8
%35 = load i64, i64* %9
%36 = call i32 @readlink(i8* %33, i8* %34, i64 %35)
store i32 %36, i32* %12
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %43
38: ; preds = %5
%39 = load i8**, i8*** %10
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8** %39
%40 = load i8*, i8** %7
%41 = call i8* @xrealpath(i8* %40)
%42 = load i8**, i8*** %11
store i8* %41, i8** %42
store i32 0, i32* %6
br label %62
43: ; preds = %5
%44 = load i32, i32* %12
%45 = icmp sge i32 %44, 0
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = load i32, i32* %12
%49 = sext i32 %48 to i64
%50 = load i64, i64* %9
%51 = icmp ne i64 %49, %50
br i1 %51, label %52, label %57
52: ; preds = %43
%53 = load i8**, i8*** %10
store i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8** %53
%54 = load i8*, i8** %7
%55 = call i8* @xrealpath(i8* %54)
%56 = load i8**, i8*** %11
store i8* %55, i8** %56
store i32 0, i32* %6
br label %62
57: ; preds = %43
%58 = load i8*, i8** %8
%59 = load i64, i64* %9
%60 = getelementptr inbounds i8, i8* %58, i64 %59
%61 = getelementptr inbounds i8, i8* %60, i64 1
store i8 0, i8* %61
store i32 1, i32* %6
br label %62
62: ; preds = %57, %52, %38
%63 = load i32, i32* %6
ret i32 %63
}

LLVM IR (-O2):
@.str = [24 x i8] c"Cannot read link target\00"
@.str.1 = [48 x i8] c"Link target length does not match buffer length\00"
define i32 @xlstat(i8* %0, i8* %1, i64 %2, i8** writeonly %3, i8** writeonly %4) {
%6 = icmp ne i8* %0, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp ne i8* %1, null
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = icmp ne i64 %2, 0
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = icmp ne i8** %3, null
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = icmp ne i8** %4, null
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = tail call i32 @readlink(i8* %0, i8* %1, i64 %2)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %5
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8** %3
%24 = tail call i8* @xrealpath(i8* %0)
store i8* %24, i8** %4
br label %36
25: ; preds = %5
%26 = xor i32 %21, -1
%27 = lshr i32 %26, 31
%28 = tail call i32 @assert(i32 %27)
%29 = sext i32 %21 to i64
%30 = icmp eq i64 %29, %2
br i1 %30, label %33, label %31
31: ; preds = %25
store i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8** %3
%32 = tail call i8* @xrealpath(i8* %0)
store i8* %32, i8** %4
br label %36
33: ; preds = %25
%34 = getelementptr inbounds i8, i8* %1, i64 %2
%35 = getelementptr inbounds i8, i8* %34, i64 1
store i8 0, i8* %35
br label %36
36: ; preds = %33, %31, %23
%37 = phi i32 [ 0, %23 ], [ 0, %31 ], [ 1, %33 ]
ret i32 %37
}