#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 */
struct timespec {
  int dummy;
};
struct iocb {
  int aio_fildes;
  unsigned long aio_buf;
  int aio_nbytes;
  scalar_t__ aio_offset;
  int /*<<< orphan*/ aio_lio_opcode;
};
struct io_event {
  int dummy;
};
typedef int /*<<< orphan*/ cb;
typedef int /*<<< orphan*/ aio_context_t;

/* Variables and functions */
int /*<<< orphan*/ IOCB_CMD_PWRITE;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ __NR_io_cancel;
int /*<<< orphan*/ __NR_io_destroy;
int /*<<< orphan*/ __NR_io_getevents;
int /*<<< orphan*/ __NR_io_setup;
int /*<<< orphan*/ __NR_io_submit;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(struct iocb *, int /*<<< orphan*/, int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int syscall(int /*<<< orphan*/, int, ...);
int main() {
  aio_context_t ctx;
  struct iocb cb;
  struct iocb *cbs[1];
  char data[8];
  struct io_event events[1];
  int ret;
  int fd;
  fd = open("testfile", O_RDWR | O_CREAT, 0644);
  ctx = 0;
  ret = syscall(__NR_io_setup, 128, &ctx);
  if (ret < 0) {
    perror("io_setup failed");
    return -1;
  }
  strcpy(data, "testdata");
  memset(&cb, 0, sizeof(cb));
  cb.aio_fildes = fd;
  cb.aio_lio_opcode = IOCB_CMD_PWRITE;
  cb.aio_buf = (unsigned long)data;
  cb.aio_offset = 0;
  cb.aio_nbytes = 8;
  cbs[0] = &cb;
  ret = syscall(__NR_io_submit, ctx, 1, cbs);
  if (ret != 1) {
    perror("io_sumbit failed");
    return -1;
  }
  ret = syscall(__NR_io_getevents, ctx, 1, 1, events, NULL);
  printf("%d\n", ret);
  ret = syscall(__NR_io_destroy, ctx);
  if (ret < 0) {
    perror("io_destroy failed");
    return -1;
  }
  syscall(__NR_io_setup, (unsigned)-1, &ctx);
  syscall(__NR_io_setup, 1, (aio_context_t *)-1);
  syscall(__NR_io_submit, (aio_context_t)-1, 1, cbs);
  syscall(__NR_io_submit, 0, (long)-1, cbs);
  syscall(__NR_io_submit, 0, 1, (struct iocb **)-1);
  syscall(__NR_io_getevents, (aio_context_t)-1, 1, 1, events, NULL);
  syscall(__NR_io_getevents, 0, (long)-1, 1, events, NULL);
  syscall(__NR_io_getevents, 0, 1, (long)-1, events, NULL);
  syscall(__NR_io_getevents, 0, 1, 1, (struct io_event *)-1, NULL);
  syscall(__NR_io_getevents, 0, 1, 1, events, (struct timespec *)-1);
  syscall(__NR_io_cancel, 1, (struct iocb *)1, (struct io_event *)1);
  syscall(__NR_io_cancel, (aio_context_t)-1, (struct iocb *)1,
          (struct io_event *)1);
  syscall(__NR_io_cancel, 1, (struct iocb *)-1, (struct io_event *)1);
  syscall(__NR_io_cancel, 1, (struct iocb *)1, (struct io_event *)-1);
  ret = syscall(__NR_io_destroy, (aio_context_t)-1);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    0x2e69(%rip),%rax
or     (%rax),%esi
lea    0xe68(%rip),%rdi
mov    $0x1a4,%edx
call   1080 <open@plt>
mov    %eax,-0x50(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    $0x80,%esi
lea    -0x8(%rbp),%rdx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    11ea <main+0x7a>
lea    0xe30(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14d6 <main+0x366>
lea    -0x40(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    -0x50(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x8,-0x20(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
lea    -0x38(%rbp),%rcx
mov    $0x1,%edx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x1,-0x4c(%rbp)
je     127c <main+0x10c>
lea    0xdb7(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14d6 <main+0x366>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
lea    -0x48(%rbp),%r8
mov    $0x1,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %ecx,%edx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%esi
lea    0xd87(%rip),%rdi
call   1040 <printf@plt>
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%esi
mov    $0x0,%al
call   1070 <syscall@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    12e9 <main+0x179>
lea    0xd5f(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14d6 <main+0x366>
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffff,%esi
lea    -0x8(%rbp),%rdx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
mov    $0xffffffffffffffff,%rdx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rcx
mov    $0xffffffff,%esi
mov    $0x1,%edx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rcx
xor    %esi,%esi
mov    $0xffffffffffffffff,%rdx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0xffffffffffffffff,%rcx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    0x2c3a(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%r8
mov    $0xffffffff,%esi
mov    $0x1,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %ecx,%edx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    0x2c15(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%r8
xor    %esi,%esi
mov    $0xffffffffffffffff,%rdx
mov    $0x1,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    $0x0,%al
call   1070 <syscall@plt>
mov    0x2bee(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%r8
xor    %esi,%esi
mov    $0x1,%edx
mov    $0xffffffffffffffff,%rcx
xor    %eax,%eax
mov    %eax,%r9d
mov    $0x0,%al
call   1070 <syscall@plt>
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0x1,%ecx
mov    $0xffffffffffffffff,%r8
xor    %eax,%eax
mov    %eax,%r9d
mov    %ecx,%edx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    0x2ba2(%rip),%rax
mov    (%rax),%edi
lea    -0x48(%rbp),%r8
xor    %esi,%esi
mov    $0x1,%ecx
mov    $0xffffffffffffffff,%r9
mov    %ecx,%edx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    0x2b6e(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
mov    $0x1,%ecx
mov    %rcx,%rdx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    0x2b51(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffff,%esi
mov    $0x1,%ecx
mov    %rcx,%rdx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    0x2b34(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
mov    $0xffffffffffffffff,%rdx
mov    $0x1,%ecx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    0x2b13(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
mov    $0x1,%edx
mov    $0xffffffffffffffff,%rcx
mov    $0x0,%al
call   1070 <syscall@plt>
mov    0x2aea(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffff,%esi
mov    $0x0,%al
call   1070 <syscall@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x50(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    0x2e53(%rip),%rax
mov    0x2e6c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe69(%rip),%rdi
mov    $0x1a4,%edx
call   1080 <open@plt>
mov    %eax,%r15d
movl   $0x0,0x4(%rsp)
mov    0x2e0d(%rip),%r13
mov    0x0(%r13),%edi
lea    0x4(%rsp),%rdx
mov    $0x80,%esi
xor    %eax,%eax
call   1070 <syscall@plt>
test   %eax,%eax
js     1453 <main+0x2e3>
lea    0xe42(%rip),%rsi
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0x18(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    %r15d,0x18(%rsp)
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
mov    %rbx,0x20(%rsp)
movq   $0x0,0x30(%rsp)
movl   $0x8,0x28(%rsp)
mov    %rbp,0x10(%rsp)
mov    0x2da4(%rip),%r12
mov    (%r12),%edi
mov    0x4(%rsp),%esi
lea    0x10(%rsp),%rcx
mov    $0x1,%edx
xor    %eax,%eax
call   1070 <syscall@plt>
cmp    $0x1,%eax
jne    145c <main+0x2ec>
mov    0x2d63(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x4(%rsp),%esi
xor    %r14d,%r14d
lea    0x8(%rsp),%r8
mov    $0x1,%edx
mov    $0x1,%ecx
xor    %r9d,%r9d
xor    %eax,%eax
call   1070 <syscall@plt>
lea    0xdb4(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x2d13(%rip),%rbx
mov    (%rbx),%edi
mov    0x4(%rsp),%esi
xor    %eax,%eax
call   1070 <syscall@plt>
test   %eax,%eax
js     1465 <main+0x2f5>
mov    0x0(%r13),%edi
lea    0x4(%rsp),%rdx
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1070 <syscall@plt>
mov    0x0(%r13),%edi
mov    $0x1,%esi
mov    $0xffffffffffffffff,%rdx
xor    %eax,%eax
call   1070 <syscall@plt>
mov    (%r12),%edi
mov    %rbx,%r13
lea    0x10(%rsp),%rbx
mov    $0xffffffff,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <syscall@plt>
mov    (%r12),%edi
xor    %esi,%esi
mov    $0xffffffffffffffff,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <syscall@plt>
mov    (%r12),%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0xffffffffffffffff,%rcx
xor    %eax,%eax
call   1070 <syscall@plt>
mov    0x0(%rbp),%edi
lea    0x8(%rsp),%rbx
mov    $0xffffffff,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
mov    %rbx,%r8
xor    %r9d,%r9d
xor    %eax,%eax
call   1070 <syscall@plt>
mov    0x0(%rbp),%edi
xor    %esi,%esi
mov    $0xffffffffffffffff,%rdx
mov    $0x1,%ecx
mov    %rbx,%r8
xor    %r9d,%r9d
xor    %eax,%eax
call   1070 <syscall@plt>
mov    0x0(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0xffffffffffffffff,%rcx
mov    %rbx,%r8
xor    %r9d,%r9d
xor    %eax,%eax
call   1070 <syscall@plt>
mov    0x0(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
mov    $0xffffffffffffffff,%r8
xor    %r9d,%r9d
xor    %eax,%eax
call   1070 <syscall@plt>
mov    0x0(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x1,%ecx
mov    %rbx,%r8
mov    $0xffffffffffffffff,%r9
xor    %eax,%eax
call   1070 <syscall@plt>
mov    0x2be3(%rip),%rbx
mov    (%rbx),%edi
mov    $0x1,%edx
mov    $0x1,%ecx
mov    $0x1,%esi
xor    %eax,%eax
call   1070 <syscall@plt>
mov    (%rbx),%edi
mov    $0x1,%edx
mov    $0x1,%ecx
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1070 <syscall@plt>
mov    (%rbx),%edi
mov    $0x1,%ecx
mov    $0x1,%esi
mov    $0xffffffffffffffff,%rdx
xor    %eax,%eax
call   1070 <syscall@plt>
mov    (%rbx),%edi
mov    $0x1,%edx
mov    $0x1,%esi
mov    $0xffffffffffffffff,%rcx
xor    %eax,%eax
call   1070 <syscall@plt>
mov    0x0(%r13),%edi
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1070 <syscall@plt>
mov    %r15d,%edi
call   1060 <close@plt>
mov    %r14d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbaf(%rip),%rdi
jmp    146c <main+0x2fc>
lea    0xbbf(%rip),%rdi
jmp    146c <main+0x2fc>
lea    0xbcb(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%r14d
jmp    1441 <main+0x2d1>

LLVM IR (-O0):
%struct.iocb = type { i32, i64, i32, i64, i32 }
%struct.io_event = type { i32 }
%struct.timespec = type { i32 }
@.str = [9 x i8] c"testfile\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@__NR_io_setup = global i32 0
@.str.1 = [16 x i8] c"io_setup failed\00"
@.str.2 = [9 x i8] c"testdata\00"
@IOCB_CMD_PWRITE = global i32 0
@__NR_io_submit = global i32 0
@.str.3 = [17 x i8] c"io_sumbit failed\00"
@__NR_io_getevents = global i32 0
@.str.4 = [4 x i8] c"%d\0A\00"
@__NR_io_destroy = global i32 0
@.str.5 = [18 x i8] c"io_destroy failed\00"
@__NR_io_cancel = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.iocb
%4 = alloca [1 x %struct.iocb*]
%5 = alloca [8 x i8]
%6 = alloca [1 x %struct.io_event]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_CREAT
%11 = or i32 %9, %10
%12 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11, i32 420)
store i32 %12, i32* %8
store i32 0, i32* %2
%13 = load i32, i32* @__NR_io_setup
%14 = call i32 (i32, i32, ...) @syscall(i32 %13, i32 128, i32* %2)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %94
19: ; preds = %0
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @memset(%struct.iocb* %3, i32 0, i32 40)
%23 = load i32, i32* %8
%24 = getelementptr inbounds %struct.iocb, %struct.iocb* %3, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* @IOCB_CMD_PWRITE
%26 = getelementptr inbounds %struct.iocb, %struct.iocb* %3, i32 0, i32 4
store i32 %25, i32* %26
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%28 = ptrtoint i8* %27 to i64
%29 = getelementptr inbounds %struct.iocb, %struct.iocb* %3, i32 0, i32 1
store i64 %28, i64* %29
%30 = getelementptr inbounds %struct.iocb, %struct.iocb* %3, i32 0, i32 3
store i64 0, i64* %30
%31 = getelementptr inbounds %struct.iocb, %struct.iocb* %3, i32 0, i32 2
store i32 8, i32* %31
%32 = getelementptr inbounds [1 x %struct.iocb*], [1 x %struct.iocb*]* %4, i64 0, i64 0
store %struct.iocb* %3, %struct.iocb** %32
%33 = load i32, i32* @__NR_io_submit
%34 = load i32, i32* %2
%35 = getelementptr inbounds [1 x %struct.iocb*], [1 x %struct.iocb*]* %4, i64 0, i64 0
%36 = call i32 (i32, i32, ...) @syscall(i32 %33, i32 %34, i32 1, %struct.iocb** %35)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp ne i32 %37, 1
br i1 %38, label %39, label %41
39: ; preds = %19
%40 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %94
41: ; preds = %19
%42 = load i32, i32* @__NR_io_getevents
%43 = load i32, i32* %2
%44 = getelementptr inbounds [1 x %struct.io_event], [1 x %struct.io_event]* %6, i64 0, i64 0
%45 = call i32 (i32, i32, ...) @syscall(i32 %42, i32 %43, i32 1, i32 1, %struct.io_event* %44, i8* null)
store i32 %45, i32* %7
%46 = load i32, i32* %7
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%48 = load i32, i32* @__NR_io_destroy
%49 = load i32, i32* %2
%50 = call i32 (i32, i32, ...) @syscall(i32 %48, i32 %49)
store i32 %50, i32* %7
%51 = load i32, i32* %7
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %41
%54 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %94
55: ; preds = %41
%56 = load i32, i32* @__NR_io_setup
%57 = call i32 (i32, i32, ...) @syscall(i32 %56, i32 -1, i32* %2)
%58 = load i32, i32* @__NR_io_setup
%59 = call i32 (i32, i32, ...) @syscall(i32 %58, i32 1, i32* inttoptr (i64 -1 to i32*))
%60 = load i32, i32* @__NR_io_submit
%61 = getelementptr inbounds [1 x %struct.iocb*], [1 x %struct.iocb*]* %4, i64 0, i64 0
%62 = call i32 (i32, i32, ...) @syscall(i32 %60, i32 -1, i32 1, %struct.iocb** %61)
%63 = load i32, i32* @__NR_io_submit
%64 = getelementptr inbounds [1 x %struct.iocb*], [1 x %struct.iocb*]* %4, i64 0, i64 0
%65 = call i32 (i32, i32, ...) @syscall(i32 %63, i32 0, i64 -1, %struct.iocb** %64)
%66 = load i32, i32* @__NR_io_submit
%67 = call i32 (i32, i32, ...) @syscall(i32 %66, i32 0, i32 1, %struct.iocb** inttoptr (i64 -1 to %struct.iocb**))
%68 = load i32, i32* @__NR_io_getevents
%69 = getelementptr inbounds [1 x %struct.io_event], [1 x %struct.io_event]* %6, i64 0, i64 0
%70 = call i32 (i32, i32, ...) @syscall(i32 %68, i32 -1, i32 1, i32 1, %struct.io_event* %69, i8* null)
%71 = load i32, i32* @__NR_io_getevents
%72 = getelementptr inbounds [1 x %struct.io_event], [1 x %struct.io_event]* %6, i64 0, i64 0
%73 = call i32 (i32, i32, ...) @syscall(i32 %71, i32 0, i64 -1, i32 1, %struct.io_event* %72, i8* null)
%74 = load i32, i32* @__NR_io_getevents
%75 = getelementptr inbounds [1 x %struct.io_event], [1 x %struct.io_event]* %6, i64 0, i64 0
%76 = call i32 (i32, i32, ...) @syscall(i32 %74, i32 0, i32 1, i64 -1, %struct.io_event* %75, i8* null)
%77 = load i32, i32* @__NR_io_getevents
%78 = call i32 (i32, i32, ...) @syscall(i32 %77, i32 0, i32 1, i32 1, %struct.io_event* inttoptr (i64 -1 to %struct.io_event*), i8* null)
%79 = load i32, i32* @__NR_io_getevents
%80 = getelementptr inbounds [1 x %struct.io_event], [1 x %struct.io_event]* %6, i64 0, i64 0
%81 = call i32 (i32, i32, ...) @syscall(i32 %79, i32 0, i32 1, i32 1, %struct.io_event* %80, %struct.timespec* inttoptr (i64 -1 to %struct.timespec*))
%82 = load i32, i32* @__NR_io_cancel
%83 = call i32 (i32, i32, ...) @syscall(i32 %82, i32 1, %struct.iocb* inttoptr (i64 1 to %struct.iocb*), %struct.io_event* inttoptr (i64 1 to %struct.io_event*))
%84 = load i32, i32* @__NR_io_cancel
%85 = call i32 (i32, i32, ...) @syscall(i32 %84, i32 -1, %struct.iocb* inttoptr (i64 1 to %struct.iocb*), %struct.io_event* inttoptr (i64 1 to %struct.io_event*))
%86 = load i32, i32* @__NR_io_cancel
%87 = call i32 (i32, i32, ...) @syscall(i32 %86, i32 1, %struct.iocb* inttoptr (i64 -1 to %struct.iocb*), %struct.io_event* inttoptr (i64 1 to %struct.io_event*))
%88 = load i32, i32* @__NR_io_cancel
%89 = call i32 (i32, i32, ...) @syscall(i32 %88, i32 1, %struct.iocb* inttoptr (i64 1 to %struct.iocb*), %struct.io_event* inttoptr (i64 -1 to %struct.io_event*))
%90 = load i32, i32* @__NR_io_destroy
%91 = call i32 (i32, i32, ...) @syscall(i32 %90, i32 -1)
store i32 %91, i32* %7
%92 = load i32, i32* %8
%93 = call i32 @close(i32 %92)
store i32 0, i32* %1
br label %94
94: ; preds = %55, %53, %39, %17
%95 = load i32, i32* %1
ret i32 %95
}

LLVM IR (-O2):
%struct.iocb = type { i32, i64, i32, i64, i32 }
%struct.io_event = type { i32 }
%struct.timespec = type { i32 }
@.str = [9 x i8] c"testfile\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@__NR_io_setup = global i32 0
@.str.1 = [16 x i8] c"io_setup failed\00"
@.str.2 = [9 x i8] c"testdata\00"
@IOCB_CMD_PWRITE = global i32 0
@__NR_io_submit = global i32 0
@.str.3 = [17 x i8] c"io_sumbit failed\00"
@__NR_io_getevents = global i32 0
@.str.4 = [4 x i8] c"%d\0A\00"
@__NR_io_destroy = global i32 0
@.str.5 = [18 x i8] c"io_destroy failed\00"
@__NR_io_cancel = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.iocb
%3 = alloca [1 x %struct.iocb*]
%4 = alloca [8 x i8]
%5 = alloca [1 x %struct.io_event]
%6 = bitcast i32* %1 to i8*
%7 = bitcast %struct.iocb* %2 to i8*
%8 = bitcast [1 x %struct.iocb*]* %3 to i8*
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%10 = bitcast [1 x %struct.io_event]* %5 to i8*
%11 = load i32, i32* @O_RDWR
%12 = load i32, i32* @O_CREAT
%13 = or i32 %12, %11
%14 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %13, i32 420)
store i32 0, i32* %1
%15 = load i32, i32* @__NR_io_setup
%16 = call i32 (i32, i32, ...) @syscall(i32 %15, i32 128, i32* %1)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %81
20: ; preds = %0
%21 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @memset(%struct.iocb* %2, i32 0, i32 40)
%23 = getelementptr inbounds %struct.iocb, %struct.iocb* %2, i64 0, i32 0
store i32 %14, i32* %23
%24 = load i32, i32* @IOCB_CMD_PWRITE
%25 = getelementptr inbounds %struct.iocb, %struct.iocb* %2, i64 0, i32 4
store i32 %24, i32* %25
%26 = ptrtoint [8 x i8]* %4 to i64
%27 = getelementptr inbounds %struct.iocb, %struct.iocb* %2, i64 0, i32 1
store i64 %26, i64* %27
%28 = getelementptr inbounds %struct.iocb, %struct.iocb* %2, i64 0, i32 3
store i64 0, i64* %28
%29 = getelementptr inbounds %struct.iocb, %struct.iocb* %2, i64 0, i32 2
store i32 8, i32* %29
%30 = getelementptr inbounds [1 x %struct.iocb*], [1 x %struct.iocb*]* %3, i64 0, i64 0
store %struct.iocb* %2, %struct.iocb** %30
%31 = load i32, i32* @__NR_io_submit
%32 = load i32, i32* %1
%33 = call i32 (i32, i32, ...) @syscall(i32 %31, i32 %32, i32 1, %struct.iocb** %30)
%34 = icmp eq i32 %33, 1
br i1 %34, label %37, label %35
35: ; preds = %20
%36 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %81
37: ; preds = %20
%38 = load i32, i32* @__NR_io_getevents
%39 = load i32, i32* %1
%40 = getelementptr inbounds [1 x %struct.io_event], [1 x %struct.io_event]* %5, i64 0, i64 0
%41 = call i32 (i32, i32, ...) @syscall(i32 %38, i32 %39, i32 1, i32 1, %struct.io_event* %40, i8* null)
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = load i32, i32* @__NR_io_destroy
%44 = load i32, i32* %1
%45 = call i32 (i32, i32, ...) @syscall(i32 %43, i32 %44)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %37
%48 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %81
49: ; preds = %37
%50 = load i32, i32* @__NR_io_setup
%51 = call i32 (i32, i32, ...) @syscall(i32 %50, i32 -1, i32* %1)
%52 = load i32, i32* @__NR_io_setup
%53 = call i32 (i32, i32, ...) @syscall(i32 %52, i32 1, i32* inttoptr (i64 -1 to i32*))
%54 = load i32, i32* @__NR_io_submit
%55 = call i32 (i32, i32, ...) @syscall(i32 %54, i32 -1, i32 1, %struct.iocb** %30)
%56 = load i32, i32* @__NR_io_submit
%57 = call i32 (i32, i32, ...) @syscall(i32 %56, i32 0, i64 -1, %struct.iocb** %30)
%58 = load i32, i32* @__NR_io_submit
%59 = call i32 (i32, i32, ...) @syscall(i32 %58, i32 0, i32 1, %struct.iocb** inttoptr (i64 -1 to %struct.iocb**))
%60 = load i32, i32* @__NR_io_getevents
%61 = call i32 (i32, i32, ...) @syscall(i32 %60, i32 -1, i32 1, i32 1, %struct.io_event* %40, i8* null)
%62 = load i32, i32* @__NR_io_getevents
%63 = call i32 (i32, i32, ...) @syscall(i32 %62, i32 0, i64 -1, i32 1, %struct.io_event* %40, i8* null)
%64 = load i32, i32* @__NR_io_getevents
%65 = call i32 (i32, i32, ...) @syscall(i32 %64, i32 0, i32 1, i64 -1, %struct.io_event* %40, i8* null)
%66 = load i32, i32* @__NR_io_getevents
%67 = call i32 (i32, i32, ...) @syscall(i32 %66, i32 0, i32 1, i32 1, %struct.io_event* inttoptr (i64 -1 to %struct.io_event*), i8* null)
%68 = load i32, i32* @__NR_io_getevents
%69 = call i32 (i32, i32, ...) @syscall(i32 %68, i32 0, i32 1, i32 1, %struct.io_event* %40, %struct.timespec* inttoptr (i64 -1 to %struct.timespec*))
%70 = load i32, i32* @__NR_io_cancel
%71 = call i32 (i32, i32, ...) @syscall(i32 %70, i32 1, %struct.iocb* inttoptr (i64 1 to %struct.iocb*), %struct.io_event* inttoptr (i64 1 to %struct.io_event*))
%72 = load i32, i32* @__NR_io_cancel
%73 = call i32 (i32, i32, ...) @syscall(i32 %72, i32 -1, %struct.iocb* inttoptr (i64 1 to %struct.iocb*), %struct.io_event* inttoptr (i64 1 to %struct.io_event*))
%74 = load i32, i32* @__NR_io_cancel
%75 = call i32 (i32, i32, ...) @syscall(i32 %74, i32 1, %struct.iocb* inttoptr (i64 -1 to %struct.iocb*), %struct.io_event* inttoptr (i64 1 to %struct.io_event*))
%76 = load i32, i32* @__NR_io_cancel
%77 = call i32 (i32, i32, ...) @syscall(i32 %76, i32 1, %struct.iocb* inttoptr (i64 1 to %struct.iocb*), %struct.io_event* inttoptr (i64 -1 to %struct.io_event*))
%78 = load i32, i32* @__NR_io_destroy
%79 = call i32 (i32, i32, ...) @syscall(i32 %78, i32 -1)
%80 = call i32 @close(i32 %14)
br label %81
81: ; preds = %49, %47, %35, %18
%82 = phi i32 [ -1, %18 ], [ -1, %35 ], [ -1, %47 ], [ 0, %49 ]
ret i32 %82
}