#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_return(struct aiocb *);
int aio_write(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 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_write/7-1.c"
           " Error at open(): %s\n",
           strerror(errno));
    exit(2);
  }
  unlink(tmpfname);
  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_write(&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_write/7-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_write/7-1.c"
           " failed with code %d: %s\n",
           errno, strerror(errno));
    close(fd);
    exit(1);
  }
  printf("aio_write/7-1.c"
         " PASSED\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x6340,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   10d0 <sysconf@plt>
cltq
cmp    $0x30db0,%rax
jl     1215 <main+0x45>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   10d0 <sysconf@plt>
cmp    $0xffffffff,%eax
jne    1221 <main+0x51>
movl   $0x4,-0x4(%rbp)
jmp    150f <main+0x33f>
lea    -0x110(%rbp),%rax
mov    %rax,-0x6338(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x6338(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xdb5(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x110(%rbp),%rdi
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
mov    0x2d6d(%rip),%rax
or     (%rax),%esi
mov    0x2d3c(%rip),%rax
or     (%rax),%esi
mov    0x2d23(%rip),%rax
mov    (%rax),%edx
mov    0x2d42(%rip),%rax
or     (%rax),%edx
call   10c0 <open@plt>
mov    %eax,-0x314(%rbp)
cmpl   $0xffffffff,-0x314(%rbp)
jne    12d1 <main+0x101>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rsi
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
lea    -0x110(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x318(%rbp)
cmpl   $0x400,-0x318(%rbp)
jge    13cb <main+0x1fb>
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   1050 <aio_write@plt>
mov    %eax,-0x632c(%rbp)
cmpl   $0xffffffff,-0x632c(%rbp)
jne    13b2 <main+0x1e2>
jmp    13cb <main+0x1fb>
jmp    13b7 <main+0x1e7>
mov    -0x318(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x318(%rbp)
jmp    12e7 <main+0x117>
movl   $0x0,-0x318(%rbp)
mov    -0x318(%rbp),%eax
mov    -0x6324(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1440 <main+0x270>
movslq -0x318(%rbp),%rax
lea    -0x6320(%rbp),%rdi
imul   $0x18,%rax,%rax
add    %rax,%rdi
call   10a0 <aio_error@plt>
mov    %eax,-0x6328(%rbp)
movslq -0x318(%rbp),%rax
lea    -0x6320(%rbp),%rdi
imul   $0x18,%rax,%rax
add    %rax,%rdi
call   10b0 <aio_return@plt>
mov    %eax,-0x632c(%rbp)
mov    -0x318(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x318(%rbp)
jmp    13d5 <main+0x205>
cmpl   $0x400,-0x6324(%rbp)
jne    1478 <main+0x2a8>
lea    0xbe8(%rip),%rdi
mov    $0x400,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x314(%rbp),%edi
call   1090 <close@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
mov    -0x6324(%rbp),%esi
lea    0xbed(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0xffffffff,-0x632c(%rbp)
je     14fa <main+0x32a>
mov    0x2b10(%rip),%rax
mov    (%rax),%eax
mov    0x2aef(%rip),%rcx
cmp    (%rcx),%eax
je     14fa <main+0x32a>
mov    0x2af8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x633c(%rbp)
mov    0x2ae9(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x633c(%rbp),%esi
mov    %rax,%rdx
lea    0xba2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x314(%rbp),%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xba8(%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    0x2de2(%rip),%rax
mov    (%rax),%edi
call   10e0 <sysconf@plt>
mov    $0x4,%ebp
cmp    $0x30db0,%eax
jl     136f <main+0x18f>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
call   10e0 <sysconf@plt>
cmp    $0xffffffff,%eax
je     136f <main+0x18f>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xdce(%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    0x2da5(%rip),%rax
mov    0x2d86(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d53(%rip),%rax
or     (%rax),%esi
mov    0x2d3a(%rip),%rax
mov    0x2d5b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbx,%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     13b5 <main+0x1d5>
mov    %eax,%r15d
mov    %rsp,%rdi
call   1030 <unlink@plt>
lea    0x300(%rsp),%rbp
xor    %eax,%eax
lea    0x100(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %rax,%rbx
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1090 <memset@plt>
mov    %r15d,0x0(%rbp)
mov    %r14,0x8(%rbp)
movl   $0x200,0x10(%rbp)
mov    %rbp,%rdi
call   1060 <aio_write@plt>
cmp    $0xffffffff,%eax
je     12f6 <main+0x116>
lea    0x1(%rbx),%rax
add    $0x18,%rbp
cmp    $0x400,%rax
jne    12b0 <main+0xd0>
mov    $0x400,%r14d
jmp    1302 <main+0x122>
lea    0x1(%rbx),%r14
test   %ebx,%ebx
je     1381 <main+0x1a1>
lea    0x300(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   10b0 <aio_error@plt>
mov    %rbp,%rdi
call   10c0 <aio_return@plt>
add    $0x18,%rbp
add    $0xffffffffffffffff,%rbx
jne    1310 <main+0x130>
mov    %eax,%r12d
cmp    $0x400,%r14d
je     1390 <main+0x1b0>
lea    0xd35(%rip),%rdi
xor    %ebp,%ebp
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0xffffffff,%r12d
je     1363 <main+0x183>
mov    0x2c5a(%rip),%rax
mov    (%rax),%ebx
mov    0x2c39(%rip),%rax
cmp    (%rax),%ebx
jne    13de <main+0x1fe>
lea    0xd3f(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%eax
add    $0x6300,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%r12d
cmp    $0x400,%r14d
jne    1336 <main+0x156>
lea    0xca8(%rip),%rdi
mov    $0x400,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    $0x2,%edi
call   10f0 <exit@plt>
mov    0x2bf4(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc50(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%edi
call   10f0 <exit@plt>
mov    %ebx,%edi
call   1100 <strerror@plt>
lea    0xc94(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    $0x1,%edi
call   10f0 <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 = [37 x i8] c"aio_write/7-1.c Error at open(): %s\0A\00"
@errno = global i32 0
@.str.2 = [51 x i8] c"aio_write/7-1.c Could not fail queuing %d request\0A\00"
@.str.3 = [14 x i8] c"Failed at %d\0A\00"
@EAGAIN = global i32 0
@.str.4 = [41 x i8] c"aio_write/7-1.c failed with code %d: %s\0A\00"
@.str.5 = [24 x i8] c"aio_write/7-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 %125
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 ([37 x i8], [37 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)
store i32 0, i32* %5
br label %45
45: ; preds = %77, %42
%46 = load i32, i32* %5
%47 = icmp slt i32 %46, 1024
br i1 %47, label %48, label %80
48: ; preds = %45
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %6, i64 0, i64 %50
%52 = call i32 @memset(%struct.aiocb* %51, i32 0, i32 24)
%53 = load i32, i32* %4
%54 = load i32, i32* %5
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %6, i64 0, i64 %55
%57 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %56, i32 0, i32 0
store i32 %53, i32* %57
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%59 = load i32, i32* %5
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %6, i64 0, i64 %60
%62 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %61, i32 0, i32 1
store i8* %58, i8** %62
%63 = load i32, i32* %5
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %6, i64 0, i64 %64
%66 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %65, i32 0, i32 2
store i32 512, i32* %66
%67 = load i32, i32* %5
%68 = add nsw i32 %67, 1
store i32 %68, i32* %7
%69 = load i32, i32* %5
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %6, i64 0, i64 %70
%72 = call i32 @aio_write(%struct.aiocb* %71)
store i32 %72, i32* %9
%73 = load i32, i32* %9
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %76
75: ; preds = %48
br label %80
76: ; preds = %48
br label %77
77: ; preds = %76
%78 = load i32, i32* %5
%79 = add nsw i32 %78, 1
store i32 %79, i32* %5
br label %45
80: ; preds = %75, %45
store i32 0, i32* %5
br label %81
81: ; preds = %95, %80
%82 = load i32, i32* %5
%83 = load i32, i32* %7
%84 = sub nsw i32 %83, 1
%85 = icmp slt i32 %82, %84
br i1 %85, label %86, label %98
86: ; preds = %81
%87 = load i32, i32* %5
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %6, i64 0, i64 %88
%90 = call i32 @aio_error(%struct.aiocb* %89)
store i32 %90, i32* %8
%91 = load i32, i32* %5
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %6, i64 0, i64 %92
%94 = call i32 @aio_return(%struct.aiocb* %93)
store i32 %94, i32* %9
br label %95
95: ; preds = %86
%96 = load i32, i32* %5
%97 = add nsw i32 %96, 1
store i32 %97, i32* %5
br label %81
98: ; preds = %81
%99 = load i32, i32* %7
%100 = icmp eq i32 %99, 1024
br i1 %100, label %101, label %106
101: ; preds = %98
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 1024)
%103 = load i32, i32* %4
%104 = call i32 @close(i32 %103)
%105 = call i32 @exit(i32 2)
unreachable
106: ; preds = %98
%107 = load i32, i32* %7
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %107)
%109 = load i32, i32* %9
%110 = icmp ne i32 %109, -1
br i1 %110, label %111, label %123
111: ; preds = %106
%112 = load i32, i32* @errno
%113 = load i32, i32* @EAGAIN
%114 = icmp ne i32 %112, %113
br i1 %114, label %115, label %123
115: ; preds = %111
%116 = load i32, i32* @errno
%117 = load i32, i32* @errno
%118 = call i8* @strerror(i32 %117)
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %116, i8* %118)
%120 = load i32, i32* %4
%121 = call i32 @close(i32 %120)
%122 = call i32 @exit(i32 1)
unreachable
123: ; preds = %111, %106
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %125
125: ; preds = %123, %18
%126 = load i32, i32* %1
ret i32 %126
}

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 = [37 x i8] c"aio_write/7-1.c Error at open(): %s\0A\00"
@errno = global i32 0
@.str.2 = [51 x i8] c"aio_write/7-1.c Could not fail queuing %d request\0A\00"
@.str.3 = [14 x i8] c"Failed at %d\0A\00"
@EAGAIN = global i32 0
@.str.4 = [41 x i8] c"aio_write/7-1.c failed with code %d: %s\0A\00"
@str = [23 x i8] c"aio_write/7-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 %83, 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 %83, 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 ([37 x i8], [37 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)
br label %37
35: ; preds = %37
%36 = icmp eq i64 %44, 1024
br i1 %36, label %51, label %37
37: ; preds = %33, %35
%38 = phi i64 [ 0, %33 ], [ %44, %35 ]
%39 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %3, i64 0, i64 %38
%40 = call i32 @memset(%struct.aiocb* %39, i32 0, i32 24)
%41 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %39, i64 0, i32 0
store i32 %26, i32* %41
%42 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %3, i64 0, i64 %38, i32 1
store i8* %5, i8** %42
%43 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %3, i64 0, i64 %38, i32 2
store i32 512, i32* %43
%44 = add nuw nsw i64 %38, 1
%45 = call i32 @aio_write(%struct.aiocb* %39)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %35
47: ; preds = %37
%48 = trunc i64 %44 to i32
%49 = trunc i64 %38 to i32
%50 = icmp eq i32 %49, 0
br i1 %50, label %61, label %51
51: ; preds = %35, %47
%52 = phi i32 [ %48, %47 ], [ 1024, %35 ]
%53 = and i64 %38, 4294967295
br label %54
54: ; preds = %51, %54
%55 = phi i64 [ 0, %51 ], [ %59, %54 ]
%56 = getelementptr inbounds [1024 x %struct.aiocb], [1024 x %struct.aiocb]* %3, i64 0, i64 %55
%57 = call i32 @aio_error(%struct.aiocb* %56)
%58 = call i32 @aio_return(%struct.aiocb* %56)
%59 = add nuw nsw i64 %55, 1
%60 = icmp eq i64 %59, %53
br i1 %60, label %61, label %54
61: ; preds = %54, %47
%62 = phi i32 [ %48, %47 ], [ %52, %54 ]
%63 = phi i32 [ -1, %47 ], [ %58, %54 ]
%64 = icmp eq i32 %62, 1024
br i1 %64, label %65, label %69
65: ; preds = %61
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 1024)
%67 = call i32 @close(i32 %26)
%68 = call i32 @exit(i32 2)
unreachable
69: ; preds = %61
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %62)
%71 = icmp eq i32 %63, -1
br i1 %71, label %81, label %72
72: ; preds = %69
%73 = load i32, i32* @errno
%74 = load i32, i32* @EAGAIN
%75 = icmp eq i32 %73, %74
br i1 %75, label %81, label %76
76: ; preds = %72
%77 = call i8* @strerror(i32 %73)
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %73, i8* %77)
%79 = call i32 @close(i32 %26)
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %72, %69
%82 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %83
83: ; preds = %0, %10, %81
%84 = phi i32 [ 0, %81 ], [ 4, %10 ], [ 4, %0 ]
ret i32 %84
}