#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;
};

/* Variables and functions */
int EAGAIN;
int O_CREAT;
int O_EXCL;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ _SC_AIO_MAX;
int /*<<< orphan*/ _SC_ASYNCHRONOUS_IO;
int aio_error(struct aiocb *);
int aio_read(struct aiocb *);
int aio_return(struct aiocb *);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int getpid();
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);
int sysconf(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int write(int, char *, int);
int main(void) {
  char tmpfname[256];
  char buf[512];
  int fd;
  int i;
  struct aiocb aiocbs[1024];
  int last_req;
  int err;
  int ret;
  if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L || sysconf(_SC_AIO_MAX) == -1)
    return 4;
  snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_write_4_1_%d", getpid());
  unlink(tmpfname);
  fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    printf("aio_read/9-1.c"
           " Error at open(): %s\n",
           strerror(errno));
    exit(2);
  }
  unlink(tmpfname);
  if (write(fd, buf, 512) != 512) {
    printf("aio_read/9-1.c"
           " Error at write(): %s\n",
           strerror(errno));
    close(fd);
    exit(2);
  }
  for (i = 0; i < 1024; i++) {
    memset(&aiocbs[i], 0, sizeof(struct aiocb));
    aiocbs[i].aio_fildes = fd;
    aiocbs[i].aio_buf = buf;
    aiocbs[i].aio_nbytes = 512;
    last_req = i + 1;
    ret = aio_read(&aiocbs[i]);
    if (ret == -1)
      break;
  }
  for (i = 0; i < last_req - 1; i++) {
    err = aio_error(&aiocbs[i]);
    ret = aio_return(&aiocbs[i]);
  }
  if (last_req == 1024) {
    printf("aio_read/9-1.c"
           " Could not fail queuing %d request\n",
           1024);
    close(fd);
    exit(2);
  }
  printf("Failed at %d\n", last_req);
  if ((ret != -1) && (errno != EAGAIN)) {
    printf("aio_read/9-1.c"
           " failed with code %d: %s\n",
           errno, strerror(errno));
    close(fd);
    exit(1);
  }
  printf("aio_read/9-1.c"
         " PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x6340,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   10e0 <sysconf@plt>
cltq
cmp    $0x30db0,%rax
jl     1225 <main+0x45>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   10e0 <sysconf@plt>
cmp    $0xffffffff,%eax
jne    1231 <main+0x51>
movl   $0x4,-0x4(%rbp)
jmp    1575 <main+0x395>
lea    -0x110(%rbp),%rax
mov    %rax,-0x6338(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x6338(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xda5(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
mov    0x2d5d(%rip),%rax
or     (%rax),%esi
mov    0x2d2c(%rip),%rax
or     (%rax),%esi
mov    0x2d13(%rip),%rax
mov    (%rax),%edx
mov    0x2d32(%rip),%rax
or     (%rax),%edx
call   10d0 <open@plt>
mov    %eax,-0x314(%rbp)
cmpl   $0xffffffff,-0x314(%rbp)
jne    12e1 <main+0x101>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2,%edi
call   10f0 <exit@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x314(%rbp),%edi
lea    -0x310(%rbp),%rsi
mov    $0x200,%edx
call   1040 <write@plt>
cmp    $0x200,%eax
je     1343 <main+0x163>
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    %rax,%rsi
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x314(%rbp),%edi
call   1090 <close@plt>
mov    $0x2,%edi
call   10f0 <exit@plt>
movl   $0x0,-0x318(%rbp)
cmpl   $0x400,-0x318(%rbp)
jge    1431 <main+0x251>
movslq -0x318(%rbp),%rax
lea    -0x6320(%rbp),%rdi
imul   $0x18,%rax,%rax
add    %rax,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    -0x314(%rbp),%ecx
movslq -0x318(%rbp),%rdx
lea    -0x6320(%rbp),%rax
imul   $0x18,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,(%rax)
lea    -0x310(%rbp),%rcx
movslq -0x318(%rbp),%rdx
lea    -0x6320(%rbp),%rax
imul   $0x18,%rdx,%rdx
add    %rdx,%rax
mov    %rcx,0x8(%rax)
movslq -0x318(%rbp),%rcx
lea    -0x6320(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movl   $0x200,0x10(%rax)
mov    -0x318(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6324(%rbp)
movslq -0x318(%rbp),%rax
lea    -0x6320(%rbp),%rdi
imul   $0x18,%rax,%rax
add    %rax,%rdi
call   10a0 <aio_read@plt>
mov    %eax,-0x632c(%rbp)
cmpl   $0xffffffff,-0x632c(%rbp)
jne    1418 <main+0x238>
jmp    1431 <main+0x251>
jmp    141d <main+0x23d>
mov    -0x318(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x318(%rbp)
jmp    134d <main+0x16d>
movl   $0x0,-0x318(%rbp)
mov    -0x318(%rbp),%eax
mov    -0x6324(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    14a6 <main+0x2c6>
movslq -0x318(%rbp),%rax
lea    -0x6320(%rbp),%rdi
imul   $0x18,%rax,%rax
add    %rax,%rdi
call   10b0 <aio_error@plt>
mov    %eax,-0x6328(%rbp)
movslq -0x318(%rbp),%rax
lea    -0x6320(%rbp),%rdi
imul   $0x18,%rax,%rax
add    %rax,%rdi
call   10c0 <aio_return@plt>
mov    %eax,-0x632c(%rbp)
mov    -0x318(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x318(%rbp)
jmp    143b <main+0x25b>
cmpl   $0x400,-0x6324(%rbp)
jne    14de <main+0x2fe>
lea    0xba6(%rip),%rdi
mov    $0x400,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x314(%rbp),%edi
call   1090 <close@plt>
mov    $0x2,%edi
call   10f0 <exit@plt>
mov    -0x6324(%rbp),%esi
lea    0xbaa(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0xffffffff,-0x632c(%rbp)
je     1560 <main+0x380>
mov    0x2aaa(%rip),%rax
mov    (%rax),%eax
mov    0x2a89(%rip),%rcx
cmp    (%rcx),%eax
je     1560 <main+0x380>
mov    0x2a92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x633c(%rbp)
mov    0x2a83(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x633c(%rbp),%esi
mov    %rax,%rdx
lea    0xb5f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x314(%rbp),%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xb64(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x6340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x6300,%rsp
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   10f0 <sysconf@plt>
mov    $0x4,%ebx
cmp    $0x30db0,%eax
jl     13a1 <main+0x1b1>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   10f0 <sysconf@plt>
cmp    $0xffffffff,%eax
je     13a1 <main+0x1b1>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xdbe(%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    0x2d95(%rip),%rax
mov    0x2d76(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d43(%rip),%rax
or     (%rax),%esi
mov    0x2d2a(%rip),%rax
mov    0x2d4b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     13d6 <main+0x1e6>
mov    %eax,%r15d
mov    %rsp,%rdi
call   1030 <unlink@plt>
lea    0x100(%rsp),%rbx
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1050 <write@plt>
cmp    $0x200,%eax
jne    13ff <main+0x20f>
lea    0x300(%rsp),%rbp
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%r12
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1090 <memset@plt>
mov    %r15d,0x0(%rbp)
mov    %rbx,0x8(%rbp)
movl   $0x200,0x10(%rbp)
mov    %rbp,%rdi
call   10b0 <aio_read@plt>
cmp    $0xffffffff,%eax
je     1327 <main+0x137>
lea    0x1(%r12),%rax
add    $0x18,%rbp
cmp    $0x400,%rax
jne    12e0 <main+0xf0>
mov    $0x400,%r14d
jmp    1335 <main+0x145>
lea    0x1(%r12),%r14
test   %r12d,%r12d
je     13b3 <main+0x1c3>
lea    0x300(%rsp),%rbx
nopl   (%rax)
mov    %rbx,%rdi
call   10c0 <aio_error@plt>
mov    %rbx,%rdi
call   10d0 <aio_return@plt>
add    $0x18,%rbx
add    $0xffffffffffffffff,%r12
jne    1340 <main+0x150>
mov    %eax,%ebp
cmp    $0x400,%r14d
je     13c1 <main+0x1d1>
lea    0xd29(%rip),%rdi
xor    %ebx,%ebx
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0xffffffff,%ebp
je     1395 <main+0x1a5>
mov    0x2c2c(%rip),%rax
mov    (%rax),%ebp
mov    0x2c0b(%rip),%rax
cmp    (%rax),%ebp
jne    1430 <main+0x240>
lea    0xd2f(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x6300,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%ebp
cmp    $0x400,%r14d
jne    1365 <main+0x175>
lea    0xc9b(%rip),%rdi
mov    $0x400,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    141e <main+0x22e>
mov    0x2bd3(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc2f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%edi
call   1100 <exit@plt>
mov    0x2baa(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xc2a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    $0x2,%edi
call   1100 <exit@plt>
mov    %ebp,%edi
call   1110 <strerror@plt>
lea    0xc65(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.aiocb = type { i32, i8*, i32 }
@_SC_ASYNCHRONOUS_IO = global i32 0
@_SC_AIO_MAX = global i32 0
@.str = [26 x i8] c"/tmp/pts_aio_write_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 = [36 x i8] c"aio_read/9-1.c Error at open(): %s\0A\00"
@errno = global i32 0
@.str.2 = [37 x i8] c"aio_read/9-1.c Error at write(): %s\0A\00"
@.str.3 = [50 x i8] c"aio_read/9-1.c Could not fail queuing %d request\0A\00"
@.str.4 = [14 x i8] c"Failed at %d\0A\00"
@EAGAIN = global i32 0
@.str.5 = [40 x i8] c"aio_read/9-1.c failed with code %d: %s\0A\00"
@.str.6 = [23 x i8] c"aio_read/9-1.c PASSED\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca [512 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x %struct.aiocb]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
%10 = load i32, i32* @_SC_ASYNCHRONOUS_IO
%11 = call i32 @sysconf(i32 %10)
%12 = sext i32 %11 to i64
%13 = icmp slt i64 %12, 200112
br i1 %13, label %18, label %14
14: ; preds = %0
%15 = load i32, i32* @_SC_AIO_MAX
%16 = call i32 @sysconf(i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %14, %0
store i32 4, i32* %1
br label %137
19: ; preds = %14
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%21 = call i32 (...) @getpid()
%22 = call i32 @snprintf(i8* %20, i32 256, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%24 = call i32 @unlink(i8* %23)
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%26 = load i32, i32* @O_CREAT
%27 = load i32, i32* @O_RDWR
%28 = or i32 %26, %27
%29 = load i32, i32* @O_EXCL
%30 = or i32 %28, %29
%31 = load i32, i32* @S_IRUSR
%32 = load i32, i32* @S_IWUSR
%33 = or i32 %31, %32
%34 = call i32 @open(i8* %25, i32 %30, i32 %33)
store i32 %34, i32* %4
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %42
37: ; preds = %19
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %39)
%41 = call i32 @exit(i32 2)
unreachable
42: ; preds = %19
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%44 = call i32 @unlink(i8* %43)
%45 = load i32, i32* %4
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%47 = call i32 @write(i32 %45, i8* %46, i32 512)
%48 = icmp ne i32 %47, 512
br i1 %48, label %49, label %56
49: ; preds = %42
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = load i32, i32* %4
%54 = call i32 @close(i32 %53)
%55 = call i32 @exit(i32 2)
unreachable
56: ; preds = %42
store i32 0, i32* %5
br label %57
57: ; preds = %89, %56
%58 = load i32, i32* %5
%59 = icmp slt i32 %58, 1024
br i1 %59, label %60, label %92
60: ; preds = %57
%61 = load i32, i32* %5
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %6, i64 0, i64 %62
%64 = call i32 @memset(%struct.aiocb* %63, i32 0, i32 24)
%65 = load i32, i32* %4
%66 = load i32, i32* %5
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %6, i64 0, i64 %67
%69 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %68, i32 0, i32 0
store i32 %65, i32* %69
%70 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%71 = load i32, i32* %5
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %6, i64 0, i64 %72
%74 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %73, i32 0, i32 1
store i8* %70, i8** %74
%75 = load i32, i32* %5
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %6, i64 0, i64 %76
%78 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %77, i32 0, i32 2
store i32 512, i32* %78
%79 = load i32, i32* %5
%80 = add nsw i32 %79, 1
store i32 %80, i32* %7
%81 = load i32, i32* %5
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %6, i64 0, i64 %82
%84 = call i32 @aio_read(%struct.aiocb* %83)
store i32 %84, i32* %9
%85 = load i32, i32* %9
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %88
87: ; preds = %60
br label %92
88: ; preds = %60
br label %89
89: ; preds = %88
%90 = load i32, i32* %5
%91 = add nsw i32 %90, 1
store i32 %91, i32* %5
br label %57
92: ; preds = %87, %57
store i32 0, i32* %5
br label %93
93: ; preds = %107, %92
%94 = load i32, i32* %5
%95 = load i32, i32* %7
%96 = sub nsw i32 %95, 1
%97 = icmp slt i32 %94, %96
br i1 %97, label %98, label %110
98: ; preds = %93
%99 = load i32, i32* %5
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %6, i64 0, i64 %100
%102 = call i32 @aio_error(%struct.aiocb* %101)
store i32 %102, i32* %8
%103 = load i32, i32* %5
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %6, i64 0, i64 %104
%106 = call i32 @aio_return(%struct.aiocb* %105)
store i32 %106, i32* %9
br label %107
107: ; preds = %98
%108 = load i32, i32* %5
%109 = add nsw i32 %108, 1
store i32 %109, i32* %5
br label %93
110: ; preds = %93
%111 = load i32, i32* %7
%112 = icmp eq i32 %111, 1024
br i1 %112, label %113, label %118
113: ; preds = %110
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 1024)
%115 = load i32, i32* %4
%116 = call i32 @close(i32 %115)
%117 = call i32 @exit(i32 2)
unreachable
118: ; preds = %110
%119 = load i32, i32* %7
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %119)
%121 = load i32, i32* %9
%122 = icmp ne i32 %121, -1
br i1 %122, label %123, label %135
123: ; preds = %118
%124 = load i32, i32* @errno
%125 = load i32, i32* @EAGAIN
%126 = icmp ne i32 %124, %125
br i1 %126, label %127, label %135
127: ; preds = %123
%128 = load i32, i32* @errno
%129 = load i32, i32* @errno
%130 = call i8* @strerror(i32 %129)
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %128, i8* %130)
%132 = load i32, i32* %4
%133 = call i32 @close(i32 %132)
%134 = call i32 @exit(i32 1)
unreachable
135: ; preds = %123, %118
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %1
br label %137
137: ; preds = %135, %18
%138 = load i32, i32* %1
ret i32 %138
}

LLVM IR (-O2):
%struct.aiocb = type { i32, i8*, i32 }
@_SC_ASYNCHRONOUS_IO = global i32 0
@_SC_AIO_MAX = global i32 0
@.str = [26 x i8] c"/tmp/pts_aio_write_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 = [36 x i8] c"aio_read/9-1.c Error at open(): %s\0A\00"
@errno = global i32 0
@.str.2 = [37 x i8] c"aio_read/9-1.c Error at write(): %s\0A\00"
@.str.3 = [50 x i8] c"aio_read/9-1.c Could not fail queuing %d request\0A\00"
@.str.4 = [14 x i8] c"Failed at %d\0A\00"
@EAGAIN = global i32 0
@.str.5 = [40 x i8] c"aio_read/9-1.c failed with code %d: %s\0A\00"
@str = [22 x i8] c"aio_read/9-1.c PASSED\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca [512 x i8]
%3 = alloca [1024 x %struct.aiocb]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%6 = bitcast [1024 x %struct.aiocb]* %3 to i8*
%7 = load i32, i32* @_SC_ASYNCHRONOUS_IO
%8 = tail call i32 @sysconf(i32 %7)
%9 = icmp slt i32 %8, 200112
br i1 %9, label %91, label %10
10: ; preds = %0
%11 = load i32, i32* @_SC_AIO_MAX
%12 = tail call i32 @sysconf(i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %91, label %14
14: ; preds = %10
%15 = tail call i32 (...) @getpid()
%16 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32 @unlink(i8* %4)
%18 = load i32, i32* @O_CREAT
%19 = load i32, i32* @O_RDWR
%20 = or i32 %19, %18
%21 = load i32, i32* @O_EXCL
%22 = or i32 %20, %21
%23 = load i32, i32* @S_IRUSR
%24 = load i32, i32* @S_IWUSR
%25 = or i32 %24, %23
%26 = call i32 @open(i8* %4, i32 %22, i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %33
28: ; preds = %14
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 2)
unreachable
33: ; preds = %14
%34 = call i32 @unlink(i8* %4)
%35 = call i32 @write(i32 %26, i8* %5, i32 512)
%36 = icmp eq i32 %35, 512
br i1 %36, label %45, label %37
37: ; preds = %33
%38 = load i32, i32* @errno
%39 = call i8* @strerror(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = call i32 @close(i32 %26)
%42 = call i32 @exit(i32 2)
unreachable
43: ; preds = %45
%44 = icmp eq i64 %52, 1024
br i1 %44, label %59, label %45
45: ; preds = %33, %43
%46 = phi i64 [ %52, %43 ], [ 0, %33 ]
%47 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %3, i64 0, i64 %46
%48 = call i32 @memset(%struct.aiocb* %47, i32 0, i32 24)
%49 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %47, i64 0, i32 0
store i32 %26, i32* %49
%50 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %3, i64 0, i64 %46, i32 1
store i8* %5, i8** %50
%51 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %3, i64 0, i64 %46, i32 2
store i32 512, i32* %51
%52 = add nuw nsw i64 %46, 1
%53 = call i32 @aio_read(%struct.aiocb* %47)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %43
55: ; preds = %45
%56 = trunc i64 %52 to i32
%57 = trunc i64 %46 to i32
%58 = icmp eq i32 %57, 0
br i1 %58, label %69, label %59
59: ; preds = %43, %55
%60 = phi i32 [ %56, %55 ], [ 1024, %43 ]
%61 = and i64 %46, 4294967295
br label %62
62: ; preds = %59, %62
%63 = phi i64 [ 0, %59 ], [ %67, %62 ]
%64 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %3, i64 0, i64 %63
%65 = call i32 @aio_error(%struct.aiocb* %64)
%66 = call i32 @aio_return(%struct.aiocb* %64)
%67 = add nuw nsw i64 %63, 1
%68 = icmp eq i64 %67, %61
br i1 %68, label %69, label %62
69: ; preds = %62, %55
%70 = phi i32 [ %56, %55 ], [ %60, %62 ]
%71 = phi i32 [ -1, %55 ], [ %66, %62 ]
%72 = icmp eq i32 %70, 1024
br i1 %72, label %73, label %77
73: ; preds = %69
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i32 1024)
%75 = call i32 @close(i32 %26)
%76 = call i32 @exit(i32 2)
unreachable
77: ; preds = %69
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %70)
%79 = icmp eq i32 %71, -1
br i1 %79, label %89, label %80
80: ; preds = %77
%81 = load i32, i32* @errno
%82 = load i32, i32* @EAGAIN
%83 = icmp eq i32 %81, %82
br i1 %83, label %89, label %84
84: ; preds = %80
%85 = call i8* @strerror(i32 %81)
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %81, i8* %85)
%87 = call i32 @close(i32 %26)
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %80, %77
%90 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %91
91: ; preds = %0, %10, %89
%92 = phi i32 [ 0, %89 ], [ 4, %10 ], [ 4, %0 ]
ret i32 %92
}