#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 aiocb {
  int aio_fildes;
  int aio_nbytes;
  scalar_t__ aio_offset;
  int /*<<< orphan*/ aio_buf;
};
typedef int /*<<< orphan*/ cblist;

/* Variables and functions */
scalar_t__ EINPROGRESS;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ aio_error(struct aiocb *);
int aio_read(struct aiocb *);
int aio_return(struct aiocb *);
int aio_suspend(struct aiocb const *const *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ malloc(int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  struct aiocb *cblist[(4096)];
  struct aiocb my_aiocb;
  int fd, ret;
  if (argc == 1) {
    fprintf(stderr, "Usage: %s <file>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    perror("open");
    exit(EXIT_FAILURE);
  }
  memset((void *)&my_aiocb, 0, sizeof(struct aiocb));
  memset((void *)cblist, 0, sizeof(cblist));
  my_aiocb.aio_buf = malloc((4096) + 1);
  if (!my_aiocb.aio_buf) {
    perror("malloc");
    exit(EXIT_FAILURE);
  }
  my_aiocb.aio_fildes = fd;
  my_aiocb.aio_nbytes = (4096);
  my_aiocb.aio_offset = 0;
  cblist[0] = &my_aiocb;
  ret = aio_read(&my_aiocb);
  if (ret < 0) {
    perror("aio_read");
    exit(EXIT_FAILURE);
  }
  ret = aio_suspend((const struct aiocb *const *)cblist, (4096), NULL);
  if (ret < 0) {
    perror("aio_suspend");
    exit(EXIT_FAILURE);
  }
  while (aio_error(&my_aiocb) == EINPROGRESS) {
  }
  if ((ret = aio_return(&my_aiocb)) > 0) {
  } else {
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11ed <main+0x4d>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe26(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x802c(%rbp)
cmpl   $0x0,-0x802c(%rbp)
jge    1230 <main+0x90>
lea    0xdf5(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x8028(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
lea    -0x8010(%rbp),%rdi
xor    %esi,%esi
mov    $0x8000,%edx
call   1030 <memset@plt>
mov    $0x1001,%edi
call   1070 <malloc@plt>
mov    %eax,-0x8018(%rbp)
cmpl   $0x0,-0x8018(%rbp)
jne    128d <main+0xed>
lea    0xd9d(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x802c(%rbp),%eax
mov    %eax,-0x8028(%rbp)
movl   $0x1000,-0x8024(%rbp)
movq   $0x0,-0x8020(%rbp)
lea    -0x8028(%rbp),%rax
mov    %rax,-0x8010(%rbp)
lea    -0x8028(%rbp),%rdi
call   1050 <aio_read@plt>
mov    %eax,-0x8030(%rbp)
cmpl   $0x0,-0x8030(%rbp)
jge    12f5 <main+0x155>
lea    0xd3c(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x8010(%rbp),%rdi
mov    $0x1000,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1090 <aio_suspend@plt>
mov    %eax,-0x8030(%rbp)
cmpl   $0x0,-0x8030(%rbp)
jge    1337 <main+0x197>
lea    0xd03(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
jmp    133c <main+0x19c>
lea    -0x8028(%rbp),%rdi
call   1060 <aio_error@plt>
mov    0x2c99(%rip),%rcx
cmp    (%rcx),%rax
jne    135d <main+0x1bd>
jmp    133c <main+0x19c>
lea    -0x8028(%rbp),%rdi
call   1080 <aio_return@plt>
mov    %eax,-0x8030(%rbp)
cmp    $0x0,%eax
jle    137d <main+0x1dd>
jmp    1382 <main+0x1e2>
jmp    1382 <main+0x1e2>
mov    -0x4(%rbp),%eax
add    $0x8030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x8028,%rsp
cmp    $0x1,%edi
je     1284 <main+0xe4>
mov    0x8(%rsi),%rdi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
test   %eax,%eax
js     129e <main+0xfe>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x8000,%edx
call   1030 <memset@plt>
mov    $0x1001,%edi
call   1070 <malloc@plt>
mov    %eax,0x18(%rsp)
test   %eax,%eax
je     12a7 <main+0x107>
mov    %ebx,0x8(%rsp)
movl   $0x1000,0xc(%rsp)
movq   $0x0,0x10(%rsp)
mov    %r14,0x20(%rsp)
mov    %r14,%rdi
call   1050 <aio_read@plt>
test   %eax,%eax
js     12b0 <main+0x110>
lea    0x20(%rsp),%rdi
mov    $0x1000,%esi
xor    %edx,%edx
call   1090 <aio_suspend@plt>
test   %eax,%eax
js     12b9 <main+0x119>
lea    0x8(%rsp),%r14
mov    0x2d93(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1060 <aio_error@plt>
cmp    (%rbx),%rax
je     1260 <main+0xc0>
lea    0x8(%rsp),%rdi
call   1080 <aio_return@plt>
xor    %eax,%eax
add    $0x8028,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd69(%rip),%rsi
call   1040 <fprintf@plt>
jmp    12c5 <main+0x125>
lea    0xd6d(%rip),%rdi
jmp    12c0 <main+0x120>
lea    0xd69(%rip),%rdi
jmp    12c0 <main+0x120>
lea    0xd67(%rip),%rdi
jmp    12c0 <main+0x120>
lea    0xd67(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.aiocb = type { i32, i32, i64, i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [7 x i8] c"malloc\00"
@.str.3 = [9 x i8] c"aio_read\00"
@.str.4 = [12 x i8] c"aio_suspend\00"
@EINPROGRESS = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x %struct.aiocb*]
%7 = alloca %struct.aiocb
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_RDONLY
%25 = call i32 @open(i8* %23, i32 %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %20
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %20
%33 = bitcast %struct.aiocb* %7 to i8*
%34 = call i32 @memset(i8* %33, i32 0, i32 24)
%35 = getelementptr inbounds [4096 x %struct.aiocb*], [4096 x %struct.aiocb*]* %6, i64 0, i64 0
%36 = bitcast %struct.aiocb** %35 to i8*
%37 = call i32 @memset(i8* %36, i32 0, i32 32768)
%38 = call i32 @malloc(i32 4097)
%39 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %7, i32 0, i32 3
store i32 %38, i32* %39
%40 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %7, i32 0, i32 3
%41 = load i32, i32* %40
%42 = icmp ne i32 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %32
%44 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %32
%48 = load i32, i32* %8
%49 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %7, i32 0, i32 0
store i32 %48, i32* %49
%50 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %7, i32 0, i32 1
store i32 4096, i32* %50
%51 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %7, i32 0, i32 2
store i64 0, i64* %51
%52 = getelementptr inbounds [4096 x %struct.aiocb*], [4096 x %struct.aiocb*]* %6, i64 0, i64 0
store %struct.aiocb* %7, %struct.aiocb** %52
%53 = call i32 @aio_read(%struct.aiocb* %7)
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %47
%57 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %47
%61 = getelementptr inbounds [4096 x %struct.aiocb*], [4096 x %struct.aiocb*]* %6, i64 0, i64 0
%62 = call i32 @aio_suspend(%struct.aiocb** %61, i32 4096, i32* null)
store i32 %62, i32* %9
%63 = load i32, i32* %9
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %60
%66 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%67 = load i32, i32* @EXIT_FAILURE
%68 = call i32 @exit(i32 %67)
unreachable
69: ; preds = %60
br label %70
70: ; preds = %74, %69
%71 = call i64 @aio_error(%struct.aiocb* %7)
%72 = load i64, i64* @EINPROGRESS
%73 = icmp eq i64 %71, %72
br i1 %73, label %74, label %75
74: ; preds = %70
br label %70
75: ; preds = %70
%76 = call i32 @aio_return(%struct.aiocb* %7)
store i32 %76, i32* %9
%77 = icmp sgt i32 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %75
br label %80
79: ; preds = %75
br label %80
80: ; preds = %79, %78
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
%struct.aiocb = type { i32, i32, i64, i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [7 x i8] c"malloc\00"
@.str.3 = [9 x i8] c"aio_read\00"
@.str.4 = [12 x i8] c"aio_suspend\00"
@EINPROGRESS = global i64 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x %struct.aiocb*]
%4 = alloca %struct.aiocb
%5 = bitcast [4096 x %struct.aiocb*]* %3 to i8*
%6 = bitcast %struct.aiocb* %4 to i8*
%7 = icmp eq i32 %0, 1
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 @open(i8* %16, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %14
%25 = call i32 @memset(i8* %6, i32 0, i32 24)
%26 = getelementptr inbounds [4096 x %struct.aiocb*], [4096 x %struct.aiocb*]* %3, i64 0, i64 0
%27 = call i32 @memset(i8* %5, i32 0, i32 32768)
%28 = call i32 @malloc(i32 4097)
%29 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %4, i64 0, i32 3
store i32 %28, i32* %29
%30 = icmp eq i32 %28, 0
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %24
%36 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %4, i64 0, i32 0
store i32 %18, i32* %36
%37 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %4, i64 0, i32 1
store i32 4096, i32* %37
%38 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %4, i64 0, i32 2
store i64 0, i64* %38
store %struct.aiocb* %4, %struct.aiocb** %26
%39 = call i32 @aio_read(%struct.aiocb* %4)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %35
%42 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %35
%46 = call i32 @aio_suspend(%struct.aiocb** %26, i32 4096, i32* null)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %45, %52
%53 = call i64 @aio_error(%struct.aiocb* %4)
%54 = load i64, i64* @EINPROGRESS
%55 = icmp eq i64 %53, %54
br i1 %55, label %52, label %56
56: ; preds = %52
%57 = call i32 @aio_return(%struct.aiocb* %4)
ret i32 0
}