#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__ {
  scalar_t__ sigev_notify;
};
struct aiocb {
  int aio_fildes;
  char *aio_buf;
  int aio_nbytes;
  scalar_t__ aio_offset;
  TYPE_1__ aio_sigevent;
};

/* Variables and functions */
int EINPROGRESS;
int O_CREAT;
int O_EXCL;
int O_RDWR;
scalar_t__ 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();
char *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];
  char *buf[128];
  int i;
  int in_progress;
  static int check_one;
  if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L)
    return 4;
  snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_5_1_%d", getpid());
  unlink(tmpfname);
  fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    printf("aio_cancel/5-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/5-1.c"
             " Error at malloc(): %s\n",
             strerror(errno));
      return 2;
    }
    buf[i] = malloc(1024);
    if (buf[i] == NULL) {
      printf("aio_cancel/5-1.c"
             " Error at malloc(): %s\n",
             strerror(errno));
      return 2;
    }
    aiocb[i]->aio_fildes = fd;
    aiocb[i]->aio_buf = buf[i];
    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/5-1.c"
             " loop %d: Error at aio_write(): %s\n",
             i, strerror(errno));
      return 1;
    }
  }
  if (aio_cancel(fd, NULL) == -1) {
    printf("aio_cancel/5-1.c"
           " Error at aio_cancel(): %s\n",
           strerror(errno));
    return 1;
  }
  close(fd);
  check_one = 0;
  do {
    in_progress = 0;
    for (i = 0; i < 128; i++) {
      int ret;
      ret = (aio_error(aiocb[i]));
      if (ret == -1) {
        printf("aio_cancel/5-1.c"
               " Error at aio_error(): %s\n",
               strerror(errno));
        return 1;
      } else if ((ret == EINPROGRESS) || (ret == 0)) {
        if (ret == EINPROGRESS)
          in_progress = 1;
        check_one = 1;
        if ((aiocb[i]->aio_fildes != fd) || (aiocb[i]->aio_buf != buf[i]) ||
            (aiocb[i]->aio_nbytes != 1024) || (aiocb[i]->aio_offset != 0) ||
            (aiocb[i]->aio_sigevent.sigev_notify != SIGEV_NONE)) {
          printf("aio_cancel/5-1.c"
                 " aiocbp modified\n");
          return 1;
        }
      }
    }
  } while (in_progress);
  if (!check_one)
    return 2;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x940,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   10e0 <sysconf@plt>
cmp    $0x30db0,%rax
jge    1208 <main+0x38>
movl   $0x4,-0x4(%rbp)
jmp    16bb <main+0x4eb>
lea    -0x110(%rbp),%rax
mov    %rax,-0x938(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x938(%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    0x2d4d(%rip),%rax
or     (%rax),%esi
mov    0x2d34(%rip),%rax
mov    (%rax),%edx
mov    0x2d4b(%rip),%rax
or     (%rax),%edx
call   10d0 <open@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xffffffff,-0x114(%rbp)
jne    12ba <main+0xea>
mov    0x2d12(%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    16bb <main+0x4eb>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x924(%rbp)
cmpl   $0x80,-0x924(%rbp)
jge    1495 <main+0x2c5>
mov    $0x1,%edi
mov    $0x28,%esi
call   10a0 <calloc@plt>
mov    %rax,%rcx
movslq -0x924(%rbp),%rax
mov    %rcx,-0x520(%rbp,%rax,8)
movslq -0x924(%rbp),%rax
cmpq   $0x0,-0x520(%rbp,%rax,8)
jne    1342 <main+0x172>
mov    0x2c8a(%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    16bb <main+0x4eb>
mov    $0x400,%edi
call   10c0 <malloc@plt>
mov    %rax,%rcx
movslq -0x924(%rbp),%rax
mov    %rcx,-0x920(%rbp,%rax,8)
ff
movslq -0x924(%rbp),%rax
cmpq   $0x0,-0x920(%rbp,%rax,8)
jne    139f <main+0x1cf>
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xcb5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    16bb <main+0x4eb>
mov    -0x114(%rbp),%ecx
movslq -0x924(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
mov    %ecx,(%rax)
movslq -0x924(%rbp),%rax
mov    -0x920(%rbp,%rax,8),%rcx
ff
movslq -0x924(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
mov    %rcx,0x8(%rax)
movslq -0x924(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
movl   $0x400,0x10(%rax)
movslq -0x924(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
movq   $0x0,0x18(%rax)
mov    0x2be4(%rip),%rax
mov    (%rax),%rcx
movslq -0x924(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
mov    %rcx,0x20(%rax)
movslq -0x924(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rdi
ff
call   1050 <aio_write@plt>
cmp    $0xffffffff,%eax
jne    147c <main+0x2ac>
mov    -0x924(%rbp),%eax
mov    %eax,-0x93c(%rbp)
mov    0x2b56(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x93c(%rbp),%esi
mov    %rax,%rdx
lea    0xc00(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16bb <main+0x4eb>
jmp    1481 <main+0x2b1>
mov    -0x924(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x924(%rbp)
jmp    12d0 <main+0x100>
mov    -0x114(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <aio_cancel@plt>
cmp    $0xffffffff,%eax
jne    14d8 <main+0x308>
mov    0x2af4(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xbd8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16bb <main+0x4eb>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,0x2ba3(%rip)
movl   $0x0,-0x928(%rbp)
movl   $0x0,-0x924(%rbp)
cmpl   $0x80,-0x924(%rbp)
jge    1689 <main+0x4b9>
movslq -0x924(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rdi
ff
call   10b0 <aio_error@plt>
mov    %eax,-0x92c(%rbp)
cmpl   $0xffffffff,-0x92c(%rbp)
jne    1563 <main+0x393>
mov    0x2a69(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xb79(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16bb <main+0x4eb>
mov    -0x92c(%rbp),%eax
mov    0x2a60(%rip),%rcx
cmp    (%rcx),%eax
je     1585 <main+0x3b5>
cmpl   $0x0,-0x92c(%rbp)
jne    166b <main+0x49b>
mov    -0x92c(%rbp),%eax
mov    0x2a3e(%rip),%rcx
cmp    (%rcx),%eax
jne    15a4 <main+0x3d4>
movl   $0x1,-0x928(%rbp)
movl   $0x1,0x2ae2(%rip)
movslq -0x924(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
mov    (%rax),%eax
cmp    -0x114(%rbp),%eax
jne    164c <main+0x47c>
movslq -0x924(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
mov    0x8(%rax),%rax
movslq -0x924(%rbp),%rcx
cmp    -0x920(%rbp,%rcx,8),%rax
ff
jne    164c <main+0x47c>
movslq -0x924(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
cmpl   $0x400,0x10(%rax)
jne    164c <main+0x47c>
movslq -0x924(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
cmpq   $0x0,0x18(%rax)
jne    164c <main+0x47c>
movslq -0x924(%rbp),%rax
mov    -0x520(%rbp,%rax,8),%rax
ff
mov    0x20(%rax),%rax
mov    0x29ad(%rip),%rcx
cmp    (%rcx),%rax
je     1666 <main+0x496>
lea    0xaa1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    16bb <main+0x4eb>
jmp    166b <main+0x49b>
jmp    1670 <main+0x4a0>
jmp    1675 <main+0x4a5>
mov    -0x924(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x924(%rbp)
jmp    1501 <main+0x331>
jmp    168e <main+0x4be>
cmpl   $0x0,-0x928(%rbp)
jne    14ed <main+0x31d>
cmpl   $0x0,0x29ee(%rip)
jne    16b4 <main+0x4e4>
movl   $0x2,-0x4(%rbp)
jmp    16bb <main+0x4eb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x940,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x908,%rsp
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   10f0 <sysconf@plt>
mov    %rax,%rcx
mov    $0x4,%eax
cmp    $0x30db0,%rcx
jl     1420 <main+0x240>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xdde(%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    0x2db5(%rip),%rax
mov    0x2d8e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d5b(%rip),%rax
or     (%rax),%esi
mov    0x2d42(%rip),%rax
mov    0x2d5b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     13e5 <main+0x205>
mov    %eax,%r14d
mov    %rsp,%rdi
call   1030 <unlink@plt>
xor    %ebx,%ebx
mov    0x2d62(%rip),%r15
xchg   %ax,%ax
mov    $0x1,%edi
mov    $0x28,%esi
call   10b0 <calloc@plt>
mov    %rax,0x500(%rsp,%rbx,8)
test   %rax,%rax
je     13fc <main+0x21c>
mov    %rax,%rbp
mov    $0x400,%edi
call   10d0 <malloc@plt>
mov    %rax,0x100(%rsp,%rbx,8)
test   %rax,%rax
je     13fc <main+0x21c>
mov    %r14d,0x0(%rbp)
mov    %rax,0x8(%rbp)
movl   $0x400,0x10(%rbp)
movq   $0x0,0x18(%rbp)
mov    (%r15),%rax
mov    %rax,0x20(%rbp)
mov    %rbp,%rdi
call   1060 <aio_write@plt>
cmp    $0xffffffff,%eax
je     1432 <main+0x252>
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     146d <main+0x28d>
mov    %r14d,%edi
call   10a0 <close@plt>
movb   $0x0,0x2d6a(%rip)
mov    0x2c9b(%rip),%r12
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
mov    0x500(%rsp,%r13,8),%rbx
mov    %rbx,%rdi
call   10c0 <aio_error@plt>
cmp    $0xffffffff,%eax
je     1484 <main+0x2a4>
mov    (%r12),%ecx
test   %eax,%eax
je     1365 <main+0x185>
cmp    %ecx,%eax
jne    13b6 <main+0x1d6>
cmp    %ecx,%eax
mov    $0x1,%eax
cmove  %eax,%ebp
movb   $0x1,0x2d22(%rip)
cmp    %r14d,(%rbx)
jne    145a <main+0x27a>
mov    0x8(%rbx),%rax
cmp    0x100(%rsp,%r13,8),%rax
jne    145a <main+0x27a>
cmpl   $0x400,0x10(%rbx)
jne    145a <main+0x27a>
cmpq   $0x0,0x18(%rbx)
jne    145a <main+0x27a>
mov    0x20(%rbx),%rax
cmp    (%r15),%rax
jne    145a <main+0x27a>
add    $0x1,%r13
cmp    $0x80,%r13
jne    1340 <main+0x160>
xor    %r13d,%r13d
test   %ebp,%ebp
mov    $0x0,%ebp
jne    1340 <main+0x160>
movzbl 0x2cba(%rip),%eax
xor    $0x1,%eax
add    %eax,%eax
jmp    1420 <main+0x240>
mov    0x2bbc(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc21(%rip),%rdi
jmp    1411 <main+0x231>
mov    0x2ba5(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc30(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%eax
add    $0x908,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b6f(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc22(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
jmp    1420 <main+0x240>
lea    0xc93(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    1420 <main+0x240>
mov    0x2b34(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc1b(%rip),%rdi
jmp    1499 <main+0x2b9>
mov    0x2b1d(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc30(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
jmp    1420 <main+0x240>

LLVM IR (-O0):
%struct.aiocb = type { i32, i8*, i32, i64, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64 }
@main.check_one = internal global i32 0
@_SC_ASYNCHRONOUS_IO = global i32 0
@.str = [27 x i8] c"/tmp/pts_aio_cancel_5_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/5-1.c Error at open(): %s\0A\00"
@errno = global i32 0
@.str.2 = [40 x i8] c"aio_cancel/5-1.c Error at malloc(): %s\0A\00"
@SIGEV_NONE = global i64 0
@.str.3 = [52 x i8] c"aio_cancel/5-1.c loop %d: Error at aio_write(): %s\0A\00"
@.str.4 = [44 x i8] c"aio_cancel/5-1.c Error at aio_cancel(): %s\0A\00"
@.str.5 = [43 x i8] c"aio_cancel/5-1.c Error at aio_error(): %s\0A\00"
@EINPROGRESS = global i32 0
@.str.6 = [34 x i8] c"aio_cancel/5-1.c aiocbp modified\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca [128 x %struct.aiocb*]
%5 = alloca [128 x i8*]
%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 %220
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 %220
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* %6
br label %38
38: ; preds = %114, %35
%39 = load i32, i32* %6
%40 = icmp slt i32 %39, 128
br i1 %40, label %41, label %117
41: ; preds = %38
%42 = call %struct.aiocb* @calloc(i32 1, i32 40)
%43 = load i32, i32* %6
%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* %6
%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 %220
55: ; preds = %41
%56 = call i8* @malloc(i32 1024)
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [128 x i8*], [128 x i8*]* %5, i64 0, i64 %58
store i8* %56, i8** %59
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [128 x i8*], [128 x i8*]* %5, i64 0, i64 %61
%63 = load i8*, i8** %62
%64 = icmp eq i8* %63, null
br i1 %64, label %65, label %69
65: ; preds = %55
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %67)
store i32 2, i32* %1
br label %220
69: ; preds = %55
%70 = load i32, i32* %3
%71 = load i32, i32* %6
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %72
%74 = load %struct.aiocb*, %struct.aiocb** %73
%75 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %74, i32 0, i32 0
store i32 %70, i32* %75
%76 = load i32, i32* %6
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [128 x i8*], [128 x i8*]* %5, i64 0, i64 %77
%79 = load i8*, i8** %78
%80 = load i32, i32* %6
%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 i8* %79, i8** %84
%85 = load i32, i32* %6
%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 2
store i32 1024, i32* %89
%90 = load i32, i32* %6
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %91
%93 = load %struct.aiocb*, %struct.aiocb** %92
%94 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %93, i32 0, i32 3
store i64 0, i64* %94
%95 = load i64, i64* @SIGEV_NONE
%96 = load i32, i32* %6
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %97
%99 = load %struct.aiocb*, %struct.aiocb** %98
%100 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %99, i32 0, i32 4
%101 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %100, i32 0, i32 0
store i64 %95, i64* %101
%102 = load i32, i32* %6
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %103
%105 = load %struct.aiocb*, %struct.aiocb** %104
%106 = call i32 @aio_write(%struct.aiocb* %105)
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %113
108: ; preds = %69
%109 = load i32, i32* %6
%110 = load i32, i32* @errno
%111 = call i8* @strerror(i32 %110)
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0), i32 %109, i8* %111)
store i32 1, i32* %1
br label %220
113: ; preds = %69
br label %114
114: ; preds = %113
%115 = load i32, i32* %6
%116 = add nsw i32 %115, 1
store i32 %116, i32* %6
br label %38
117: ; preds = %38
%118 = load i32, i32* %3
%119 = call i32 @aio_cancel(i32 %118, i32* null)
%120 = icmp eq i32 %119, -1
br i1 %120, label %121, label %125
121: ; preds = %117
%122 = load i32, i32* @errno
%123 = call i8* @strerror(i32 %122)
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i8* %123)
store i32 1, i32* %1
br label %220
125: ; preds = %117
%126 = load i32, i32* %3
%127 = call i32 @close(i32 %126)
store i32 0, i32* @main.check_one
br label %128
128: ; preds = %212, %125
store i32 0, i32* %7
store i32 0, i32* %6
br label %129
129: ; preds = %208, %128
%130 = load i32, i32* %6
%131 = icmp slt i32 %130, 128
br i1 %131, label %132, label %211
132: ; preds = %129
%133 = load i32, i32* %6
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %134
%136 = load %struct.aiocb*, %struct.aiocb** %135
%137 = call i32 @aio_error(%struct.aiocb* %136)
store i32 %137, i32* %8
%138 = load i32, i32* %8
%139 = icmp eq i32 %138, -1
br i1 %139, label %140, label %144
140: ; preds = %132
%141 = load i32, i32* @errno
%142 = call i8* @strerror(i32 %141)
%143 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i8* %142)
store i32 1, i32* %1
br label %220
144: ; preds = %132
%145 = load i32, i32* %8
%146 = load i32, i32* @EINPROGRESS
%147 = icmp eq i32 %145, %146
br i1 %147, label %151, label %148
148: ; preds = %144
%149 = load i32, i32* %8
%150 = icmp eq i32 %149, 0
br i1 %150, label %151, label %206
151: ; preds = %148, %144
%152 = load i32, i32* %8
%153 = load i32, i32* @EINPROGRESS
%154 = icmp eq i32 %152, %153
br i1 %154, label %155, label %156
155: ; preds = %151
store i32 1, i32* %7
br label %156
156: ; preds = %155, %151
store i32 1, i32* @main.check_one
%157 = load i32, i32* %6
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %158
%160 = load %struct.aiocb*, %struct.aiocb** %159
%161 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %160, i32 0, i32 0
%162 = load i32, i32* %161
%163 = load i32, i32* %3
%164 = icmp ne i32 %162, %163
br i1 %164, label %203, label %165
165: ; preds = %156
%166 = load i32, i32* %6
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %167
%169 = load %struct.aiocb*, %struct.aiocb** %168
%170 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %169, i32 0, i32 1
%171 = load i8*, i8** %170
%172 = load i32, i32* %6
%173 = sext i32 %172 to i64
%174 = getelementptr inbounds [128 x i8*], [128 x i8*]* %5, i64 0, i64 %173
%175 = load i8*, i8** %174
%176 = icmp ne i8* %171, %175
br i1 %176, label %203, label %177
177: ; preds = %165
%178 = load i32, i32* %6
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %179
%181 = load %struct.aiocb*, %struct.aiocb** %180
%182 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %181, i32 0, i32 2
%183 = load i32, i32* %182
%184 = icmp ne i32 %183, 1024
br i1 %184, label %203, label %185
185: ; preds = %177
%186 = load i32, i32* %6
%187 = sext i32 %186 to i64
%188 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %187
%189 = load %struct.aiocb*, %struct.aiocb** %188
%190 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %189, i32 0, i32 3
%191 = load i64, i64* %190
%192 = icmp ne i64 %191, 0
br i1 %192, label %203, label %193
193: ; preds = %185
%194 = load i32, i32* %6
%195 = sext i32 %194 to i64
%196 = getelementptr inbounds [128 x %struct.aiocb*], [128 x %struct.aiocb*]* %4, i64 0, i64 %195
%197 = load %struct.aiocb*, %struct.aiocb** %196
%198 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %197, i32 0, i32 4
%199 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %198, i32 0, i32 0
%200 = load i64, i64* %199
%201 = load i64, i64* @SIGEV_NONE
%202 = icmp ne i64 %200, %201
br i1 %202, label %203, label %205
203: ; preds = %193, %185, %177, %165, %156
%204 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %220
205: ; preds = %193
br label %206
206: ; preds = %205, %148
br label %207
207: ; preds = %206
br label %208
208: ; preds = %207
%209 = load i32, i32* %6
%210 = add nsw i32 %209, 1
store i32 %210, i32* %6
br label %129
211: ; preds = %129
br label %212
212: ; preds = %211
%213 = load i32, i32* %7
%214 = icmp ne i32 %213, 0
br i1 %214, label %128, label %215
215: ; preds = %212
%216 = load i32, i32* @main.check_one
%217 = icmp ne i32 %216, 0
br i1 %217, label %219, label %218
218: ; preds = %215
store i32 2, i32* %1
br label %220
219: ; preds = %215
store i32 0, i32* %1
br label %220
220: ; preds = %219, %218, %203, %140, %121, %108, %65, %51, %31, %12
%221 = load i32, i32* %1
ret i32 %221
}

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