#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 dummy;
};

/* Variables and functions */
scalar_t__ EFAULT;
scalar_t__ EINVAL;
int /*<<< orphan*/ abort();
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int lstat(int /*<<< orphan*/ *, struct stat *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  struct stat buf;
  if (lstat(NULL, &buf) != -1 || (errno != EINVAL && errno != EFAULT)) {
    perror("lstat 1");
    abort();
  }
  printf("pass\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    -0x8(%rbp),%rsi
call   1050 <lstat@plt>
cmp    $0xffffffff,%eax
jne    11a9 <main+0x59>
mov    0x2e5c(%rip),%rax
mov    (%rax),%rax
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%rax
je     11bc <main+0x6c>
mov    0x2e42(%rip),%rax
mov    (%rax),%rax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%rax
je     11bc <main+0x6c>
lea    0xe50(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rsi
xor    %edi,%edi
call   1050 <lstat@plt>
cmp    $0xffffffff,%eax
jne    1182 <main+0x32>
mov    0x2e71(%rip),%rax
mov    (%rax),%rax
mov    0x2e5f(%rip),%rcx
cmp    (%rcx),%rax
je     1195 <main+0x45>
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%rax
je     1195 <main+0x45>
lea    0xe77(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xe6c(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@EINVAL = global i64 0
@EFAULT = global i64 0
@.str = [8 x i8] c"lstat 1\00"
@str = [5 x i8] c"pass\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = call i32 @lstat(i32* null, %struct.stat* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = load i64, i64* @errno
%7 = load i64, i64* @EINVAL
%8 = icmp eq i64 %6, %7
%9 = load i64, i64* @EFAULT
%10 = icmp eq i64 %6, %9
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %15, label %12
12: ; preds = %5, %0
%13 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 (...) @abort()
unreachable
15: ; preds = %5
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 0)
unreachable
}