#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct aiocb {
  scalar_t__ aio_buf;
};
struct TYPE_3__ {
  scalar_t__ sival_ptr;
};
typedef TYPE_1__ sigval_t;

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
scalar_t__ aio_error(struct aiocb *);
int aio_return(struct aiocb *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ write(int /*<<< orphan*/, void *, int);
void read_notify(sigval_t sigval) {
  struct aiocb *cb = (struct aiocb *)sigval.sival_ptr;
  if (aio_error(cb) != 0) {
    fprintf(stderr, "aio_error: %s/n", strerror(errno));
    return;
  }
  int len = aio_return(cb);
  if (len < 0) {
    fprintf(stderr, "aio_return error: %s/n", strerror(errno));
    return;
  }
  write(STDOUT_FILENO, (void *)cb->aio_buf, len);
  exit(0);
}


x86 assembly (clang, -O0):
<read_notify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <aio_error@plt>
cmp    $0x0,%rax
je     11b8 <read_notify+0x58>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe52(%rip),%rsi
call   1040 <fprintf@plt>
jmp    121e <read_notify+0xbe>
mov    -0x10(%rbp),%rdi
call   1060 <aio_return@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ff <read_notify+0x9f>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe1b(%rip),%rsi
call   1040 <fprintf@plt>
jmp    121e <read_notify+0xbe>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1070 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_notify>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <aio_error@plt>
test   %rax,%rax
je     1179 <read_notify+0x19>
lea    0xe89(%rip),%rbx
jmp    118c <read_notify+0x2c>
mov    %rbx,%rdi
call   1060 <aio_return@plt>
test   %eax,%eax
jns    11b6 <read_notify+0x56>
lea    0xe84(%rip),%rbx
mov    0x2e45(%rip),%rax
mov    (%rax),%ebp
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fprintf@plt>
mov    0x2e33(%rip),%rcx
mov    (%rcx),%edi
mov    (%rbx),%rsi
mov    %eax,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64 }
%struct.aiocb = type { i64 }
@stderr = global i32 0
@.str = [16 x i8] c"aio_error: %s/n\00"
@errno = global i32 0
@.str.1 = [23 x i8] c"aio_return error: %s/n\00"
@STDOUT_FILENO = global i32 0
define void @read_notify(i64 %0) {
%2 = alloca %struct.TYPE_3__
%3 = alloca %struct.aiocb*
%4 = alloca i32
%5 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 0
store i64 %0, i64* %5
%6 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 0
%7 = load i64, i64* %6
%8 = inttoptr i64 %7 to %struct.aiocb*
store %struct.aiocb* %8, %struct.aiocb** %3
%9 = load %struct.aiocb*, %struct.aiocb** %3
%10 = call i64 @aio_error(%struct.aiocb* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %36
17: ; preds = %1
%18 = load %struct.aiocb*, %struct.aiocb** %3
%19 = call i32 @aio_return(%struct.aiocb* %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %36
27: ; preds = %17
%28 = load i32, i32* @STDOUT_FILENO
%29 = load %struct.aiocb*, %struct.aiocb** %3
%30 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %29, i32 0, i32 0
%31 = load i64, i64* %30
%32 = inttoptr i64 %31 to i8*
%33 = load i32, i32* %4
%34 = call i32 @write(i32 %28, i8* %32, i32 %33)
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %22, %12
ret void
}

LLVM IR (-O2):
%struct.aiocb = type { i64 }
@stderr = global i32 0
@.str = [16 x i8] c"aio_error: %s/n\00"
@errno = global i32 0
@.str.1 = [23 x i8] c"aio_return error: %s/n\00"
@STDOUT_FILENO = global i32 0
define void @read_notify(i64 %0) {
%2 = inttoptr i64 %0 to %struct.aiocb*
%3 = tail call i64 @aio_error(%struct.aiocb* %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %1
%6 = tail call i32 @aio_return(%struct.aiocb* %2)
%7 = icmp slt i32 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %5
%9 = load i32, i32* @STDOUT_FILENO
%10 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %2, i64 0, i32 0
%11 = load i64, i64* %10
%12 = inttoptr i64 %11 to i8*
%13 = tail call i32 @write(i32 %9, i8* %12, i32 %6)
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %5, %1
%16 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), %5 ]
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 @fprintf(i32 %17, i8* %16, i8* %19)
ret void
}