#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_NOTCANCELED;
#define EINPROGRESS 128
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_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_7_1_%d", getpid());
  unlink(tmpfname);
  fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    printf("aio_cancel/7-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/7-1.c"
             " Error at malloc(): %s\n",
             strerror(errno));
      close(fd);
      return 2;
    }
    aiocb[i]->aio_fildes = fd;
    aiocb[i]->aio_buf = malloc(1024);
    if (aiocb[i]->aio_buf == NULL) {
      printf("aio_cancel/7-1.c"
             " Error at malloc(): %s\n",
             strerror(errno));
      close(fd);
      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/7-1.c"
             " loop %d: Error at aio_write(): %s\n",
             i, strerror(errno));
      close(fd);
      return 1;
    }
  }
  gret = aio_cancel(fd, NULL);
  if (gret == -1) {
    printf("aio_cancel/7-1.c"
           " Error at aio_cancel(): %s\n",
           strerror(errno));
    close(fd);
    return 1;
  }
  do {
    in_progress = 0;
    for (i = 0; i < 128; i++) {
      int ret = aio_error(aiocb[i]);
      switch (ret) {
      case -1:
        printf("aio_cancel/7-1.c"
               " Error at aio_error(): %s\n",
               strerror(errno));
        close(fd);
        return 1;
        break;
      case EINPROGRESS:
        if (gret != AIO_NOTCANCELED) {
          printf("aio_cancel/7-1.c"
                 " Error at aio_error(): %s\n",
                 strerror(errno));
          close(fd);
          return 1;
        }
        in_progress = 1;
        break;
      case 0:
        if (gret == AIO_NOTCANCELED) {
          printf("Test PASSED\n");
          close(fd);
          return 0;
        }
        break;
      }
    }
  } while (in_progress);
  close(fd);
  return 2;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x540,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   10e0 <sysconf@plt>
cmp    $0x30db0,%rax
jge    1208 <main+0x38>
movl   $0x4,-0x4(%rbp)
jmp    1684 <main+0x4b4>
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    0x2d55(%rip),%rax
or     (%rax),%esi
mov    0x2d3c(%rip),%rax
mov    (%rax),%edx
mov    0x2d53(%rip),%rax
or     (%rax),%edx
call   10d0 <open@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xffffffff,-0x114(%rbp)
jne    12ba <main+0xea>
mov    0x2d1a(%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    1684 <main+0x4b4>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x524(%rbp)
cmpl   $0x80,-0x524(%rbp)
jge    149a <main+0x2ca>
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    134d <main+0x17d>
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xd12(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
movl   $0x2,-0x4(%rbp)
jmp    1684 <main+0x4b4>
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    13d4 <main+0x204>
mov    0x2c0b(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xc8b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
movl   $0x2,-0x4(%rbp)
jmp    1684 <main+0x4b4>
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    0x2be8(%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    1481 <main+0x2b1>
mov    -0x524(%rbp),%eax
mov    %eax,-0x53c(%rbp)
mov    0x2b64(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x53c(%rbp),%esi
mov    %rax,%rdx
lea    0xc06(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1684 <main+0x4b4>
jmp    1486 <main+0x2b6>
mov    -0x524(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x524(%rbp)
jmp    12d0 <main+0x100>
mov    -0x114(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <aio_cancel@plt>
mov    %eax,-0x52c(%rbp)
cmpl   $0xffffffff,-0x52c(%rbp)
jne    14f2 <main+0x322>
mov    0x2aed(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xbc9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1684 <main+0x4b4>
jmp    14f7 <main+0x327>
movl   $0x0,-0x528(%rbp)
movl   $0x0,-0x524(%rbp)
cmpl   $0x80,-0x524(%rbp)
jge    1660 <main+0x490>
movslq -0x524(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rdi
ff
call   10b0 <aio_error@plt>
mov    %eax,-0x530(%rbp)
mov    -0x530(%rbp),%eax
mov    %eax,-0x540(%rbp)
sub    $0xffffffff,%eax
je     1578 <main+0x3a8>
jmp    154f <main+0x37f>
mov    -0x540(%rbp),%eax
test   %eax,%eax
je     1608 <main+0x438>
jmp    1562 <main+0x392>
mov    -0x540(%rbp),%eax
sub    $0x80,%eax
je     15ae <main+0x3de>
jmp    1647 <main+0x477>
mov    0x2a31(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xb39(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1684 <main+0x4b4>
mov    -0x52c(%rbp),%eax
mov    0x29dd(%rip),%rcx
cmp    (%rcx),%eax
je     15f9 <main+0x429>
mov    0x29e6(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xaee(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1684 <main+0x4b4>
movl   $0x1,-0x528(%rbp)
jmp    1647 <main+0x477>
mov    -0x52c(%rbp),%eax
mov    0x2983(%rip),%rcx
cmp    (%rcx),%eax
jne    1642 <main+0x472>
lea    0xad0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1684 <main+0x4b4>
jmp    1647 <main+0x477>
jmp    164c <main+0x47c>
mov    -0x524(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x524(%rbp)
jmp    150b <main+0x33b>
jmp    1665 <main+0x495>
cmpl   $0x0,-0x528(%rbp)
jne    14f7 <main+0x327>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
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    0x2dda(%rip),%rax
mov    (%rax),%edi
call   10f0 <sysconf@plt>
mov    %rax,%rcx
mov    $0x4,%eax
cmp    $0x30db0,%rcx
jl     1455 <main+0x275>
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    0x2d65(%rip),%rax
or     (%rax),%esi
mov    0x2d4c(%rip),%rax
mov    0x2d65(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     1398 <main+0x1b8>
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     13c1 <main+0x1e1>
mov    %rax,%rbp
mov    %r14d,(%rax)
mov    $0x400,%edi
call   10d0 <malloc@plt>
mov    %rax,0x18(%rbp)
test   %rax,%rax
je     13c1 <main+0x1e1>
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     13ef <main+0x20f>
add    $0x1,%rbx
cmp    $0x80,%rbx
jne    1290 <main+0xb0>
xor    %ebp,%ebp
mov    %r14d,%edi
xor    %esi,%esi
call   1090 <aio_cancel@plt>
cmp    $0xffffffff,%eax
je     1412 <main+0x232>
mov    %eax,%r12d
mov    0x2c79(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x100(%rsp,%rbx,8),%rdi
call   10c0 <aio_error@plt>
test   %eax,%eax
je     1360 <main+0x180>
cmp    $0x80,%eax
je     1370 <main+0x190>
cmp    $0xffffffff,%eax
jne    137e <main+0x19e>
jmp    1429 <main+0x249>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    (%r15),%r12d
jne    137e <main+0x19e>
jmp    1465 <main+0x285>
nopw   0x0(%rax,%rax,1)
mov    $0x1,%ebp
cmp    (%r15),%r12d
jne    1429 <main+0x249>
add    $0x1,%rbx
cmp    $0x80,%rbx
jne    1330 <main+0x150>
xor    %ebx,%ebx
test   %ebp,%ebp
mov    $0x0,%ebp
jne    1330 <main+0x150>
jmp    13e0 <main+0x200>
mov    0x2c11(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc6e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%eax
jmp    1455 <main+0x275>
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc6b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
mov    $0x2,%eax
jmp    1455 <main+0x275>
mov    0x2bba(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc65(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1448 <main+0x268>
mov    0x2b97(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc76(%rip),%rdi
jmp    143e <main+0x25e>
mov    0x2b80(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc8b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
mov    $0x1,%eax
add    $0x500,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc88(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
xor    %eax,%eax
jmp    1455 <main+0x275>

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_7_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/7-1.c Error at open(): %s\0A\00"
@errno = global i32 0
@.str.2 = [40 x i8] c"aio_cancel/7-1.c Error at malloc(): %s\0A\00"
@SIGEV_NONE = global i32 0
@.str.3 = [52 x i8] c"aio_cancel/7-1.c loop %d: Error at aio_write(): %s\0A\00"
@.str.4 = [44 x i8] c"aio_cancel/7-1.c Error at aio_cancel(): %s\0A\00"
@.str.5 = [43 x i8] c"aio_cancel/7-1.c Error at aio_error(): %s\0A\00"
@AIO_NOTCANCELED = global i32 0
@.str.6 = [13 x i8] c"Test PASSED\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 %178
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 %178
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 = %115, %35
%39 = load i32, i32* %5
%40 = icmp slt i32 %39, 128
br i1 %40, label %41, label %118
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 %57
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)
%55 = load i32, i32* %3
%56 = call i32 @close(i32 %55)
store i32 2, i32* %1
br label %178
57: ; preds = %41
%58 = load i32, i32* %3
%59 = load i32, i32* %5
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %60
%62 = load %struct.aiocb*, %struct.aiocb** %61
%63 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %62, i32 0, i32 0
store i32 %58, i32* %63
%64 = call i32* @malloc(i32 1024)
%65 = load i32, i32* %5
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %66
%68 = load %struct.aiocb*, %struct.aiocb** %67
%69 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %68, i32 0, i32 4
store i32* %64, i32** %69
%70 = load i32, i32* %5
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %71
%73 = load %struct.aiocb*, %struct.aiocb** %72
%74 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %73, i32 0, i32 4
%75 = load i32*, i32** %74
%76 = icmp eq i32* %75, null
br i1 %76, label %77, label %83
77: ; preds = %57
%78 = load i32, i32* @errno
%79 = call i8* @strerror(i32 %78)
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %79)
%81 = load i32, i32* %3
%82 = call i32 @close(i32 %81)
store i32 2, i32* %1
br label %178
83: ; preds = %57
%84 = load i32, i32* %5
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %85
%87 = load %struct.aiocb*, %struct.aiocb** %86
%88 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %87, i32 0, i32 1
store i32 1024, i32* %88
%89 = load i32, i32* %5
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %90
%92 = load %struct.aiocb*, %struct.aiocb** %91
%93 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %92, i32 0, i32 3
store i64 0, i64* %93
%94 = load i32, i32* @SIGEV_NONE
%95 = load i32, i32* %5
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %96
%98 = load %struct.aiocb*, %struct.aiocb** %97
%99 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %98, i32 0, i32 2
%100 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %99, i32 0, i32 0
store i32 %94, i32* %100
%101 = load i32, i32* %5
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %102
%104 = load %struct.aiocb*, %struct.aiocb** %103
%105 = call i32 @aio_write(%struct.aiocb* %104)
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %114
107: ; preds = %83
%108 = load i32, i32* %5
%109 = load i32, i32* @errno
%110 = call i8* @strerror(i32 %109)
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %108, i8* %110)
%112 = load i32, i32* %3
%113 = call i32 @close(i32 %112)
store i32 1, i32* %1
br label %178
114: ; preds = %83
br label %115
115: ; preds = %114
%116 = load i32, i32* %5
%117 = add nsw i32 %116, 1
store i32 %117, i32* %5
br label %38
118: ; preds = %38
%119 = load i32, i32* %3
%120 = call i32 @aio_cancel(i32 %119, i32* null)
store i32 %120, i32* %7
%121 = load i32, i32* %7
%122 = icmp eq i32 %121, -1
br i1 %122, label %123, label %129
123: ; preds = %118
%124 = load i32, i32* @errno
%125 = call i8* @strerror(i32 %124)
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %125)
%127 = load i32, i32* %3
%128 = call i32 @close(i32 %127)
store i32 1, i32* %1
br label %178
129: ; preds = %118
br label %130
130: ; preds = %172, %129
store i32 0, i32* %6
store i32 0, i32* %5
br label %131
131: ; preds = %168, %130
%132 = load i32, i32* %5
%133 = icmp slt i32 %132, 128
br i1 %133, label %134, label %171
134: ; preds = %131
%135 = load i32, i32* %5
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %136
%138 = load %struct.aiocb*, %struct.aiocb** %137
%139 = call i32 @aio_error(%struct.aiocb* %138)
store i32 %139, i32* %8
%140 = load i32, i32* %8
switch i32 %140, label %167 [
i32 -1, label %141
i32 128, label %147
i32 0, label %158
]
141: ; preds = %134
%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)
%145 = load i32, i32* %3
%146 = call i32 @close(i32 %145)
store i32 1, i32* %1
br label %178
147: ; preds = %134
%148 = load i32, i32* %7
%149 = load i32, i32* @AIO_NOTCANCELED
%150 = icmp ne i32 %148, %149
br i1 %150, label %151, label %157
151: ; preds = %147
%152 = load i32, i32* @errno
%153 = call i8* @strerror(i32 %152)
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %153)
%155 = load i32, i32* %3
%156 = call i32 @close(i32 %155)
store i32 1, i32* %1
br label %178
157: ; preds = %147
store i32 1, i32* %6
br label %167
158: ; preds = %134
%159 = load i32, i32* %7
%160 = load i32, i32* @AIO_NOTCANCELED
%161 = icmp eq i32 %159, %160
br i1 %161, label %162, label %166
162: ; preds = %158
%163 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%164 = load i32, i32* %3
%165 = call i32 @close(i32 %164)
store i32 0, i32* %1
br label %178
166: ; preds = %158
br label %167
167: ; preds = %134, %166, %157
br label %168
168: ; preds = %167
%169 = load i32, i32* %5
%170 = add nsw i32 %169, 1
store i32 %170, i32* %5
br label %131
171: ; preds = %131
br label %172
172: ; preds = %171
%173 = load i32, i32* %6
%174 = icmp ne i32 %173, 0
br i1 %174, label %130, label %175
175: ; preds = %172
%176 = load i32, i32* %3
%177 = call i32 @close(i32 %176)
store i32 2, i32* %1
br label %178
178: ; preds = %175, %162, %151, %141, %123, %107, %77, %51, %31, %12
%179 = load i32, i32* %1
ret i32 %179
}

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