#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 {
  scalar_t__ st_size;
};

/* Variables and functions */
scalar_t__ UINT_MAX;
int /*<<< orphan*/ assert(int);
int lstat(char const *const, struct stat *);
char *xrealpath(char const *const);
bool xlstatlen(const char *const path, size_t *const target_len,
               const char **const err_msg, char **const err_path) {
  assert(path != NULL);
  assert(target_len != NULL);
  assert(err_msg != NULL);
  assert(err_path != NULL);
  struct stat st;
  if (lstat(path, &st) == -1) {
    *err_msg = "Cannot stat link";
    *err_path = xrealpath(path);
    return false;
  }
  assert(st.st_size >= 0);
  assert(st.st_size <= UINT_MAX);
  *target_len = (size_t)st.st_size;
  return true;
}


x86 assembly (clang, -O0):
<xlstatlen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%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)
setne  %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>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <lstat@plt>
cmp    $0xffffffff,%eax
jne    11d3 <xlstatlen+0xa3>
mov    -0x20(%rbp),%rax
lea    0xe4f(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <xrealpath@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1212 <xlstatlen+0xe2>
cmpq   $0x0,-0x30(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x30(%rbp),%rax
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%rax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xlstatlen>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %r12,%r12
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1050 <assert@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <lstat@plt>
cmp    $0xffffffff,%eax
je     11be <xlstatlen+0x8e>
mov    (%rsp),%rbx
mov    %rbx,%rdi
shr    $0x3f,%rdi
xor    $0x1,%edi
call   1050 <assert@plt>
mov    0x2e42(%rip),%rax
xor    %edi,%edi
cmp    (%rax),%rbx
setle  %dil
call   1050 <assert@plt>
mov    %rbx,(%r14)
mov    $0x1,%eax
jmp    11d6 <xlstatlen+0xa6>
lea    0xe3b(%rip),%rax
mov    %rax,(%r12)
mov    %rbx,%rdi
call   1030 <xrealpath@plt>
mov    %rax,(%r15)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [17 x i8] c"Cannot stat link\00"
@UINT_MAX = global i64 0
define i32 @xlstatlen(i8* %0, i64* %1, i8** %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca %struct.stat
store i8* %0, i8** %6
store i64* %1, i64** %7
store i8** %2, i8*** %8
store i8** %3, i8*** %9
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i64*, i64** %7
%16 = icmp ne i64* %15, null
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i8**, i8*** %8
%20 = icmp ne i8** %19, null
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i8**, i8*** %9
%24 = icmp ne i8** %23, null
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i8*, i8** %6
%28 = call i32 @lstat(i8* %27, %struct.stat* %10)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %35
30: ; preds = %4
%31 = load i8**, i8*** %8
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %31
%32 = load i8*, i8** %6
%33 = call i8* @xrealpath(i8* %32)
%34 = load i8**, i8*** %9
store i8* %33, i8** %34
store i32 0, i32* %5
br label %50
35: ; preds = %4
%36 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%37 = load i64, i64* %36
%38 = icmp sge i64 %37, 0
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%42 = load i64, i64* %41
%43 = load i64, i64* @UINT_MAX
%44 = icmp sle i64 %42, %43
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%48 = load i64, i64* %47
%49 = load i64*, i64** %7
store i64 %48, i64* %49
store i32 1, i32* %5
br label %50
50: ; preds = %35, %30
%51 = load i32, i32* %5
ret i32 %51
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [17 x i8] c"Cannot stat link\00"
@UINT_MAX = global i64 0
define i32 @xlstatlen(i8* %0, i64* writeonly %1, i8** writeonly %2, i8** writeonly %3) {
%5 = alloca %struct.stat
%6 = icmp ne i8* %0, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp ne i64* %1, null
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = icmp ne i8** %2, null
%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 = bitcast %struct.stat* %5 to i8*
%19 = call i32 @lstat(i8* %0, %struct.stat* %5)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %4
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %2
%22 = tail call i8* @xrealpath(i8* %0)
store i8* %22, i8** %3
br label %34
23: ; preds = %4
%24 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%25 = load i64, i64* %24
%26 = lshr i64 %25, 63
%27 = trunc i64 %26 to i32
%28 = xor i32 %27, 1
%29 = tail call i32 @assert(i32 %28)
%30 = load i64, i64* @UINT_MAX
%31 = icmp sle i64 %25, %30
%32 = zext i1 %31 to i32
%33 = tail call i32 @assert(i32 %32)
store i64 %25, i64* %1
br label %34
34: ; preds = %23, %21
%35 = phi i32 [ 0, %21 ], [ 1, %23 ]
ret i32 %35
}