#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__ EBADF;
int /*<<< orphan*/ _SC_ASYNCHRONOUS_IO;
int aio_cancel(int, int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ printf(char *, ...);
char *strerror(scalar_t__);
long sysconf(int /*<<< orphan*/);
int main(void) {
  if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L)
    return 4;
  if (aio_cancel(-1, NULL) != -1) {
    printf("aio_cancel/10-1.c"
           " bad aio_cancel return value()\n");
    return 1;
  }
  if (errno != EBADF) {
    printf("aio_cancel/10-1.c"
           " errno is not EBADF %s\n",
           strerror(errno));
    return 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    0x2e92(%rip),%rax
mov    (%rax),%edi
call   1050 <sysconf@plt>
cmp    $0x30db0,%rax
jge    1175 <main+0x35>
movl   $0x4,-0x4(%rbp)
jmp    1201 <main+0xc1>
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <aio_cancel@plt>
cmp    $0xffffffff,%eax
je     11a6 <main+0x66>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1201 <main+0xc1>
mov    0x2e2b(%rip),%rax
mov    (%rax),%rax
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
je     11ec <main+0xac>
mov    0x2e11(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1201 <main+0xc1>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    %rax,%rcx
mov    $0x4,%eax
cmp    $0x30db0,%rcx
jge    1172 <main+0x22>
pop    %rcx
ret
mov    $0xffffffff,%edi
xor    %esi,%esi
call   1050 <aio_cancel@plt>
cmp    $0xffffffff,%eax
je     1191 <main+0x41>
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
jmp    11cd <main+0x7d>
mov    0x2e40(%rip),%rax
mov    (%rax),%rdi
mov    0x2e2e(%rip),%rax
cmp    (%rax),%rdi
jne    11b7 <main+0x67>
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
call   1070 <strerror@plt>
lea    0xe3d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@_SC_ASYNCHRONOUS_IO = global i32 0
@.str = [49 x i8] c"aio_cancel/10-1.c bad aio_cancel return value()\0A\00"
@errno = global i64 0
@EBADF = global i64 0
@.str.1 = [41 x i8] c"aio_cancel/10-1.c errno is not EBADF %s\0A\00"
@.str.2 = [13 x i8] c"Test PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = load i32, i32* @_SC_ASYNCHRONOUS_IO
%3 = call i64 @sysconf(i32 %2)
%4 = icmp slt i64 %3, 200112
br i1 %4, label %5, label %6
5: ; preds = %0
store i32 4, i32* %1
br label %21
6: ; preds = %0
%7 = call i32 @aio_cancel(i32 -1, i32* null)
%8 = icmp ne i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %21
11: ; preds = %6
%12 = load i64, i64* @errno
%13 = load i64, i64* @EBADF
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i64, i64* @errno
%17 = call i8* @strerror(i64 %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 1, i32* %1
br label %21
19: ; preds = %11
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %21
21: ; preds = %19, %15, %9, %5
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@_SC_ASYNCHRONOUS_IO = global i32 0
@errno = global i64 0
@EBADF = global i64 0
@.str.1 = [41 x i8] c"aio_cancel/10-1.c errno is not EBADF %s\0A\00"
@str = [12 x i8] c"Test PASSED\00"
@str.3 = [48 x i8] c"aio_cancel/10-1.c bad aio_cancel return value()\00"
define i32 @main() {
%1 = load i32, i32* @_SC_ASYNCHRONOUS_IO
%2 = tail call i64 @sysconf(i32 %1)
%3 = icmp slt i64 %2, 200112
br i1 %3, label %18, label %4
4: ; preds = %0
%5 = tail call i32 @aio_cancel(i32 -1, i32* null)
%6 = icmp eq i32 %5, -1
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.3, i64 0, i64 0))
br label %18
9: ; preds = %4
%10 = load i64, i64* @errno
%11 = load i64, i64* @EBADF
%12 = icmp eq i64 %10, %11
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = tail call i8* @strerror(i64 %10)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %18
16: ; preds = %9
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %0, %16, %13, %7
%19 = phi i32 [ 1, %7 ], [ 1, %13 ], [ 0, %16 ], [ 4, %0 ]
ret i32 %19
}