#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 */
scalar_t__ EFAULT;
int /*<<< orphan*/ abort();
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int readlink(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  if (readlink("/proc/42/exe", NULL, 4096) != -1 || errno != EFAULT)
    abort();
  printf("pass\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x1000,%edx
call   1040 <readlink@plt>
cmp    $0xffffffff,%eax
jne    118e <main+0x4e>
mov    0x2e5d(%rip),%rax
mov    (%rax),%rax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%rax
je     1195 <main+0x55>
mov    $0x0,%al
call   1030 <abort@plt>
lea    0xe71(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xeb8(%rip),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <readlink@plt>
cmp    $0xffffffff,%eax
jne    1182 <main+0x42>
mov    0x2e78(%rip),%rax
mov    (%rax),%rax
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%rax
jne    1182 <main+0x42>
lea    0xe97(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/42/exe\00"
@errno = global i64 0
@EFAULT = global i64 0
@.str.1 = [6 x i8] c"pass\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i32 @readlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* null, i32 4096)
%7 = icmp ne i32 %6, -1
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i64, i64* @errno
%10 = load i64, i64* @EFAULT
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %8, %2
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %8
%15 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/42/exe\00"
@errno = global i64 0
@EFAULT = global i64 0
@str = [5 x i8] c"pass\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @readlink(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* null, i32 4096)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i64, i64* @errno
%7 = load i64, i64* @EFAULT
%8 = icmp eq i64 %6, %7
br i1 %8, label %11, label %9
9: ; preds = %5, %2
%10 = tail call i32 (...) @abort()
unreachable
11: ; preds = %5
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
}