#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 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, int /*<<< orphan*/ *);
int aio_error(struct aiocb *);
int aio_return(struct aiocb *);
int aio_write(struct aiocb *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int getpid();
void *malloc(int);
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(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;
  if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L)
    return 4;
  snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_4_1_%d", getpid());
  unlink(tmpfname);
  fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    printf("aio_cancel/4-1.c"
           " Error at open(): %s\n",
           strerror(errno));
    return 2;
  }
  unlink(tmpfname);
  for (i = 0; i < 128; i++) {
    aiocb[i] = malloc(sizeof(struct aiocb));
    if (aiocb[i] == NULL) {
      printf("aio_cancel/4-1.c"
             " Error at malloc(): %s\n",
             strerror(errno));
      return 2;
    }
    memset(aiocb[i], 0, sizeof(struct aiocb));
    aiocb[i]->aio_fildes = fd;
    aiocb[i]->aio_buf = malloc((1024 * 1024));
    if (aiocb[i]->aio_buf == NULL) {
      printf("aio_cancel/4-1.c"
             " Error at malloc(): %s\n",
             strerror(errno));
      return 2;
    }
    aiocb[i]->aio_nbytes = (1024 * 1024);
    aiocb[i]->aio_offset = 0;
    aiocb[i]->aio_sigevent.sigev_notify = SIGEV_NONE;
  }
  for (i = 0; i < 128; i++) {
    if (aio_write(aiocb[i]) == -1) {
      printf("aio_cancel/4-1.c"
             " loop %d: Error at aio_write(): %s\n",
             i, strerror(errno));
      return 1;
    }
  }
  if (aio_cancel(fd, NULL) == -1) {
    printf("aio_cancel/4-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/4-1.c"
               " Error at aio_error(): %s\n",
               strerror(errno));
        return 1;
      } else if (ret == EINPROGRESS)
        in_progress = 1;
      else if (ret == ECANCELED) {
        if (aio_return(aiocb[i]) == -1) {
          printf("Test PASSED\n");
          return 0;
        }
        printf("aio_cancel/4-1.c"
               " aio_return is not -1\n");
        return 1;
      }
    }
  } while (in_progress);
  return 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x540,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   10f0 <sysconf@plt>
cmp    $0x30db0,%rax
jge    1218 <main+0x38>
movl   $0x4,-0x4(%rbp)
jmp    1657 <main+0x477>
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    0xdbe(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
mov    0x2d6e(%rip),%rax
or     (%rax),%esi
mov    0x2d35(%rip),%rax
or     (%rax),%esi
mov    0x2d1c(%rip),%rax
mov    (%rax),%edx
mov    0x2d33(%rip),%rax
or     (%rax),%edx
call   10e0 <open@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xffffffff,-0x114(%rbp)
jne    12ca <main+0xea>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1657 <main+0x477>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x524(%rbp)
cmpl   $0x80,-0x524(%rbp)
jge    1440 <main+0x260>
mov    $0x20,%edi
call   10c0 <malloc@plt>
mov    %rax,%rcx
movslq -0x524(%rbp),%rax
mov    %rcx,-0x520(%rbp,%rax,8)
ff
movslq -0x524(%rbp),%rax
cmpq   $0x0,-0x520(%rbp,%rax,8)
jne    134d <main+0x16d>
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xd07(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1657 <main+0x477>
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rdi
ff
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
mov    -0x114(%rbp),%ecx
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
mov    %ecx,(%rax)
mov    $0x100000,%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    13e4 <main+0x204>
mov    0x2be0(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xc70(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1657 <main+0x477>
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
movl   $0x100000,0x4(%rax)
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
movq   $0x0,0x10(%rax)
mov    0x2bd8(%rip),%rax
mov    (%rax),%ecx
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
mov    %ecx,0x8(%rax)
mov    -0x524(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x524(%rbp)
jmp    12e0 <main+0x100>
movl   $0x0,-0x524(%rbp)
cmpl   $0x80,-0x524(%rbp)
jge    14cd <main+0x2ed>
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rdi
ff
call   1050 <aio_write@plt>
cmp    $0xffffffff,%eax
jne    14b4 <main+0x2d4>
mov    -0x524(%rbp),%eax
mov    %eax,-0x53c(%rbp)
mov    0x2b16(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x53c(%rbp),%esi
mov    %rax,%rdx
lea    0xbc8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1657 <main+0x477>
jmp    14b9 <main+0x2d9>
mov    -0x524(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x524(%rbp)
jmp    144a <main+0x26a>
mov    -0x114(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <aio_cancel@plt>
cmp    $0xffffffff,%eax
jne    1510 <main+0x330>
mov    0x2ab4(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xba0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1657 <main+0x477>
mov    -0x114(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x528(%rbp)
movl   $0x0,-0x524(%rbp)
cmpl   $0x80,-0x524(%rbp)
jge    163e <main+0x45e>
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rdi
ff
call   10b0 <aio_error@plt>
mov    %eax,-0x52c(%rbp)
cmpl   $0xffffffff,-0x52c(%rbp)
jne    1591 <main+0x3b1>
mov    0x2a33(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xb4b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1657 <main+0x477>
mov    -0x52c(%rbp),%eax
mov    0x2a32(%rip),%rcx
cmp    (%rcx),%eax
jne    15b5 <main+0x3d5>
movl   $0x1,-0x528(%rbp)
jmp    1620 <main+0x440>
mov    -0x52c(%rbp),%eax
mov    0x2a06(%rip),%rcx
cmp    (%rcx),%eax
jne    161b <main+0x43b>
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rdi
ff
call   10d0 <aio_return@plt>
cmp    $0xffffffff,%eax
jne    1601 <main+0x421>
lea    0xb06(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1657 <main+0x477>
lea    0xaf9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1657 <main+0x477>
jmp    1620 <main+0x440>
jmp    1625 <main+0x445>
jmp    162a <main+0x44a>
mov    -0x524(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x524(%rbp)
jmp    152f <main+0x34f>
jmp    1643 <main+0x463>
cmpl   $0x0,-0x528(%rbp)
jne    151b <main+0x33b>
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    0x2dba(%rip),%rax
mov    (%rax),%edi
call   1100 <sysconf@plt>
mov    %rax,%rcx
mov    $0x4,%eax
cmp    $0x30db0,%rcx
jl     13ff <main+0x20f>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xdd0(%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    0x2da7(%rip),%rax
mov    0x2d80(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d45(%rip),%rax
or     (%rax),%esi
mov    0x2d2c(%rip),%rax
mov    0x2d45(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   10f0 <open@plt>
cmp    $0xffffffff,%eax
je     13db <main+0x1eb>
mov    %eax,%r15d
mov    %rsp,%rdi
call   1030 <unlink@plt>
xor    %ebp,%ebp
mov    0x2d54(%rip),%r14
nopl   0x0(%rax)
mov    $0x20,%edi
call   10d0 <malloc@plt>
mov    %rax,0x100(%rsp,%rbp,8)
test   %rax,%rax
je     13c4 <main+0x1d4>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1090 <memset@plt>
mov    %r15d,(%rbx)
mov    $0x100000,%edi
call   10d0 <malloc@plt>
mov    %rax,0x18(%rbx)
test   %rax,%rax
je     13c4 <main+0x1d4>
movl   $0x100000,0x4(%rbx)
movq   $0x0,0x10(%rbx)
mov    (%r14),%eax
mov    %eax,0x8(%rbx)
add    $0x1,%rbp
cmp    $0x80,%rbp
jne    12a0 <main+0xb0>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x100(%rsp,%rbx,8),%rdi
call   1060 <aio_write@plt>
cmp    $0xffffffff,%eax
je     140f <main+0x21f>
add    $0x1,%rbx
cmp    $0x80,%rbx
jne    1310 <main+0x120>
xor    %r14d,%r14d
mov    %r15d,%edi
xor    %esi,%esi
call   10a0 <aio_cancel@plt>
cmp    $0xffffffff,%eax
je     1437 <main+0x247>
mov    %r15d,%edi
call   10b0 <close@plt>
mov    0x2c78(%rip),%r12
mov    0x2c69(%rip),%r15
xor    %ebp,%ebp
jmp    1380 <main+0x190>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbp
mov    %ecx,%r14d
cmp    $0x80,%rbp
je     13b1 <main+0x1c1>
mov    0x100(%rsp,%rbp,8),%rbx
mov    %rbx,%rdi
call   10c0 <aio_error@plt>
cmp    $0xffffffff,%eax
je     144e <main+0x25e>
mov    $0x1,%ecx
cmp    (%r12),%eax
je     1370 <main+0x180>
mov    %r14d,%ecx
cmp    (%r15),%eax
jne    1370 <main+0x180>
jmp    1474 <main+0x284>
xor    %ebp,%ebp
mov    $0x2,%eax
mov    $0x0,%r14d
test   %ecx,%ecx
jne    1380 <main+0x190>
jmp    13ff <main+0x20f>
mov    0x2bd5(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc68(%rip),%rdi
jmp    13f0 <main+0x200>
mov    0x2bbe(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc2b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%eax
add    $0x500,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b8a(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc45(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
jmp    13ff <main+0x20f>
mov    0x2b62(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc51(%rip),%rdi
jmp    1463 <main+0x273>
mov    0x2b4b(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc66(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
jmp    13ff <main+0x20f>
mov    %rbx,%rdi
call   10e0 <aio_return@plt>
cmp    $0xffffffff,%eax
je     1497 <main+0x2a7>
lea    0xc6c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    13ff <main+0x20f>
lea    0xc7c(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    13ff <main+0x20f>

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

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_4_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/4-1.c Error at open(): %s\0A\00"
@errno = global i32 0
@.str.2 = [40 x i8] c"aio_cancel/4-1.c Error at malloc(): %s\0A\00"
@SIGEV_NONE = global i32 0
@.str.3 = [52 x i8] c"aio_cancel/4-1.c loop %d: Error at aio_write(): %s\0A\00"
@.str.4 = [44 x i8] c"aio_cancel/4-1.c Error at aio_cancel(): %s\0A\00"
@.str.5 = [43 x i8] c"aio_cancel/4-1.c Error at aio_error(): %s\0A\00"
@EINPROGRESS = global i32 0
@ECANCELED = global i32 0
@str = [38 x i8] c"aio_cancel/4-1.c aio_return is not -1\00"
@str.8 = [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 %113, 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 %113
26: ; preds = %8
%27 = call i32 @unlink(i8* %3)
br label %28
28: ; preds = %26, %50
%29 = phi i64 [ 0, %26 ], [ %55, %50 ]
%30 = call dereferenceable_or_null(32) i8* @malloc(i32 32)
%31 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %2, i64 0, i64 %29
%32 = bitcast %struct.aiocb** %31 to i8**
store i8* %30, i8** %32
%33 = icmp eq i8* %30, null
%34 = bitcast i8* %30 to %struct.aiocb*
br i1 %33, label %35, label %39
35: ; preds = %28
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %37)
br label %113
39: ; preds = %28
%40 = call i32 @memset(%struct.aiocb* %34, i32 0, i32 32)
%41 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %34, i64 0, i32 0
store i32 %20, i32* %41
%42 = call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%43 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %34, i64 0, i32 4
%44 = bitcast i32** %43 to i8**
store i8* %42, i8** %44
%45 = icmp eq i8* %42, null
br i1 %45, label %46, label %50
46: ; preds = %39
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %48)
br label %113
50: ; preds = %39
%51 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %34, i64 0, i32 1
store i32 1048576, i32* %51
%52 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %34, i64 0, i32 3
store i64 0, i64* %52
%53 = load i32, i32* @SIGEV_NONE
%54 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %34, i64 0, i32 2, i32 0
store i32 %53, i32* %54
%55 = add nuw nsw i64 %29, 1
%56 = icmp eq i64 %55, 128
br i1 %56, label %57, label %28
57: ; preds = %50, %68
%58 = phi i64 [ %69, %68 ], [ 0, %50 ]
%59 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %2, i64 0, i64 %58
%60 = load %struct.aiocb*, %struct.aiocb** %59
%61 = call i32 @aio_write(%struct.aiocb* %60)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %68
63: ; preds = %57
%64 = trunc i64 %58 to i32
%65 = load i32, i32* @errno
%66 = call i8* @strerror(i32 %65)
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %64, i8* %66)
br label %113
68: ; preds = %57
%69 = add nuw nsw i64 %58, 1
%70 = icmp eq i64 %69, 128
br i1 %70, label %71, label %57
71: ; preds = %68
%72 = call i32 @aio_cancel(i32 %20, i32* null)
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %78
74: ; preds = %71
%75 = load i32, i32* @errno
%76 = call i8* @strerror(i32 %75)
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %76)
br label %113
78: ; preds = %71
%79 = call i32 @close(i32 %20)
br label %80
80: ; preds = %108, %78
%81 = phi i64 [ 0, %78 ], [ %109, %108 ]
%82 = phi i32 [ 0, %78 ], [ %110, %108 ]
%83 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %2, i64 0, i64 %81
%84 = load %struct.aiocb*, %struct.aiocb** %83
%85 = call i32 @aio_error(%struct.aiocb* %84)
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %91
87: ; preds = %80
%88 = load i32, i32* @errno
%89 = call i8* @strerror(i32 %88)
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %89)
br label %113
91: ; preds = %80
%92 = load i32, i32* @EINPROGRESS
%93 = icmp eq i32 %85, %92
br i1 %93, label %104, label %94
94: ; preds = %91
%95 = load i32, i32* @ECANCELED
%96 = icmp eq i32 %85, %95
br i1 %96, label %97, label %104
97: ; preds = %94
%98 = call i32 @aio_return(%struct.aiocb* %84)
%99 = icmp eq i32 %98, -1
br i1 %99, label %100, label %102
100: ; preds = %97
%101 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
br label %113
102: ; preds = %97
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %113
104: ; preds = %91, %94
%105 = phi i32 [ %82, %94 ], [ 1, %91 ]
%106 = add nuw nsw i64 %81, 1
%107 = icmp eq i64 %106, 128
br i1 %107, label %111, label %108
108: ; preds = %104, %111
%109 = phi i64 [ %106, %104 ], [ 0, %111 ]
%110 = phi i32 [ %105, %104 ], [ 0, %111 ]
br label %80
111: ; preds = %104
%112 = icmp eq i32 %105, 0
br i1 %112, label %113, label %108
113: ; preds = %111, %102, %100, %87, %0, %74, %63, %46, %35, %22
%114 = phi i32 [ 2, %22 ], [ 2, %35 ], [ 2, %46 ], [ 1, %63 ], [ 1, %74 ], [ 4, %0 ], [ 1, %102 ], [ 0, %100 ], [ 1, %87 ], [ 2, %111 ]
ret i32 %114
}