#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int ps_test_aio_return(struct aiocb *);
int ps_test_aio_suspend(struct aiocb const **, int, int /*<<< orphan*/ *);
int ps_test_aio_read_waitcomplete(struct aiocb *aiorp) {
  const struct aiocb *aioptr[1];
  int rv;
  aioptr[0] = aiorp;
  rv = ps_test_aio_suspend(aioptr, 1, NULL);
  rv = ps_test_aio_return(aiorp);
  printf("AIO complete, %d bytes read.\n", rv);
  return 1;
}


x86 assembly (clang, -O0):
<ps_test_aio_read_waitcomplete>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <ps_test_aio_suspend@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <ps_test_aio_return@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe91(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ps_test_aio_read_waitcomplete>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <ps_test_aio_suspend@plt>
mov    %rbx,%rdi
call   1050 <ps_test_aio_return@plt>
lea    0xea3(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.aiocb = type { i32 }
@.str = [30 x i8] c"AIO complete, %d bytes read.\0A\00"
define i32 @ps_test_aio_read_waitcomplete(%struct.aiocb* %0) {
%2 = alloca %struct.aiocb*
%3 = alloca [1 x %struct.aiocb*]
%4 = alloca i32
store %struct.aiocb* %0, %struct.aiocb** %2
%5 = load %struct.aiocb*, %struct.aiocb** %2
%6 = getelementptr inbounds [1 x %struct.aiocb*], [1 x %struct.aiocb*]* %3, i64 0, i64 0
store %struct.aiocb* %5, %struct.aiocb** %6
%7 = getelementptr inbounds [1 x %struct.aiocb*], [1 x %struct.aiocb*]* %3, i64 0, i64 0
%8 = call i32 @ps_test_aio_suspend(%struct.aiocb** %7, i32 1, i32* null)
store i32 %8, i32* %4
%9 = load %struct.aiocb*, %struct.aiocb** %2
%10 = call i32 @ps_test_aio_return(%struct.aiocb* %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %11)
ret i32 1
}

LLVM IR (-O2):
%struct.aiocb = type { i32 }
@.str = [30 x i8] c"AIO complete, %d bytes read.\0A\00"
define i32 @ps_test_aio_read_waitcomplete(%struct.aiocb* %0) {
%2 = alloca [1 x %struct.aiocb*]
%3 = bitcast [1 x %struct.aiocb*]* %2 to i8*
%4 = getelementptr inbounds [1 x %struct.aiocb*], [1 x %struct.aiocb*]* %2, i64 0, i64 0
store %struct.aiocb* %0, %struct.aiocb** %4
%5 = call i32 @ps_test_aio_suspend(%struct.aiocb** %4, i32 1, i32* null)
%6 = call i32 @ps_test_aio_return(%struct.aiocb* %0)
%7 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %6)
ret i32 1
}