#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 /*<<< orphan*/ tmpfname;
struct aiocb {
  int aio_fildes;
  char *aio_buf;
  int aio_reqprio;
  int aio_nbytes;
};

/* Variables and functions */
scalar_t__ EINVAL;
int O_CREAT;
int O_EXCL;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ _SC_ASYNCHRONOUS_IO;
int aio_read(struct aiocb *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int getpid();
int /*<<< orphan*/ memset(struct aiocb *, int /*<<< orphan*/, int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char *strerror(scalar_t__);
long sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  char tmpfname[256];
  char buf[111];
  int fd;
  struct aiocb aiocb;
  if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L)
    return 4;
  snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_read_11_2%d", getpid());
  unlink(tmpfname);
  fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    printf("aio_read/11-2.c"
           " Error at open(): %s\n",
           strerror(errno));
    exit(2);
  }
  unlink(tmpfname);
  memset(&aiocb, 0, sizeof(struct aiocb));
  aiocb.aio_fildes = fd;
  aiocb.aio_buf = buf;
  aiocb.aio_reqprio = -1;
  aiocb.aio_nbytes = 111;
  if (aio_read(&aiocb) != -1) {
    printf("aio_read/11-2.c"
           " bad aio_read return value()\n");
    exit(1);
  }
  if (errno != EINVAL) {
    printf("aio_read/11-2.c"
           " errno is not EINVAL %s\n",
           strerror(errno));
    exit(1);
  }
  close(fd);
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   10b0 <sysconf@plt>
cmp    $0x30db0,%rax
jge    11e8 <main+0x38>
movl   $0x4,-0x4(%rbp)
jmp    1377 <main+0x1c7>
lea    -0x110(%rbp),%rax
mov    %rax,-0x1a8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x1a8(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xdee(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
mov    0x2da6(%rip),%rax
or     (%rax),%esi
mov    0x2d7d(%rip),%rax
or     (%rax),%esi
mov    0x2d64(%rip),%rax
mov    (%rax),%edx
mov    0x2d7b(%rip),%rax
or     (%rax),%edx
call   10a0 <open@plt>
mov    %eax,-0x184(%rbp)
cmpl   $0xffffffff,-0x184(%rbp)
jne    1299 <main+0xe9>
mov    0x2d42(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x1a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1070 <memset@plt>
mov    -0x184(%rbp),%eax
mov    %eax,-0x1a0(%rbp)
lea    -0x180(%rbp),%rax
mov    %rax,-0x198(%rbp)
movl   $0xffffffff,-0x190(%rbp)
ff ff ff
movl   $0x6f,-0x18c(%rbp)
lea    -0x1a0(%rbp),%rdi
call   1090 <aio_read@plt>
cmp    $0xffffffff,%eax
je     1313 <main+0x163>
lea    0xd3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2c9e(%rip),%rax
mov    (%rax),%rax
mov    0x2c84(%rip),%rcx
cmp    (%rcx),%rax
je     1357 <main+0x1a7>
mov    0x2c84(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xd25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x184(%rbp),%edi
call   1080 <close@plt>
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x198,%rsp
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   10c0 <sysconf@plt>
mov    %rax,%rcx
mov    $0x4,%eax
cmp    $0x30db0,%rcx
jl     12d0 <main+0x110>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe05(%rip),%rdx
lea    0x90(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %eax,%ecx
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    0x2dd7(%rip),%rax
mov    0x2db8(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d8d(%rip),%rax
or     (%rax),%esi
mov    0x2d74(%rip),%rax
mov    0x2d8d(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     12db <main+0x11b>
mov    %eax,%ebx
lea    0x90(%rsp),%rdi
call   1030 <unlink@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    %ebx,0x8(%rsp)
lea    0x20(%rsp),%rax
mov    %rax,0x10(%rsp)
movabs $0x6fffffffff,%rax
mov    %rax,0x18(%rsp)
mov    %r14,%rdi
call   10a0 <aio_read@plt>
cmp    $0xffffffff,%eax
jne    1305 <main+0x145>
mov    0x2d0c(%rip),%rax
mov    (%rax),%rdi
mov    0x2cf2(%rip),%rax
cmp    (%rax),%rdi
jne    131b <main+0x15b>
mov    %ebx,%edi
call   1090 <close@plt>
lea    0xd9d(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x198,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2cd6(%rip),%rax
mov    (%rax),%rdi
call   10e0 <strerror@plt>
lea    0xd28(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
lea    0xd66(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
call   10e0 <strerror@plt>
lea    0xd17(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.aiocb = type { i32, i8*, i32, i32 }
@_SC_ASYNCHRONOUS_IO = global i32 0
@.str = [25 x i8] c"/tmp/pts_aio_read_11_2%d\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [37 x i8] c"aio_read/11-2.c Error at open(): %s\0A\00"
@errno = global i64 0
@.str.2 = [45 x i8] c"aio_read/11-2.c bad aio_read return value()\0A\00"
@EINVAL = global i64 0
@.str.3 = [40 x i8] c"aio_read/11-2.c errno is not EINVAL %s\0A\00"
@.str.4 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca [111 x i8]
%4 = alloca i32
%5 = alloca %struct.aiocb
store i32 0, i32* %1
%6 = load i32, i32* @_SC_ASYNCHRONOUS_IO
%7 = call i64 @sysconf(i32 %6)
%8 = icmp slt i64 %7, 200112
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 4, i32* %1
br label %61
10: ; preds = %0
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%12 = call i32 (...) @getpid()
%13 = call i32 @snprintf(i8* %11, i32 256, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%15 = call i32 @unlink(i8* %14)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%17 = load i32, i32* @O_CREAT
%18 = load i32, i32* @O_RDWR
%19 = or i32 %17, %18
%20 = load i32, i32* @O_EXCL
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IRUSR
%23 = load i32, i32* @S_IWUSR
%24 = or i32 %22, %23
%25 = call i32 @open(i8* %16, i32 %21, i32 %24)
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %33
28: ; preds = %10
%29 = load i64, i64* @errno
%30 = call i8* @strerror(i64 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 2)
unreachable
33: ; preds = %10
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%35 = call i32 @unlink(i8* %34)
%36 = call i32 @memset(%struct.aiocb* %5, i32 0, i32 24)
%37 = load i32, i32* %4
%38 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %5, i32 0, i32 0
store i32 %37, i32* %38
%39 = getelementptr inbounds [111 x i8], [111 x i8]* %3, i64 0, i64 0
%40 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %5, i32 0, i32 1
store i8* %39, i8** %40
%41 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %5, i32 0, i32 2
store i32 -1, i32* %41
%42 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %5, i32 0, i32 3
store i32 111, i32* %42
%43 = call i32 @aio_read(%struct.aiocb* %5)
%44 = icmp ne i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %33
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %33
%49 = load i64, i64* @errno
%50 = load i64, i64* @EINVAL
%51 = icmp ne i64 %49, %50
br i1 %51, label %52, label %57
52: ; preds = %48
%53 = load i64, i64* @errno
%54 = call i8* @strerror(i64 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %54)
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %48
%58 = load i32, i32* %4
%59 = call i32 @close(i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %61
61: ; preds = %57, %9
%62 = load i32, i32* %1
ret i32 %62
}

LLVM IR (-O2):
%struct.aiocb = type { i32, i8*, i32, i32 }
@_SC_ASYNCHRONOUS_IO = global i32 0
@.str = [25 x i8] c"/tmp/pts_aio_read_11_2%d\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [37 x i8] c"aio_read/11-2.c Error at open(): %s\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.3 = [40 x i8] c"aio_read/11-2.c errno is not EINVAL %s\0A\00"
@str = [12 x i8] c"Test PASSED\00"
@str.5 = [44 x i8] c"aio_read/11-2.c bad aio_read return value()\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca [111 x i8]
%3 = alloca %struct.aiocb
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [111 x i8], [111 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.aiocb* %3 to i8*
%7 = load i32, i32* @_SC_ASYNCHRONOUS_IO
%8 = tail call i64 @sysconf(i32 %7)
%9 = icmp slt i64 %8, 200112
br i1 %9, label %52, label %10
10: ; preds = %0
%11 = tail call i32 (...) @getpid()
%12 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 @unlink(i8* %4)
%14 = load i32, i32* @O_CREAT
%15 = load i32, i32* @O_RDWR
%16 = or i32 %15, %14
%17 = load i32, i32* @O_EXCL
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IRUSR
%20 = load i32, i32* @S_IWUSR
%21 = or i32 %20, %19
%22 = call i32 @open(i8* %4, i32 %18, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %29
24: ; preds = %10
%25 = load i64, i64* @errno
%26 = call i8* @strerror(i64 %25)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 2)
unreachable
29: ; preds = %10
%30 = call i32 @unlink(i8* %4)
%31 = call i32 @memset(%struct.aiocb* %3, i32 0, i32 24)
%32 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %3, i64 0, i32 0
store i32 %22, i32* %32
%33 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %3, i64 0, i32 1
store i8* %5, i8** %33
%34 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %3, i64 0, i32 2
store i32 -1, i32* %34
%35 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %3, i64 0, i32 3
store i32 111, i32* %35
%36 = call i32 @aio_read(%struct.aiocb* %3)
%37 = icmp eq i32 %36, -1
br i1 %37, label %41, label %38
38: ; preds = %29
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.5, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %29
%42 = load i64, i64* @errno
%43 = load i64, i64* @EINVAL
%44 = icmp eq i64 %42, %43
br i1 %44, label %49, label %45
45: ; preds = %41
%46 = call i8* @strerror(i64 %42)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %41
%50 = call i32 @close(i32 %22)
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %52
52: ; preds = %0, %49
%53 = phi i32 [ 0, %49 ], [ 4, %0 ]
ret i32 %53
}