#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 aiocb {
  int aio_reqprio;
};

/* Variables and functions */
int /*<<< orphan*/ _SC_ASYNCHRONOUS_IO;
int /*<<< orphan*/ _SC_PRIORITIZED_IO;
int aio_read(struct aiocb *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(struct aiocb *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
long sysconf(int /*<<< orphan*/);
int main(void) {
  struct aiocb aiocb;
  if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L)
    return 4;
  if (sysconf(_SC_PRIORITIZED_IO) < 200112L)
    return 5;
  memset(&aiocb, 0, sizeof(struct aiocb));
  aiocb.aio_reqprio = -1;
  if (aio_read(&aiocb) != -1) {
    printf("aio_read/8-1.c"
           " aio_read() should fail!\n");
    exit(1);
  }
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
cmp    $0x30db0,%rax
jge    1185 <main+0x35>
movl   $0x4,-0x4(%rbp)
jmp    11fd <main+0xad>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
cmp    $0x30db0,%rax
jge    11ab <main+0x5b>
movl   $0x5,-0x4(%rbp)
jmp    11fd <main+0xad>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
movl   $0xffffffff,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <aio_read@plt>
cmp    $0xffffffff,%eax
je     11ea <main+0x9a>
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    $0x4,%ebx
cmp    $0x30db0,%rax
jl     11be <main+0x6e>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    $0x5,%ebx
cmp    $0x30db0,%rax
jl     11be <main+0x6e>
mov    %rsp,%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
movl   $0xffffffff,(%rsp)
mov    %r14,%rdi
call   1050 <aio_read@plt>
cmp    $0xffffffff,%eax
jne    11c8 <main+0x78>
lea    0xe47(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.aiocb = type { i32 }
@_SC_ASYNCHRONOUS_IO = global i32 0
@_SC_PRIORITIZED_IO = global i32 0
@.str = [40 x i8] c"aio_read/8-1.c aio_read() should fail!\0A\00"
@.str.1 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.aiocb
store i32 0, i32* %1
%3 = load i32, i32* @_SC_ASYNCHRONOUS_IO
%4 = call i64 @sysconf(i32 %3)
%5 = icmp slt i64 %4, 200112
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 4, i32* %1
br label %22
7: ; preds = %0
%8 = load i32, i32* @_SC_PRIORITIZED_IO
%9 = call i64 @sysconf(i32 %8)
%10 = icmp slt i64 %9, 200112
br i1 %10, label %11, label %12
11: ; preds = %7
store i32 5, i32* %1
br label %22
12: ; preds = %7
%13 = call i32 @memset(%struct.aiocb* %2, i32 0, i32 4)
%14 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %2, i32 0, i32 0
store i32 -1, i32* %14
%15 = call i32 @aio_read(%struct.aiocb* %2)
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %22
22: ; preds = %20, %11, %6
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
%struct.aiocb = type { i32 }
@_SC_ASYNCHRONOUS_IO = global i32 0
@_SC_PRIORITIZED_IO = global i32 0
@str = [12 x i8] c"Test PASSED\00"
@str.2 = [39 x i8] c"aio_read/8-1.c aio_read() should fail!\00"
define i32 @main() {
%1 = alloca %struct.aiocb
%2 = bitcast %struct.aiocb* %1 to i8*
%3 = load i32, i32* @_SC_ASYNCHRONOUS_IO
%4 = tail call i64 @sysconf(i32 %3)
%5 = icmp slt i64 %4, 200112
br i1 %5, label %20, label %6
6: ; preds = %0
%7 = load i32, i32* @_SC_PRIORITIZED_IO
%8 = tail call i64 @sysconf(i32 %7)
%9 = icmp slt i64 %8, 200112
br i1 %9, label %20, label %10
10: ; preds = %6
%11 = call i32 @memset(%struct.aiocb* %1, i32 0, i32 4)
%12 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %1, i64 0, i32 0
store i32 -1, i32* %12
%13 = call i32 @aio_read(%struct.aiocb* %1)
%14 = icmp eq i32 %13, -1
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %6, %0, %18
%21 = phi i32 [ 0, %18 ], [ 4, %0 ], [ 5, %6 ]
ret i32 %21
}