#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ tmpfname;
struct aiocb {
  int aio_fildes;
  char *aio_buf;
  int aio_nbytes;
  int aio_lio_opcode;
  scalar_t__ aio_offset;
};

/* Variables and functions */
int EIO;
int LIO_NOP;
int LIO_READ;
int /*<<< orphan*/ LIO_WAIT;
int LIO_WRITE;
int O_CREAT;
int O_EXCL;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ _SC_ASYNCHRONOUS_IO;
int aio_error(struct aiocb *);
int aio_return(struct aiocb *);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(struct aiocb *);
int getpid();
int lio_listio(int /*<<< orphan*/, struct aiocb **, int, int /*<<< orphan*/ *);
struct aiocb *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);
long sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  char tmpfname[256];
  int fd;
  struct aiocb *aiocbs[3];
  char buf[1024];
  int errors = 0;
  int ret;
  int err;
  int i;
  if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L)
    exit(4);
  snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_4_1_%d", getpid());
  unlink(tmpfname);
  fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    printf("lio_listio/5-1.c"
           " Error at open(): %s\n",
           strerror(errno));
    exit(2);
  }
  unlink(tmpfname);
  for (i = 0; i < 3; i++) {
    aiocbs[i] = malloc(sizeof(struct aiocb));
    memset(aiocbs[i], 0, sizeof(struct aiocb));
    aiocbs[i]->aio_fildes = fd;
    aiocbs[i]->aio_offset = 0;
    aiocbs[i]->aio_buf = buf;
    aiocbs[i]->aio_nbytes = 1024;
    if (i == 0)
      aiocbs[i]->aio_lio_opcode = LIO_WRITE;
    else if (i == 1)
      aiocbs[i]->aio_lio_opcode = LIO_READ;
    else
      aiocbs[i]->aio_lio_opcode = LIO_NOP;
  }
  ret = lio_listio(LIO_WAIT, aiocbs, 3, NULL);
  if (ret) {
    printf("lio_listio/5-1.c"
           " lio_listio() does not accept valid opcodes\n");
    for (i = 0; i < 3; i++)
      free(aiocbs[i]);
    close(fd);
    exit(1);
  }
  for (i = 0; i < 3 - 1; i++) {
    err = aio_error(aiocbs[i]);
    ret = aio_return(aiocbs[i]);
    if ((err != 0) && (ret != 1024)) {
      printf("lio_listio/5-1.c"
             " req %d: error = %d - return = %d\n",
             i, err, ret);
      errors++;
    }
  }
  if (errors) {
    for (i = 0; i < 3; i++)
      free(aiocbs[i]);
    close(fd);
    exit(1);
  }
  aiocbs[0]->aio_lio_opcode = -1;
  if (lio_listio(LIO_WAIT, aiocbs, 1, NULL) != -1) {
    printf("lio_listio/5-1.c"
           " lio_listio() accepts invalid opcode\n");
    for (i = 0; i < 3; i++)
      free(aiocbs[i]);
    close(fd);
    exit(1);
  }
  if (errno != EIO) {
    printf("lio_listio/5-1.c"
           " lio_listio() sould set errno to EIO %d\n",
           errno);
    for (i = 0; i < 3; i++)
      free(aiocbs[i]);
    close(fd);
    exit(1);
  }
  for (i = 0; i < 3; i++)
    free(aiocbs[i]);
  close(fd);
  printf("Test PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x550,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x534(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   10e0 <sysconf@plt>
cmp    $0x30db0,%rax
jge    1230 <main+0x40>
mov    $0x4,%edi
call   1100 <exit@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x548(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x548(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xda6(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2d7f(%rip),%rax
mov    (%rax),%esi
mov    0x2d56(%rip),%rax
or     (%rax),%esi
mov    0x2d15(%rip),%rax
or     (%rax),%esi
mov    0x2cf4(%rip),%rax
mov    (%rax),%edx
mov    0x2d1b(%rip),%rax
or     (%rax),%edx
call   10d0 <open@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xffffffff,-0x114(%rbp)
jne    12e0 <main+0xf0>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2,%edi
call   1100 <exit@plt>
lea    -0x110(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x0,-0x540(%rbp)
cmpl   $0x3,-0x540(%rbp)
jge    142b <main+0x23b>
mov    $0x20,%edi
call   10b0 <malloc@plt>
mov    %rax,%rcx
movslq -0x540(%rbp),%rax
mov    %rcx,-0x130(%rbp,%rax,8)
ff
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rdi
ff
xor    %esi,%esi
mov    $0x20,%edx
call   1080 <memset@plt>
mov    -0x114(%rbp),%ecx
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rax
ff
mov    %ecx,(%rax)
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rax
ff
movq   $0x0,0x18(%rax)
lea    -0x530(%rbp),%rcx
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rax
ff
mov    %rcx,0x8(%rax)
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rax
ff
movl   $0x400,0x10(%rax)
cmpl   $0x0,-0x540(%rbp)
jne    13c5 <main+0x1d5>
mov    0x2c1c(%rip),%rax
mov    (%rax),%ecx
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rax
ff
mov    %ecx,0x14(%rax)
jmp    1412 <main+0x222>
cmpl   $0x1,-0x540(%rbp)
jne    13f2 <main+0x202>
mov    0x2bb7(%rip),%rax
mov    (%rax),%ecx
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rax
ff
mov    %ecx,0x14(%rax)
jmp    140d <main+0x21d>
mov    0x2bef(%rip),%rax
mov    (%rax),%ecx
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rax
ff
mov    %ecx,0x14(%rax)
jmp    1412 <main+0x222>
jmp    1417 <main+0x227>
mov    -0x540(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x540(%rbp)
jmp    12f6 <main+0x106>
mov    0x2b9e(%rip),%rax
mov    (%rax),%edi
lea    -0x130(%rbp),%rsi
mov    $0x3,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   10f0 <lio_listio@plt>
mov    %eax,-0x538(%rbp)
cmpl   $0x0,-0x538(%rbp)
je     14be <main+0x2ce>
lea    0xbde(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x540(%rbp)
cmpl   $0x3,-0x540(%rbp)
jge    14a9 <main+0x2b9>
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x540(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x540(%rbp)
jmp    1474 <main+0x284>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movl   $0x0,-0x540(%rbp)
cmpl   $0x2,-0x540(%rbp)
jge    156e <main+0x37e>
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rdi
ff
call   10a0 <aio_error@plt>
mov    %eax,-0x53c(%rbp)
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rdi
ff
call   10c0 <aio_return@plt>
mov    %eax,-0x538(%rbp)
cmpl   $0x0,-0x53c(%rbp)
je     1555 <main+0x365>
cmpl   $0x400,-0x538(%rbp)
je     1555 <main+0x365>
mov    -0x540(%rbp),%esi
mov    -0x53c(%rbp),%edx
mov    -0x538(%rbp),%ecx
lea    0xb3f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x534(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x534(%rbp)
jmp    155a <main+0x36a>
mov    -0x540(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x540(%rbp)
jmp    14c8 <main+0x2d8>
cmpl   $0x0,-0x534(%rbp)
je     15cf <main+0x3df>
movl   $0x0,-0x540(%rbp)
cmpl   $0x3,-0x540(%rbp)
jge    15ba <main+0x3ca>
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x540(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x540(%rbp)
jmp    1585 <main+0x395>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x130(%rbp),%rax
movl   $0xffffffff,0x14(%rax)
mov    0x29ec(%rip),%rax
mov    (%rax),%edi
lea    -0x130(%rbp),%rsi
mov    $0x1,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   10f0 <lio_listio@plt>
cmp    $0xffffffff,%eax
je     1666 <main+0x476>
lea    0xaa6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x540(%rbp)
cmpl   $0x3,-0x540(%rbp)
jge    1651 <main+0x461>
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x540(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x540(%rbp)
jmp    161c <main+0x42c>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x292b(%rip),%rax
mov    (%rax),%eax
mov    0x2932(%rip),%rcx
cmp    (%rcx),%eax
je     16e9 <main+0x4f9>
mov    0x2913(%rip),%rax
mov    (%rax),%esi
lea    0xa59(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x540(%rbp)
cmpl   $0x3,-0x540(%rbp)
jge    16d4 <main+0x4e4>
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x540(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x540(%rbp)
jmp    169f <main+0x4af>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movl   $0x0,-0x540(%rbp)
cmpl   $0x3,-0x540(%rbp)
jge    1728 <main+0x538>
movslq -0x540(%rbp),%rax
mov    -0x130(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x540(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x540(%rbp)
jmp    16f3 <main+0x503>
mov    -0x114(%rbp),%edi
call   1090 <close@plt>
lea    0x9e6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x550,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x528,%rsp
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   10f0 <sysconf@plt>
cmp    $0x30daf,%rax
jle    1481 <main+0x281>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xdcb(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %eax,%ecx
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <unlink@plt>
mov    0x2da0(%rip),%rax
mov    0x2d79(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d36(%rip),%rax
or     (%rax),%esi
mov    0x2d15(%rip),%rax
mov    0x2d3e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     148b <main+0x28b>
mov    %eax,%r15d
lea    0x20(%rsp),%rdi
call   1040 <unlink@plt>
mov    $0x20,%edi
call   10c0 <malloc@plt>
mov    %rax,(%rsp)
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1090 <memset@plt>
mov    (%rsp),%rax
mov    %r15d,(%rax)
movq   $0x0,0x18(%rax)
lea    0x120(%rsp),%rbp
mov    %rbp,0x8(%rax)
movl   $0x400,0x10(%rax)
mov    0x2ce6(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x14(%rax)
mov    $0x20,%edi
call   10c0 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1090 <memset@plt>
mov    0x8(%rsp),%rax
mov    %r15d,(%rax)
movq   $0x0,0x18(%rax)
mov    %rbp,0x8(%rax)
mov    0x8(%rsp),%rax
movl   $0x400,0x10(%rax)
mov    0x2c64(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x14(%rax)
mov    $0x20,%edi
call   10c0 <malloc@plt>
mov    %rax,0x10(%rsp)
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1090 <memset@plt>
mov    0x10(%rsp),%rax
mov    %r15d,(%rax)
movq   $0x0,0x18(%rax)
mov    %rbp,0x8(%rax)
mov    0x10(%rsp),%rax
movl   $0x400,0x10(%rax)
mov    0x2c72(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x14(%rax)
mov    0x2c4e(%rip),%r14
mov    (%r14),%edi
mov    %rsp,%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1100 <lio_listio@plt>
test   %eax,%eax
jne    14b4 <main+0x2b4>
mov    (%rsp),%rdi
call   10b0 <aio_error@plt>
mov    %eax,%ebp
mov    (%rsp),%rdi
call   10d0 <aio_return@plt>
test   %ebp,%ebp
setne  %cl
cmp    $0x400,%eax
setne  %bl
and    %cl,%bl
je     13d5 <main+0x1d5>
lea    0xc79(%rip),%rdi
xor    %esi,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%rsp),%rdi
call   10b0 <aio_error@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rdi
call   10d0 <aio_return@plt>
test   %ebp,%ebp
je     13fa <main+0x1fa>
cmp    $0x400,%eax
jne    14c2 <main+0x2c2>
test   %bl,%bl
jne    14f7 <main+0x2f7>
mov    (%rsp),%rax
movl   $0xffffffff,0x14(%rax)
mov    (%r14),%edi
mov    %rsp,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1100 <lio_listio@plt>
cmp    $0xffffffff,%eax
jne    14db <main+0x2db>
mov    0x2b69(%rip),%rax
mov    (%rax),%esi
mov    0x2b70(%rip),%rax
cmp    (%rax),%esi
jne    14e9 <main+0x2e9>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
lea    0xc41(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x528,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x4,%edi
call   1110 <exit@plt>
mov    0x2b06(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xb7b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%edi
call   1110 <exit@plt>
lea    0xc33(%rip),%rdi
call   1050 <puts@plt>
jmp    14f7 <main+0x2f7>
lea    0xb78(%rip),%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    14f7 <main+0x2f7>
lea    0xbd7(%rip),%rdi
call   1050 <puts@plt>
jmp    14f7 <main+0x2f7>
lea    0xb84(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    $0x1,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.aiocb = type { i32, i8*, i32, i32, i64 }
@_SC_ASYNCHRONOUS_IO = global i32 0
@.str = [27 x i8] c"/tmp/pts_lio_listio_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"lio_listio/5-1.c Error at open(): %s\0A\00"
@errno = global i32 0
@LIO_WRITE = global i32 0
@LIO_READ = global i32 0
@LIO_NOP = global i32 0
@LIO_WAIT = global i32 0
@.str.2 = [61 x i8] c"lio_listio/5-1.c lio_listio() does not accept valid opcodes\0A\00"
@.str.3 = [51 x i8] c"lio_listio/5-1.c req %d: error = %d - return = %d\0A\00"
@.str.4 = [54 x i8] c"lio_listio/5-1.c lio_listio() accepts invalid opcode\0A\00"
@EIO = global i32 0
@.str.5 = [57 x i8] c"lio_listio/5-1.c lio_listio() sould set errno to EIO %d\0A\00"
@.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 [3 x %struct.aiocb*]
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
%10 = load i32, i32* @_SC_ASYNCHRONOUS_IO
%11 = call i64 @sysconf(i32 %10)
%12 = icmp slt i64 %11, 200112
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @exit(i32 4)
unreachable
15: ; preds = %0
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%17 = call i32 (...) @getpid()
%18 = call i32 @snprintf(i8* %16, i32 256, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%20 = call i32 @unlink(i8* %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%22 = load i32, i32* @O_CREAT
%23 = load i32, i32* @O_RDWR
%24 = or i32 %22, %23
%25 = load i32, i32* @O_EXCL
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IRUSR
%28 = load i32, i32* @S_IWUSR
%29 = or i32 %27, %28
%30 = call i32 @open(i8* %21, i32 %26, i32 %29)
store i32 %30, i32* %3
%31 = load i32, i32* %3
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %38
33: ; preds = %15
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 2)
unreachable
38: ; preds = %15
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%40 = call i32 @unlink(i8* %39)
store i32 0, i32* %9
br label %41
41: ; preds = %104, %38
%42 = load i32, i32* %9
%43 = icmp slt i32 %42, 3
br i1 %43, label %44, label %107
44: ; preds = %41
%45 = call %struct.aiocb* @malloc(i32 32)
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 %47
store %struct.aiocb* %45, %struct.aiocb** %48
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 %50
%52 = load %struct.aiocb*, %struct.aiocb** %51
%53 = call i32 @memset(%struct.aiocb* %52, i32 0, i32 32)
%54 = load i32, i32* %3
%55 = load i32, i32* %9
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 %56
%58 = load %struct.aiocb*, %struct.aiocb** %57
%59 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %58, i32 0, i32 0
store i32 %54, i32* %59
%60 = load i32, i32* %9
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 %61
%63 = load %struct.aiocb*, %struct.aiocb** %62
%64 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %63, i32 0, i32 4
store i64 0, i64* %64
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%66 = load i32, i32* %9
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 %67
%69 = load %struct.aiocb*, %struct.aiocb** %68
%70 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %69, i32 0, i32 1
store i8* %65, i8** %70
%71 = load i32, i32* %9
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [3 x %struct.aiocb*], [3 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 2
store i32 1024, i32* %75
%76 = load i32, i32* %9
%77 = icmp eq i32 %76, 0
br i1 %77, label %78, label %85
78: ; preds = %44
%79 = load i32, i32* @LIO_WRITE
%80 = load i32, i32* %9
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [3 x %struct.aiocb*], [3 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 3
store i32 %79, i32* %84
br label %103
85: ; preds = %44
%86 = load i32, i32* %9
%87 = icmp eq i32 %86, 1
br i1 %87, label %88, label %95
88: ; preds = %85
%89 = load i32, i32* @LIO_READ
%90 = load i32, i32* %9
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [3 x %struct.aiocb*], [3 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 i32 %89, i32* %94
br label %102
95: ; preds = %85
%96 = load i32, i32* @LIO_NOP
%97 = load i32, i32* %9
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds [3 x %struct.aiocb*], [3 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 3
store i32 %96, i32* %101
br label %102
102: ; preds = %95, %88
br label %103
103: ; preds = %102, %78
br label %104
104: ; preds = %103
%105 = load i32, i32* %9
%106 = add nsw i32 %105, 1
store i32 %106, i32* %9
br label %41
107: ; preds = %41
%108 = load i32, i32* @LIO_WAIT
%109 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 0
%110 = call i32 @lio_listio(i32 %108, %struct.aiocb** %109, i32 3, i32* null)
store i32 %110, i32* %7
%111 = load i32, i32* %7
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %131
113: ; preds = %107
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %9
br label %115
115: ; preds = %124, %113
%116 = load i32, i32* %9
%117 = icmp slt i32 %116, 3
br i1 %117, label %118, label %127
118: ; preds = %115
%119 = load i32, i32* %9
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 %120
%122 = load %struct.aiocb*, %struct.aiocb** %121
%123 = call i32 @free(%struct.aiocb* %122)
br label %124
124: ; preds = %118
%125 = load i32, i32* %9
%126 = add nsw i32 %125, 1
store i32 %126, i32* %9
br label %115
127: ; preds = %115
%128 = load i32, i32* %3
%129 = call i32 @close(i32 %128)
%130 = call i32 @exit(i32 1)
unreachable
131: ; preds = %107
store i32 0, i32* %9
br label %132
132: ; preds = %159, %131
%133 = load i32, i32* %9
%134 = icmp slt i32 %133, 2
br i1 %134, label %135, label %162
135: ; preds = %132
%136 = load i32, i32* %9
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 %137
%139 = load %struct.aiocb*, %struct.aiocb** %138
%140 = call i32 @aio_error(%struct.aiocb* %139)
store i32 %140, i32* %8
%141 = load i32, i32* %9
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 %142
%144 = load %struct.aiocb*, %struct.aiocb** %143
%145 = call i32 @aio_return(%struct.aiocb* %144)
store i32 %145, i32* %7
%146 = load i32, i32* %8
%147 = icmp ne i32 %146, 0
br i1 %147, label %148, label %158
148: ; preds = %135
%149 = load i32, i32* %7
%150 = icmp ne i32 %149, 1024
br i1 %150, label %151, label %158
151: ; preds = %148
%152 = load i32, i32* %9
%153 = load i32, i32* %8
%154 = load i32, i32* %7
%155 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %152, i32 %153, i32 %154)
%156 = load i32, i32* %6
%157 = add nsw i32 %156, 1
store i32 %157, i32* %6
br label %158
158: ; preds = %151, %148, %135
br label %159
159: ; preds = %158
%160 = load i32, i32* %9
%161 = add nsw i32 %160, 1
store i32 %161, i32* %9
br label %132
162: ; preds = %132
%163 = load i32, i32* %6
%164 = icmp ne i32 %163, 0
br i1 %164, label %165, label %182
165: ; preds = %162
store i32 0, i32* %9
br label %166
166: ; preds = %175, %165
%167 = load i32, i32* %9
%168 = icmp slt i32 %167, 3
br i1 %168, label %169, label %178
169: ; preds = %166
%170 = load i32, i32* %9
%171 = sext i32 %170 to i64
%172 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 %171
%173 = load %struct.aiocb*, %struct.aiocb** %172
%174 = call i32 @free(%struct.aiocb* %173)
br label %175
175: ; preds = %169
%176 = load i32, i32* %9
%177 = add nsw i32 %176, 1
store i32 %177, i32* %9
br label %166
178: ; preds = %166
%179 = load i32, i32* %3
%180 = call i32 @close(i32 %179)
%181 = call i32 @exit(i32 1)
unreachable
182: ; preds = %162
%183 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 0
%184 = load %struct.aiocb*, %struct.aiocb** %183
%185 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %184, i32 0, i32 3
store i32 -1, i32* %185
%186 = load i32, i32* @LIO_WAIT
%187 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 0
%188 = call i32 @lio_listio(i32 %186, %struct.aiocb** %187, i32 1, i32* null)
%189 = icmp ne i32 %188, -1
br i1 %189, label %190, label %208
190: ; preds = %182
%191 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %9
br label %192
192: ; preds = %201, %190
%193 = load i32, i32* %9
%194 = icmp slt i32 %193, 3
br i1 %194, label %195, label %204
195: ; preds = %192
%196 = load i32, i32* %9
%197 = sext i32 %196 to i64
%198 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 %197
%199 = load %struct.aiocb*, %struct.aiocb** %198
%200 = call i32 @free(%struct.aiocb* %199)
br label %201
201: ; preds = %195
%202 = load i32, i32* %9
%203 = add nsw i32 %202, 1
store i32 %203, i32* %9
br label %192
204: ; preds = %192
%205 = load i32, i32* %3
%206 = call i32 @close(i32 %205)
%207 = call i32 @exit(i32 1)
unreachable
208: ; preds = %182
%209 = load i32, i32* @errno
%210 = load i32, i32* @EIO
%211 = icmp ne i32 %209, %210
br i1 %211, label %212, label %231
212: ; preds = %208
%213 = load i32, i32* @errno
%214 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0), i32 %213)
store i32 0, i32* %9
br label %215
215: ; preds = %224, %212
%216 = load i32, i32* %9
%217 = icmp slt i32 %216, 3
br i1 %217, label %218, label %227
218: ; preds = %215
%219 = load i32, i32* %9
%220 = sext i32 %219 to i64
%221 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 %220
%222 = load %struct.aiocb*, %struct.aiocb** %221
%223 = call i32 @free(%struct.aiocb* %222)
br label %224
224: ; preds = %218
%225 = load i32, i32* %9
%226 = add nsw i32 %225, 1
store i32 %226, i32* %9
br label %215
227: ; preds = %215
%228 = load i32, i32* %3
%229 = call i32 @close(i32 %228)
%230 = call i32 @exit(i32 1)
unreachable
231: ; preds = %208
store i32 0, i32* %9
br label %232
232: ; preds = %241, %231
%233 = load i32, i32* %9
%234 = icmp slt i32 %233, 3
br i1 %234, label %235, label %244
235: ; preds = %232
%236 = load i32, i32* %9
%237 = sext i32 %236 to i64
%238 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %4, i64 0, i64 %237
%239 = load %struct.aiocb*, %struct.aiocb** %238
%240 = call i32 @free(%struct.aiocb* %239)
br label %241
241: ; preds = %235
%242 = load i32, i32* %9
%243 = add nsw i32 %242, 1
store i32 %243, i32* %9
br label %232
244: ; preds = %232
%245 = load i32, i32* %3
%246 = call i32 @close(i32 %245)
%247 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.aiocb = type { i32, i8*, i32, i32, i64 }
@_SC_ASYNCHRONOUS_IO = global i32 0
@.str = [27 x i8] c"/tmp/pts_lio_listio_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"lio_listio/5-1.c Error at open(): %s\0A\00"
@errno = global i32 0
@LIO_WRITE = global i32 0
@LIO_READ = global i32 0
@LIO_NOP = global i32 0
@LIO_WAIT = global i32 0
@.str.3 = [51 x i8] c"lio_listio/5-1.c req %d: error = %d - return = %d\0A\00"
@EIO = global i32 0
@.str.5 = [57 x i8] c"lio_listio/5-1.c lio_listio() sould set errno to EIO %d\0A\00"
@str = [12 x i8] c"Test PASSED\00"
@str.7 = [53 x i8] c"lio_listio/5-1.c lio_listio() accepts invalid opcode\00"
@str.8 = [60 x i8] c"lio_listio/5-1.c lio_listio() does not accept valid opcodes\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca [3 x %struct.aiocb*]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%5 = bitcast [3 x %struct.aiocb*]* %2 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @_SC_ASYNCHRONOUS_IO
%8 = tail call i64 @sysconf(i32 %7)
%9 = icmp slt i64 %8, 200112
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = tail call i32 @exit(i32 4)
unreachable
12: ; preds = %0
%13 = tail call i32 (...) @getpid()
%14 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @unlink(i8* %4)
%16 = load i32, i32* @O_CREAT
%17 = load i32, i32* @O_RDWR
%18 = or i32 %17, %16
%19 = load i32, i32* @O_EXCL
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IRUSR
%22 = load i32, i32* @S_IWUSR
%23 = or i32 %22, %21
%24 = call i32 @open(i8* %4, i32 %20, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %12
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 2)
unreachable
31: ; preds = %12
%32 = call i32 @unlink(i8* %4)
%33 = call %struct.aiocb* @malloc(i32 32)
%34 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %2, i64 0, i64 0
store %struct.aiocb* %33, %struct.aiocb** %34
%35 = call i32 @memset(%struct.aiocb* %33, i32 0, i32 32)
%36 = load %struct.aiocb*, %struct.aiocb** %34
%37 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %36, i64 0, i32 0
store i32 %24, i32* %37
%38 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %36, i64 0, i32 4
store i64 0, i64* %38
%39 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %36, i64 0, i32 1
store i8* %6, i8** %39
%40 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %36, i64 0, i32 2
store i32 1024, i32* %40
%41 = load i32, i32* @LIO_WRITE
%42 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %36, i64 0, i32 3
store i32 %41, i32* %42
%43 = call %struct.aiocb* @malloc(i32 32)
%44 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %2, i64 0, i64 1
store %struct.aiocb* %43, %struct.aiocb** %44
%45 = call i32 @memset(%struct.aiocb* %43, i32 0, i32 32)
%46 = load %struct.aiocb*, %struct.aiocb** %44
%47 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %46, i64 0, i32 0
store i32 %24, i32* %47
%48 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %46, i64 0, i32 4
store i64 0, i64* %48
%49 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %46, i64 0, i32 1
store i8* %6, i8** %49
%50 = load %struct.aiocb*, %struct.aiocb** %44
%51 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %50, i64 0, i32 2
store i32 1024, i32* %51
%52 = load i32, i32* @LIO_READ
%53 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %50, i64 0, i32 3
store i32 %52, i32* %53
%54 = call %struct.aiocb* @malloc(i32 32)
%55 = getelementptr inbounds [3 x %struct.aiocb*], [3 x %struct.aiocb*]* %2, i64 0, i64 2
store %struct.aiocb* %54, %struct.aiocb** %55
%56 = call i32 @memset(%struct.aiocb* %54, i32 0, i32 32)
%57 = load %struct.aiocb*, %struct.aiocb** %55
%58 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %57, i64 0, i32 0
store i32 %24, i32* %58
%59 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %57, i64 0, i32 4
store i64 0, i64* %59
%60 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %57, i64 0, i32 1
store i8* %6, i8** %60
%61 = load %struct.aiocb*, %struct.aiocb** %55
%62 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %61, i64 0, i32 2
store i32 1024, i32* %62
%63 = load i32, i32* @LIO_NOP
%64 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %61, i64 0, i32 3
store i32 %63, i32* %64
%65 = load i32, i32* @LIO_WAIT
%66 = call i32 @lio_listio(i32 %65, %struct.aiocb** %34, i32 3, i32* null)
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %76
68: ; preds = %31
%69 = load %struct.aiocb*, %struct.aiocb** %34
%70 = call i32 @aio_error(%struct.aiocb* %69)
%71 = load %struct.aiocb*, %struct.aiocb** %34
%72 = call i32 @aio_return(%struct.aiocb* %71)
%73 = icmp ne i32 %70, 0
%74 = icmp ne i32 %72, 1024
%75 = select i1 %73, i1 %74, i1 false
br i1 %75, label %86, label %88
76: ; preds = %31
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.8, i64 0, i64 0))
%78 = load %struct.aiocb*, %struct.aiocb** %34
%79 = call i32 @free(%struct.aiocb* %78)
%80 = load %struct.aiocb*, %struct.aiocb** %44
%81 = call i32 @free(%struct.aiocb* %80)
%82 = load %struct.aiocb*, %struct.aiocb** %55
%83 = call i32 @free(%struct.aiocb* %82)
%84 = call i32 @close(i32 %24)
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %68
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 %70, i32 %72)
br label %88
88: ; preds = %68, %86
%89 = load %struct.aiocb*, %struct.aiocb** %44
%90 = call i32 @aio_error(%struct.aiocb* %89)
%91 = load %struct.aiocb*, %struct.aiocb** %44
%92 = call i32 @aio_return(%struct.aiocb* %91)
%93 = icmp ne i32 %90, 0
%94 = icmp ne i32 %92, 1024
%95 = select i1 %93, i1 %94, i1 false
br i1 %95, label %96, label %98
96: ; preds = %88
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 %90, i32 %92)
br label %99
98: ; preds = %88
br i1 %75, label %99, label %108
99: ; preds = %96, %98
%100 = load %struct.aiocb*, %struct.aiocb** %34
%101 = call i32 @free(%struct.aiocb* %100)
%102 = load %struct.aiocb*, %struct.aiocb** %44
%103 = call i32 @free(%struct.aiocb* %102)
%104 = load %struct.aiocb*, %struct.aiocb** %55
%105 = call i32 @free(%struct.aiocb* %104)
%106 = call i32 @close(i32 %24)
%107 = call i32 @exit(i32 1)
unreachable
108: ; preds = %98
%109 = load %struct.aiocb*, %struct.aiocb** %34
%110 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %109, i64 0, i32 3
store i32 -1, i32* %110
%111 = load i32, i32* @LIO_WAIT
%112 = call i32 @lio_listio(i32 %111, %struct.aiocb** %34, i32 1, i32* null)
%113 = icmp eq i32 %112, -1
br i1 %113, label %124, label %114
114: ; preds = %108
%115 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.7, i64 0, i64 0))
%116 = load %struct.aiocb*, %struct.aiocb** %34
%117 = call i32 @free(%struct.aiocb* %116)
%118 = load %struct.aiocb*, %struct.aiocb** %44
%119 = call i32 @free(%struct.aiocb* %118)
%120 = load %struct.aiocb*, %struct.aiocb** %55
%121 = call i32 @free(%struct.aiocb* %120)
%122 = call i32 @close(i32 %24)
%123 = call i32 @exit(i32 1)
unreachable
124: ; preds = %108
%125 = load i32, i32* @errno
%126 = load i32, i32* @EIO
%127 = icmp eq i32 %125, %126
br i1 %127, label %128, label %137
128: ; preds = %124
%129 = load %struct.aiocb*, %struct.aiocb** %34
%130 = call i32 @free(%struct.aiocb* %129)
%131 = load %struct.aiocb*, %struct.aiocb** %44
%132 = call i32 @free(%struct.aiocb* %131)
%133 = load %struct.aiocb*, %struct.aiocb** %55
%134 = call i32 @free(%struct.aiocb* %133)
%135 = call i32 @close(i32 %24)
%136 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
ret i32 0
137: ; preds = %124
%138 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0), i32 %125)
%139 = load %struct.aiocb*, %struct.aiocb** %34
%140 = call i32 @free(%struct.aiocb* %139)
%141 = load %struct.aiocb*, %struct.aiocb** %44
%142 = call i32 @free(%struct.aiocb* %141)
%143 = load %struct.aiocb*, %struct.aiocb** %55
%144 = call i32 @free(%struct.aiocb* %143)
%145 = call i32 @close(i32 %24)
%146 = call i32 @exit(i32 1)
unreachable
}