#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;
  char *aio_buf;
  int aio_nbytes;
  scalar_t__ aio_offset;
};

/* Variables and functions */
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ ps_test_aio_read(struct aiocb *);
int ps_read_bytes(int desc, struct aiocb *block, char *buf, int bufOffset,
                  int bytes) {
  memset((void *)block, 0, sizeof(struct aiocb));
  block->aio_fildes = desc;
  block->aio_buf = buf + bufOffset;
  block->aio_nbytes = bytes;
  block->aio_offset = 0;
  if (ps_test_aio_read(block) != 0) {
    printf("Klaida skaitymo pradzioje\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ps_read_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rax
add    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,0x18(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <ps_test_aio_read@plt>
cmp    $0x0,%rax
je     11b7 <ps_read_bytes+0x87>
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <ps_read_bytes+0x8e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ps_read_bytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %ecx,%r13d
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r12d,%r12d
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    %ebp,(%rbx)
movslq %r13d,%rax
add    %r15,%rax
mov    %rax,0x8(%rbx)
mov    %r14d,0x10(%rbx)
movq   $0x0,0x18(%rbx)
mov    %rbx,%rdi
call   1050 <ps_test_aio_read@plt>
test   %rax,%rax
je     1192 <ps_read_bytes+0x62>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.aiocb = type { i32, i8*, i32, i64 }
@.str = [27 x i8] c"Klaida skaitymo pradzioje\0A\00"
define i32 @ps_read_bytes(i32 %0, %struct.aiocb* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.aiocb*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %7
store %struct.aiocb* %1, %struct.aiocb** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%12 = load %struct.aiocb*, %struct.aiocb** %8
%13 = bitcast %struct.aiocb* %12 to i8*
%14 = call i32 @memset(i8* %13, i32 0, i32 32)
%15 = load i32, i32* %7
%16 = load %struct.aiocb*, %struct.aiocb** %8
%17 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = load i8*, i8** %9
%19 = load i32, i32* %10
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load %struct.aiocb*, %struct.aiocb** %8
%23 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %22, i32 0, i32 1
store i8* %21, i8** %23
%24 = load i32, i32* %11
%25 = load %struct.aiocb*, %struct.aiocb** %8
%26 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %25, i32 0, i32 2
store i32 %24, i32* %26
%27 = load %struct.aiocb*, %struct.aiocb** %8
%28 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %27, i32 0, i32 3
store i64 0, i64* %28
%29 = load %struct.aiocb*, %struct.aiocb** %8
%30 = call i64 @ps_test_aio_read(%struct.aiocb* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %5
%33 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %6
br label %35
34: ; preds = %5
store i32 0, i32* %6
br label %35
35: ; preds = %34, %32
%36 = load i32, i32* %6
ret i32 %36
}

LLVM IR (-O2):
%struct.aiocb = type { i32, i8*, i32, i64 }
@str = [26 x i8] c"Klaida skaitymo pradzioje\00"
define i32 @ps_read_bytes(i32 %0, %struct.aiocb* %1, i8* %2, i32 %3, i32 %4) {
%6 = bitcast %struct.aiocb* %1 to i8*
%7 = tail call i32 @memset(i8* %6, i32 0, i32 32)
%8 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %1, i64 0, i32 0
store i32 %0, i32* %8
%9 = sext i32 %3 to i64
%10 = getelementptr inbounds i8, i8* %2, i64 %9
%11 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %1, i64 0, i32 1
store i8* %10, i8** %11
%12 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %1, i64 0, i32 2
store i32 %4, i32* %12
%13 = getelementptr inbounds %struct.aiocb, %struct.aiocb* %1, i64 0, i32 3
store i64 0, i64* %13
%14 = tail call i64 @ps_test_aio_read(%struct.aiocb* %1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %5
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %5, %16
%19 = phi i32 [ -1, %16 ], [ 0, %5 ]
ret i32 %19
}