#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 */
scalar_t__ EINVAL;
int /*<<< orphan*/ _SC_ASYNCHRONOUS_IO;
int /*<<< orphan*/ _SC_PRIORITIZED_IO;
int aio_write(struct aiocb *);
scalar_t__ errno;
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_write(&aiocb) != -1) {
    printf("aio_write/6-1.c"
           " aio_write should fail!\n");
    exit(1);
  }
  if (errno != EINVAL) {
    printf("aio_write/6-1.c"
           " errno should be EINVAL!\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    122d <main+0xdd>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
cmp    $0x30db0,%rax
jge    11ab <main+0x5b>
movl   $0x5,-0x4(%rbp)
jmp    122d <main+0xdd>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
movl   $0xffffffff,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <aio_write@plt>
cmp    $0xffffffff,%eax
je     11ea <main+0x9a>
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%rax
mov    0x2dcd(%rip),%rcx
cmp    (%rcx),%rax
je     121a <main+0xca>
lea    0xe1d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe30(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    %rax,%rcx
mov    $0x4,%eax
cmp    $0x30db0,%rcx
jl     11e0 <main+0x90>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    %rax,%rcx
mov    $0x5,%eax
cmp    $0x30db0,%rcx
jl     11e0 <main+0x90>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
movl   $0xffffffff,0x8(%rsp)
ff
mov    %rbx,%rdi
call   1040 <aio_write@plt>
cmp    $0xffffffff,%eax
jne    11e6 <main+0x96>
mov    0x2e0d(%rip),%rax
mov    (%rax),%rax
mov    0x2dfb(%rip),%rcx
cmp    (%rcx),%rax
jne    11ef <main+0x9f>
lea    0xe27(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe47(%rip),%rdi
jmp    11f6 <main+0xa6>
lea    0xe16(%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_write/6-1.c aio_write should fail!\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.1 = [41 x i8] c"aio_write/6-1.c errno should be EINVAL!\0A\00"
@.str.2 = [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 %29
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 %29
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_write(%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 = load i64, i64* @errno
%22 = load i64, i64* @EINVAL
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %29
29: ; preds = %27, %11, %6
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
%struct.aiocb = type { i32 }
@_SC_ASYNCHRONOUS_IO = global i32 0
@_SC_PRIORITIZED_IO = global i32 0
@errno = global i64 0
@EINVAL = global i64 0
@str = [12 x i8] c"Test PASSED\00"
@str.3 = [40 x i8] c"aio_write/6-1.c errno should be EINVAL!\00"
@str.4 = [39 x i8] c"aio_write/6-1.c aio_write 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 %27, 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 %27, 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_write(%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.4, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINVAL
%21 = icmp eq i64 %19, %20
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.3, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %18
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %27
27: ; preds = %6, %0, %25
%28 = phi i32 [ 0, %25 ], [ 4, %0 ], [ 5, %6 ]
ret i32 %28
}