#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 */
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, unsigned char *, int);
int qaoed_file_read(int fd, unsigned char *buff, int len, off_t pos) {
  if (lseek(fd, pos, SEEK_SET) == -1) {
    perror("lseek");
    printf("fseek failed!\n");
    return (-1);
  }
  return (read(fd, buff, len));
}


x86 assembly (clang, -O0):
<qaoed_file_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1196 <qaoed_file_read+0x56>
lea    0xe87(%rip),%rdi
call   1060 <perror@plt>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a8 <qaoed_file_read+0x68>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qaoed_file_read>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e8d(%rip),%rax
mov    (%rax),%edx
mov    %ecx,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     1172 <qaoed_file_read+0x32>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <read@plt>
lea    0xe87(%rip),%rdi
call   1060 <perror@plt>
lea    0xe81(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [6 x i8] c"lseek\00"
@.str.1 = [15 x i8] c"fseek failed!\0A\00"
define i32 @qaoed_file_read(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%10 = load i32, i32* %6
%11 = load i32, i32* %9
%12 = load i32, i32* @SEEK_SET
%13 = call i32 @lseek(i32 %10, i32 %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
br label %23
18: ; preds = %4
%19 = load i32, i32* %6
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = call i32 @read(i32 %19, i8* %20, i32 %21)
store i32 %22, i32* %5
br label %23
23: ; preds = %18, %15
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [6 x i8] c"lseek\00"
@str = [14 x i8] c"fseek failed!\00"
define i32 @qaoed_file_read(i32 %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @lseek(i32 %0, i32 %3, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %13
11: ; preds = %4
%12 = tail call i32 @read(i32 %0, i8* %1, i32 %2)
br label %13
13: ; preds = %11, %8
%14 = phi i32 [ -1, %8 ], [ %12, %11 ]
ret i32 %14
}