#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ tmpfname;
struct TYPE_2__ {
  int /*<<< orphan*/ sigev_notify;
};
struct aiocb {
  int aio_fildes;
  int aio_nbytes;
  TYPE_1__ aio_sigevent;
  scalar_t__ aio_offset;
  int /*<<< orphan*/ *aio_buf;
};

/* Variables and functions */
int AIO_CANCELED;
int ECANCELED;
int EINPROGRESS;
int O_CREAT;
int O_EXCL;
int O_RDWR;
int /*<<< orphan*/ SIGEV_NONE;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ _SC_ASYNCHRONOUS_IO;
int aio_cancel(int, struct aiocb *);
int aio_error(struct aiocb *);
int aio_write(struct aiocb *);
struct aiocb *calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int getpid();
int /*<<< orphan*/ *malloc(int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char *strerror(int /*<<< orphan*/);
long sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  char tmpfname[256];
  int fd;
  struct aiocb *aiocb[128];
  int i;
  int in_progress;
  int gret;
  if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L)
    return 4;
  snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_6_1_%d", getpid());
  unlink(tmpfname);
  fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    printf("aio_cancel/6-1.c"
           " Error at open(): %s\n",
           strerror(errno));
    return 2;
  }
  unlink(tmpfname);
  for (i = 0; i < 128; i++) {
    aiocb[i] = calloc(1, sizeof(struct aiocb));
    if (aiocb[i] == NULL) {
      printf("aio_cancel/6-1.c"
             " Error at malloc(): %s\n",
             strerror(errno));
      return 2;
    }
    aiocb[i]->aio_fildes = fd;
    aiocb[i]->aio_buf = malloc(1024);
    if (aiocb[i]->aio_buf == NULL) {
      printf("aio_cancel/6-1.c"
             " Error at malloc(): %s\n",
             strerror(errno));
      return 2;
    }
    aiocb[i]->aio_nbytes = 1024;
    aiocb[i]->aio_offset = 0;
    aiocb[i]->aio_sigevent.sigev_notify = SIGEV_NONE;
    if (aio_write(aiocb[i]) == -1) {
      printf("aio_cancel/6-1.c"
             " loop %d: Error at aio_write(): %s\n",
             i, strerror(errno));
      return 1;
    }
  }
  gret = aio_cancel(fd, aiocb[i - 1]);
  if (gret == -1) {
    printf("aio_cancel/6-1.c"
           " Error at aio_cancel(): %s\n",
           strerror(errno));
    return 1;
  }
  close(fd);
  do {
    in_progress = 0;
    for (i = 0; i < 128; i++) {
      int ret;
      ret = (aio_error(aiocb[i]));
      if (ret == -1) {
        printf("aio_cancel/6-1.c"
               " Error at aio_error(): %s\n",
               strerror(errno));
        return 1;
      } else if (ret == EINPROGRESS)
        in_progress = 1;
      else if (ret == ECANCELED) {
        if (gret == AIO_CANCELED) {
          printf("Test PASSED\n");
          return 0;
        }
        printf("aio_cancel/6-1.c"
               " aio_cancel() is not AIO_CANCELED\n");
        return 1;
      }
    }
  } while (in_progress);
  if (gret == AIO_CANCELED) {
    printf("aio_cancel/6-1.c"
           " aio_cancel() is AIO_CANCELED without ECANCELED\n");
    return 1;
  }
  return 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x540,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   10e0 <sysconf@plt>
cmp    $0x30db0,%rax
jge    1208 <main+0x38>
movl   $0x4,-0x4(%rbp)
jmp    1643 <main+0x473>
lea    -0x110(%rbp),%rax
mov    %rax,-0x538(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x538(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xdce(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
mov    0x2d7e(%rip),%rax
or     (%rax),%esi
mov    0x2d45(%rip),%rax
or     (%rax),%esi
mov    0x2d2c(%rip),%rax
mov    (%rax),%edx
mov    0x2d43(%rip),%rax
or     (%rax),%edx
call   10d0 <open@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xffffffff,-0x114(%rbp)
jne    12ba <main+0xea>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1643 <main+0x473>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x524(%rbp)
cmpl   $0x80,-0x524(%rbp)
jge    1479 <main+0x2a9>
mov    $0x1,%edi
mov    $0x20,%esi
call   10a0 <calloc@plt>
mov    %rax,%rcx
movslq -0x524(%rbp),%rax
mov    %rcx,-0x520(%rbp,%rax,8)
movslq -0x524(%rbp),%rax
cmpq   $0x0,-0x520(%rbp,%rax,8)
jne    1342 <main+0x172>
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xd12(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1643 <main+0x473>
mov    -0x114(%rbp),%ecx
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
mov    %ecx,(%rax)
mov    $0x400,%edi
call   10c0 <malloc@plt>
mov    %rax,%rcx
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
mov    %rcx,0x18(%rax)
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
cmpq   $0x0,0x18(%rax)
jne    13be <main+0x1ee>
mov    0x2c06(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1643 <main+0x473>
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
movl   $0x400,0x4(%rax)
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
movq   $0x0,0x10(%rax)
mov    0x2bfe(%rip),%rax
mov    (%rax),%ecx
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
mov    %ecx,0x8(%rax)
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rdi
ff
call   1050 <aio_write@plt>
cmp    $0xffffffff,%eax
jne    1460 <main+0x290>
mov    -0x524(%rbp),%eax
mov    %eax,-0x53c(%rbp)
mov    0x2b6a(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x53c(%rbp),%esi
mov    %rax,%rdx
lea    0xc1c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1643 <main+0x473>
jmp    1465 <main+0x295>
mov    -0x524(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x524(%rbp)
jmp    12d0 <main+0x100>
mov    -0x114(%rbp),%edi
mov    -0x524(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x520(%rbp,%rax,8),%rsi
ff
call   1080 <aio_cancel@plt>
mov    %eax,-0x52c(%rbp)
cmpl   $0xffffffff,-0x52c(%rbp)
jne    14d5 <main+0x305>
mov    0x2aef(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xbdb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1643 <main+0x473>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x528(%rbp)
movl   $0x0,-0x524(%rbp)
cmpl   $0x80,-0x524(%rbp)
jge    15fb <main+0x42b>
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rdi
ff
call   10b0 <aio_error@plt>
mov    %eax,-0x530(%rbp)
cmpl   $0xffffffff,-0x530(%rbp)
jne    1556 <main+0x386>
mov    0x2a6e(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xb86(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1643 <main+0x473>
mov    -0x530(%rbp),%eax
mov    0x2a6d(%rip),%rcx
cmp    (%rcx),%eax
jne    157a <main+0x3aa>
movl   $0x1,-0x528(%rbp)
jmp    15dd <main+0x40d>
mov    -0x530(%rbp),%eax
mov    0x2a41(%rip),%rcx
cmp    (%rcx),%eax
jne    15d8 <main+0x408>
mov    -0x52c(%rbp),%eax
mov    0x29f4(%rip),%rcx
cmp    (%rcx),%eax
jne    15be <main+0x3ee>
lea    0xb49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1643 <main+0x473>
lea    0xb3c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1643 <main+0x473>
jmp    15dd <main+0x40d>
jmp    15e2 <main+0x412>
jmp    15e7 <main+0x417>
mov    -0x524(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x524(%rbp)
jmp    14f4 <main+0x324>
jmp    1600 <main+0x430>
cmpl   $0x0,-0x528(%rbp)
jne    14e0 <main+0x310>
mov    -0x52c(%rbp),%eax
mov    0x2976(%rip),%rcx
cmp    (%rcx),%eax
jne    163c <main+0x46c>
lea    0xb0b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1643 <main+0x473>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x540,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x500,%rsp
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   10f0 <sysconf@plt>
mov    %rax,%rcx
mov    $0x4,%eax
cmp    $0x30db0,%rcx
jl     1447 <main+0x267>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xde0(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %eax,%ecx
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    0x2db7(%rip),%rax
mov    0x2d90(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d55(%rip),%rax
or     (%rax),%esi
mov    0x2d3c(%rip),%rax
mov    0x2d55(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     13ac <main+0x1cc>
mov    %eax,%r14d
mov    %rsp,%rdi
call   1030 <unlink@plt>
xor    %ebx,%ebx
mov    0x2d64(%rip),%r15
nopl   0x0(%rax)
mov    $0x1,%edi
mov    $0x20,%esi
call   10b0 <calloc@plt>
mov    %rax,0x100(%rsp,%rbx,8)
test   %rax,%rax
je     13c3 <main+0x1e3>
mov    %rax,%rbp
mov    %r14d,(%rax)
mov    $0x400,%edi
call   10d0 <malloc@plt>
mov    %rax,0x18(%rbp)
test   %rax,%rax
je     13c3 <main+0x1e3>
movl   $0x400,0x4(%rbp)
movq   $0x0,0x10(%rbp)
mov    (%r15),%eax
mov    %eax,0x8(%rbp)
mov    %rbp,%rdi
call   1060 <aio_write@plt>
cmp    $0xffffffff,%eax
je     13e9 <main+0x209>
add    $0x1,%rbx
cmp    $0x80,%rbx
jne    1290 <main+0xb0>
mov    0x4f8(%rsp),%rsi
mov    %r14d,%edi
call   1090 <aio_cancel@plt>
cmp    $0xffffffff,%eax
je     140c <main+0x22c>
mov    %eax,%r15d
mov    %r14d,%edi
call   10a0 <close@plt>
xor    %ebp,%ebp
mov    0x2ca3(%rip),%r12
mov    0x2c94(%rip),%r14
xor    %ebx,%ebx
jmp    134f <main+0x16f>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
mov    %ecx,%ebx
cmp    $0x80,%rbp
je     1380 <main+0x1a0>
mov    0x100(%rsp,%rbp,8),%rdi
call   10c0 <aio_error@plt>
cmp    $0xffffffff,%eax
je     1423 <main+0x243>
mov    $0x1,%ecx
cmp    (%r12),%eax
je     1340 <main+0x160>
mov    %ebx,%ecx
cmp    (%r14),%eax
jne    1340 <main+0x160>
jmp    1457 <main+0x277>
nopl   0x0(%rax)
xor    %ebp,%ebp
mov    $0x0,%ebx
test   %ecx,%ecx
jne    134f <main+0x16f>
mov    0x2bfe(%rip),%rcx
mov    $0x2,%eax
cmp    (%rcx),%r15d
jne    1447 <main+0x267>
lea    0xd4d(%rip),%rdi
jmp    147a <main+0x29a>
mov    0x2bed(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc5a(%rip),%rdi
jmp    13d8 <main+0x1f8>
mov    0x2bd6(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc69(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%eax
jmp    1447 <main+0x267>
mov    0x2bb0(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc6b(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1442 <main+0x262>
mov    0x2b8d(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc7c(%rip),%rdi
jmp    1438 <main+0x258>
mov    0x2b76(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc91(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
add    $0x500,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b32(%rip),%rax
cmp    (%rax),%r15d
jne    1473 <main+0x293>
lea    0xcfc(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    1447 <main+0x267>
lea    0xcba(%rip),%rdi
call   1040 <puts@plt>
jmp    1442 <main+0x262>

LLVM IR (-O0):
%struct.aiocb = type { i32, i32, %struct.TYPE_2__, i64, i32* }
%struct.TYPE_2__ = type { i32 }
@_SC_ASYNCHRONOUS_IO = global i32 0
@.str = [27 x i8] c"/tmp/pts_aio_cancel_6_1_%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 = [38 x i8] c"aio_cancel/6-1.c Error at open(): %s\0A\00"
@errno = global i32 0
@.str.2 = [40 x i8] c"aio_cancel/6-1.c Error at malloc(): %s\0A\00"
@SIGEV_NONE = global i32 0
@.str.3 = [52 x i8] c"aio_cancel/6-1.c loop %d: Error at aio_write(): %s\0A\00"
@.str.4 = [44 x i8] c"aio_cancel/6-1.c Error at aio_cancel(): %s\0A\00"
@.str.5 = [43 x i8] c"aio_cancel/6-1.c Error at aio_error(): %s\0A\00"
@EINPROGRESS = global i32 0
@ECANCELED = global i32 0
@AIO_CANCELED = global i32 0
@.str.6 = [13 x i8] c"Test PASSED\0A\00"
@.str.7 = [51 x i8] c"aio_cancel/6-1.c aio_cancel() is not AIO_CANCELED\0A\00"
@.str.8 = [65 x i8] c"aio_cancel/6-1.c aio_cancel() is AIO_CANCELED without ECANCELED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca [128 x %struct.aiocb*]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* @_SC_ASYNCHRONOUS_IO
%10 = call i64 @sysconf(i32 %9)
%11 = icmp slt i64 %10, 200112
br i1 %11, label %12, label %13
12: ; preds = %0
store i32 4, i32* %1
br label %179
13: ; preds = %0
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%15 = call i32 (...) @getpid()
%16 = call i32 @snprintf(i8* %14, i32 256, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%18 = call i32 @unlink(i8* %17)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%20 = load i32, i32* @O_CREAT
%21 = load i32, i32* @O_RDWR
%22 = or i32 %20, %21
%23 = load i32, i32* @O_EXCL
%24 = or i32 %22, %23
%25 = load i32, i32* @S_IRUSR
%26 = load i32, i32* @S_IWUSR
%27 = or i32 %25, %26
%28 = call i32 @open(i8* %19, i32 %24, i32 %27)
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %13
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %33)
store i32 2, i32* %1
br label %179
35: ; preds = %13
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%37 = call i32 @unlink(i8* %36)
store i32 0, i32* %5
br label %38
38: ; preds = %109, %35
%39 = load i32, i32* %5
%40 = icmp slt i32 %39, 128
br i1 %40, label %41, label %112
41: ; preds = %38
%42 = call %struct.aiocb* @calloc(i32 1, i32 32)
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %44
store %struct.aiocb* %42, %struct.aiocb** %45
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %47
%49 = load %struct.aiocb*, %struct.aiocb** %48
%50 = icmp eq %struct.aiocb* %49, null
br i1 %50, label %51, label %55
51: ; preds = %41
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %53)
store i32 2, i32* %1
br label %179
55: ; preds = %41
%56 = load i32, i32* %3
%57 = load i32, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %58
%60 = load %struct.aiocb*, %struct.aiocb** %59
%61 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %60, i32 0, i32 0
store i32 %56, i32* %61
%62 = call i32* @malloc(i32 1024)
%63 = load i32, i32* %5
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %64
%66 = load %struct.aiocb*, %struct.aiocb** %65
%67 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %66, i32 0, i32 4
store i32* %62, i32** %67
%68 = load i32, i32* %5
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %69
%71 = load %struct.aiocb*, %struct.aiocb** %70
%72 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %71, i32 0, i32 4
%73 = load i32*, i32** %72
%74 = icmp eq i32* %73, null
br i1 %74, label %75, label %79
75: ; preds = %55
%76 = load i32, i32* @errno
%77 = call i8* @strerror(i32 %76)
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %77)
store i32 2, i32* %1
br label %179
79: ; preds = %55
%80 = load i32, i32* %5
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %81
%83 = load %struct.aiocb*, %struct.aiocb** %82
%84 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %83, i32 0, i32 1
store i32 1024, i32* %84
%85 = load i32, i32* %5
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %86
%88 = load %struct.aiocb*, %struct.aiocb** %87
%89 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %88, i32 0, i32 3
store i64 0, i64* %89
%90 = load i32, i32* @SIGEV_NONE
%91 = load i32, i32* %5
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %92
%94 = load %struct.aiocb*, %struct.aiocb** %93
%95 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %94, i32 0, i32 2
%96 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %95, i32 0, i32 0
store i32 %90, i32* %96
%97 = load i32, i32* %5
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %98
%100 = load %struct.aiocb*, %struct.aiocb** %99
%101 = call i32 @aio_write(%struct.aiocb* %100)
%102 = icmp eq i32 %101, -1
br i1 %102, label %103, label %108
103: ; preds = %79
%104 = load i32, i32* %5
%105 = load i32, i32* @errno
%106 = call i8* @strerror(i32 %105)
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %104, i8* %106)
store i32 1, i32* %1
br label %179
108: ; preds = %79
br label %109
109: ; preds = %108
%110 = load i32, i32* %5
%111 = add nsw i32 %110, 1
store i32 %111, i32* %5
br label %38
112: ; preds = %38
%113 = load i32, i32* %3
%114 = load i32, i32* %5
%115 = sub nsw i32 %114, 1
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %116
%118 = load %struct.aiocb*, %struct.aiocb** %117
%119 = call i32 @aio_cancel(i32 %113, %struct.aiocb* %118)
store i32 %119, i32* %7
%120 = load i32, i32* %7
%121 = icmp eq i32 %120, -1
br i1 %121, label %122, label %126
122: ; preds = %112
%123 = load i32, i32* @errno
%124 = call i8* @strerror(i32 %123)
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %124)
store i32 1, i32* %1
br label %179
126: ; preds = %112
%127 = load i32, i32* %3
%128 = call i32 @close(i32 %127)
br label %129
129: ; preds = %169, %126
store i32 0, i32* %6
store i32 0, i32* %5
br label %130
130: ; preds = %165, %129
%131 = load i32, i32* %5
%132 = icmp slt i32 %131, 128
br i1 %132, label %133, label %168
133: ; preds = %130
%134 = load i32, i32* %5
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %135
%137 = load %struct.aiocb*, %struct.aiocb** %136
%138 = call i32 @aio_error(%struct.aiocb* %137)
store i32 %138, i32* %8
%139 = load i32, i32* %8
%140 = icmp eq i32 %139, -1
br i1 %140, label %141, label %145
141: ; preds = %133
%142 = load i32, i32* @errno
%143 = call i8* @strerror(i32 %142)
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %143)
store i32 1, i32* %1
br label %179
145: ; preds = %133
%146 = load i32, i32* %8
%147 = load i32, i32* @EINPROGRESS
%148 = icmp eq i32 %146, %147
br i1 %148, label %149, label %150
149: ; preds = %145
store i32 1, i32* %6
br label %163
150: ; preds = %145
%151 = load i32, i32* %8
%152 = load i32, i32* @ECANCELED
%153 = icmp eq i32 %151, %152
br i1 %153, label %154, label %162
154: ; preds = %150
%155 = load i32, i32* %7
%156 = load i32, i32* @AIO_CANCELED
%157 = icmp eq i32 %155, %156
br i1 %157, label %158, label %160
158: ; preds = %154
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %1
br label %179
160: ; preds = %154
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %1
br label %179
162: ; preds = %150
br label %163
163: ; preds = %162, %149
br label %164
164: ; preds = %163
br label %165
165: ; preds = %164
%166 = load i32, i32* %5
%167 = add nsw i32 %166, 1
store i32 %167, i32* %5
br label %130
168: ; preds = %130
br label %169
169: ; preds = %168
%170 = load i32, i32* %6
%171 = icmp ne i32 %170, 0
br i1 %171, label %129, label %172
172: ; preds = %169
%173 = load i32, i32* %7
%174 = load i32, i32* @AIO_CANCELED
%175 = icmp eq i32 %173, %174
br i1 %175, label %176, label %178
176: ; preds = %172
%177 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %1
br label %179
178: ; preds = %172
store i32 2, i32* %1
br label %179
179: ; preds = %178, %176, %160, %158, %141, %122, %103, %75, %51, %31, %12
%180 = load i32, i32* %1
ret i32 %180
}

LLVM IR (-O2):
%struct.aiocb = type { i32, i32, %struct.TYPE_2__, i64, i32* }
%struct.TYPE_2__ = type { i32 }
@_SC_ASYNCHRONOUS_IO = global i32 0
@.str = [27 x i8] c"/tmp/pts_aio_cancel_6_1_%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 = [38 x i8] c"aio_cancel/6-1.c Error at open(): %s\0A\00"
@errno = global i32 0
@.str.2 = [40 x i8] c"aio_cancel/6-1.c Error at malloc(): %s\0A\00"
@SIGEV_NONE = global i32 0
@.str.3 = [52 x i8] c"aio_cancel/6-1.c loop %d: Error at aio_write(): %s\0A\00"
@.str.4 = [44 x i8] c"aio_cancel/6-1.c Error at aio_cancel(): %s\0A\00"
@.str.5 = [43 x i8] c"aio_cancel/6-1.c Error at aio_error(): %s\0A\00"
@EINPROGRESS = global i32 0
@ECANCELED = global i32 0
@AIO_CANCELED = global i32 0
@str = [64 x i8] c"aio_cancel/6-1.c aio_cancel() is AIO_CANCELED without ECANCELED\00"
@str.9 = [50 x i8] c"aio_cancel/6-1.c aio_cancel() is not AIO_CANCELED\00"
@str.10 = [12 x i8] c"Test PASSED\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca [128 x %struct.aiocb*]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast [128 x %struct.aiocb*]* %2 to i8*
%5 = load i32, i32* @_SC_ASYNCHRONOUS_IO
%6 = tail call i64 @sysconf(i32 %5)
%7 = icmp slt i64 %6, 200112
br i1 %7, label %110, label %8
8: ; preds = %0
%9 = tail call i32 (...) @getpid()
%10 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 @unlink(i8* %3)
%12 = load i32, i32* @O_CREAT
%13 = load i32, i32* @O_RDWR
%14 = or i32 %13, %12
%15 = load i32, i32* @O_EXCL
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IRUSR
%18 = load i32, i32* @S_IWUSR
%19 = or i32 %18, %17
%20 = call i32 @open(i8* %3, i32 %16, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %8
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %110
26: ; preds = %8
%27 = call i32 @unlink(i8* %3)
br label %28
28: ; preds = %26, %58
%29 = phi i64 [ 0, %26 ], [ %59, %58 ]
%30 = call %struct.aiocb* @calloc(i32 1, i32 32)
%31 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %2, i64 0, i64 %29
store %struct.aiocb* %30, %struct.aiocb** %31
%32 = icmp eq %struct.aiocb* %30, null
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %35)
br label %110
37: ; preds = %28
%38 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %30, i64 0, i32 0
store i32 %20, i32* %38
%39 = call i32* @malloc(i32 1024)
%40 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %30, i64 0, i32 4
store i32* %39, i32** %40
%41 = icmp eq i32* %39, null
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %44)
br label %110
46: ; preds = %37
%47 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %30, i64 0, i32 1
store i32 1024, i32* %47
%48 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %30, i64 0, i32 3
store i64 0, i64* %48
%49 = load i32, i32* @SIGEV_NONE
%50 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %30, i64 0, i32 2, i32 0
store i32 %49, i32* %50
%51 = call i32 @aio_write(%struct.aiocb* %30)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %58
53: ; preds = %46
%54 = trunc i64 %29 to i32
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %54, i8* %56)
br label %110
58: ; preds = %46
%59 = add nuw nsw i64 %29, 1
%60 = icmp eq i64 %59, 128
br i1 %60, label %61, label %28
61: ; preds = %58
%62 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %2, i64 0, i64 127
%63 = load %struct.aiocb*, %struct.aiocb** %62
%64 = call i32 @aio_cancel(i32 %20, %struct.aiocb* %63)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %70
66: ; preds = %61
%67 = load i32, i32* @errno
%68 = call i8* @strerror(i32 %67)
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %68)
br label %110
70: ; preds = %61
%71 = call i32 @close(i32 %20)
br label %72
72: ; preds = %100, %70
%73 = phi i64 [ 0, %70 ], [ %101, %100 ]
%74 = phi i32 [ 0, %70 ], [ %102, %100 ]
%75 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %2, i64 0, i64 %73
%76 = load %struct.aiocb*, %struct.aiocb** %75
%77 = call i32 @aio_error(%struct.aiocb* %76)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %83
79: ; preds = %72
%80 = load i32, i32* @errno
%81 = call i8* @strerror(i32 %80)
%82 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %81)
br label %110
83: ; preds = %72
%84 = load i32, i32* @EINPROGRESS
%85 = icmp eq i32 %77, %84
br i1 %85, label %96, label %86
86: ; preds = %83
%87 = load i32, i32* @ECANCELED
%88 = icmp eq i32 %77, %87
br i1 %88, label %89, label %96
89: ; preds = %86
%90 = load i32, i32* @AIO_CANCELED
%91 = icmp eq i32 %64, %90
br i1 %91, label %92, label %94
92: ; preds = %89
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.10, i64 0, i64 0))
br label %110
94: ; preds = %89
%95 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.9, i64 0, i64 0))
br label %110
96: ; preds = %83, %86
%97 = phi i32 [ %74, %86 ], [ 1, %83 ]
%98 = add nuw nsw i64 %73, 1
%99 = icmp eq i64 %98, 128
br i1 %99, label %103, label %100
100: ; preds = %96, %103
%101 = phi i64 [ %98, %96 ], [ 0, %103 ]
%102 = phi i32 [ %97, %96 ], [ 0, %103 ]
br label %72
103: ; preds = %96
%104 = icmp eq i32 %97, 0
br i1 %104, label %105, label %100
105: ; preds = %103
%106 = load i32, i32* @AIO_CANCELED
%107 = icmp eq i32 %64, %106
br i1 %107, label %108, label %110
108: ; preds = %105
%109 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str, i64 0, i64 0))
br label %110
110: ; preds = %94, %92, %79, %105, %0, %108, %66, %53, %42, %33, %22
%111 = phi i32 [ 2, %22 ], [ 2, %33 ], [ 2, %42 ], [ 1, %53 ], [ 1, %66 ], [ 1, %108 ], [ 4, %0 ], [ 2, %105 ], [ 1, %94 ], [ 0, %92 ], [ 1, %79 ]
ret i32 %111
}