#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_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct aiocb {
  scalar_t__ aio_buf;
};
struct TYPE_4__ {
  scalar_t__ sival_ptr;
};
struct TYPE_5__ {
  TYPE_1__ si_value;
};
typedef TYPE_2__ siginfo_t;

/* Variables and functions */
int SIGIO;
int /*<<< orphan*/ STDOUT_FILENO;
scalar_t__ aio_error(struct aiocb *);
int aio_return(struct aiocb *);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ write(int /*<<< orphan*/, void *, int);
void sigio_handler(int signo, siginfo_t *info, void *context) {
  assert(signo == SIGIO);
  struct aiocb *cb = (struct aiocb *)(info->si_value.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;
  }
  printf("aio completed!\n");
  write(STDOUT_FILENO, (void *)cb->aio_buf, len);
}


x86 assembly (clang, -O0):
<sigio_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e3b(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <aio_error@plt>
cmp    $0x0,%rax
je     11eb <sigio_handler+0x7b>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xe1f(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1256 <sigio_handler+0xe6>
mov    -0x20(%rbp),%rdi
call   1080 <aio_return@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1232 <sigio_handler+0xc2>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xde8(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1256 <sigio_handler+0xe6>
lea    0xdee(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x24(%rbp),%edx
call   1030 <write@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigio_handler>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e4b(%rip),%rcx
xor    %eax,%eax
cmp    %edi,(%rcx)
sete   %al
mov    %eax,%edi
call   1050 <assert@plt>
mov    (%rbx),%rbx
mov    %rbx,%rdi
call   1070 <aio_error@plt>
test   %rax,%rax
je     11c9 <sigio_handler+0x59>
mov    0x2e36(%rip),%rax
mov    (%rax),%ebx
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe47(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <aio_return@plt>
test   %eax,%eax
js     11fc <sigio_handler+0x8c>
mov    %eax,%ebp
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rsi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <write@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%ebx
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdf6(%rip),%rsi
jmp    11b9 <sigio_handler+0x49>

LLVM IR (-O0):
%struct.TYPE_5__ = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i64 }
%struct.aiocb = type { i64 }
@SIGIO = global i32 0
@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"
@.str.2 = [16 x i8] c"aio completed!\0A\00"
@STDOUT_FILENO = global i32 0
define void @sigio_handler(i32 %0, %struct.TYPE_5__* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_5__*
%6 = alloca i8*
%7 = alloca %struct.aiocb*
%8 = alloca i32
store i32 %0, i32* %4
store %struct.TYPE_5__* %1, %struct.TYPE_5__** %5
store i8* %2, i8** %6
%9 = load i32, i32* %4
%10 = load i32, i32* @SIGIO
%11 = icmp eq i32 %9, %10
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = inttoptr i64 %17 to %struct.aiocb*
store %struct.aiocb* %18, %struct.aiocb** %7
%19 = load %struct.aiocb*, %struct.aiocb** %7
%20 = call i64 @aio_error(%struct.aiocb* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %3
%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 ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %25)
br label %46
27: ; preds = %3
%28 = load %struct.aiocb*, %struct.aiocb** %7
%29 = call i32 @aio_return(%struct.aiocb* %28)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %35)
br label %46
37: ; preds = %27
%38 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @STDOUT_FILENO
%40 = load %struct.aiocb*, %struct.aiocb** %7
%41 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %40, i32 0, i32 0
%42 = load i64, i64* %41
%43 = inttoptr i64 %42 to i8*
%44 = load i32, i32* %8
%45 = call i32 @write(i32 %39, i8* %43, i32 %44)
br label %46
46: ; preds = %37, %32, %22
ret void
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i64 }
%struct.aiocb = type { i64 }
@SIGIO = global i32 0
@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
@str = [15 x i8] c"aio completed!\00"
define void @sigio_handler(i32 %0, %struct.TYPE_5__* nocapture %1, i8* nocapture readnone %2) {
%4 = load i32, i32* @SIGIO
%5 = icmp eq i32 %4, %0
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %1, i64 0, i32 0, i32 0
%9 = load i64, i64* %8
%10 = inttoptr i64 %9 to %struct.aiocb*
%11 = tail call i64 @aio_error(%struct.aiocb* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %33
18: ; preds = %3
%19 = tail call i32 @aio_return(%struct.aiocb* %10)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = tail call i8* @strerror(i32 %23)
%25 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %33
26: ; preds = %18
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%28 = load i32, i32* @STDOUT_FILENO
%29 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %10, i64 0, i32 0
%30 = load i64, i64* %29
%31 = inttoptr i64 %30 to i8*
%32 = tail call i32 @write(i32 %28, i8* %31, i32 %19)
br label %33
33: ; preds = %21, %26, %13
ret void
}