#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 ps_test_aio_return(struct aiocb *);
scalar_t__ ps_test_aio_suspend(struct aiocb const **, int,
                               int /*<<< orphan*/ *);
int ps_read_wait(struct aiocb *block) {
  const struct aiocb *temp[1];
  temp[0] = block;
  if (ps_test_aio_suspend(temp, 1, NULL) != 0) {
    printf("Klaida skaitymo pabaigoje\n");
    return -1;
  }
  return ps_test_aio_return(block);
}


x86 assembly (clang, -O0):
<ps_read_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <ps_test_aio_suspend@plt>
cmp    $0x0,%rax
je     1178 <ps_read_wait+0x48>
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <ps_read_wait+0x54>
mov    -0x10(%rbp),%rdi
call   1050 <ps_test_aio_return@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ps_read_wait>:
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>
test   %rax,%rax
je     1166 <ps_read_wait+0x36>
lea    0xea6(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    116e <ps_read_wait+0x3e>
mov    %rbx,%rdi
call   1050 <ps_test_aio_return@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.aiocb = type { i32 }
@.str = [27 x i8] c"Klaida skaitymo pabaigoje\0A\00"
define i32 @ps_read_wait(%struct.aiocb* %0) {
%2 = alloca i32
%3 = alloca %struct.aiocb*
%4 = alloca [1 x %struct.aiocb*]
store %struct.aiocb* %0, %struct.aiocb** %3
%5 = load %struct.aiocb*, %struct.aiocb** %3
%6 = getelementptr inbounds [1 x %struct.aiocb*], [1 x %struct.aiocb*]* %4, i64 0, i64 0
store %struct.aiocb* %5, %struct.aiocb** %6
%7 = getelementptr inbounds [1 x %struct.aiocb*], [1 x %struct.aiocb*]* %4, i64 0, i64 0
%8 = call i64 @ps_test_aio_suspend(%struct.aiocb** %7, i32 1, i32* null)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %15
12: ; preds = %1
%13 = load %struct.aiocb*, %struct.aiocb** %3
%14 = call i32 @ps_test_aio_return(%struct.aiocb* %13)
store i32 %14, i32* %2
br label %15
15: ; preds = %12, %10
%16 = load i32, i32* %2
ret i32 %16
}

LLVM IR (-O2):
%struct.aiocb = type { i32 }
@str = [26 x i8] c"Klaida skaitymo pabaigoje\00"
define i32 @ps_read_wait(%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 i64 @ps_test_aio_suspend(%struct.aiocb** %4, i32 1, i32* null)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %11
9: ; preds = %1
%10 = call i32 @ps_test_aio_return(%struct.aiocb* %0)
br label %11
11: ; preds = %9, %7
%12 = phi i32 [ -1, %7 ], [ %10, %9 ]
ret i32 %12
}