#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 scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
scalar_t__ lseek(int, scalar_t__, int /*<<< orphan*/);
size_t read(int, void *, size_t);
int xerror(char *);
int xseekread(int fd, off_t offset, void *buf, size_t bytes) {
  if (lseek(fd, offset, SEEK_SET) == (off_t)-1)
    return xerror("Seek failed");
  if (read(fd, buf, bytes) != bytes)
    return xerror("Read failed");
  return 1;
}


x86 assembly (clang, -O0):
<xseekread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    $0xffffffffffffffff,%rax
jne    117a <xseekread+0x4a>
lea    0xe93(%rip),%rdi
call   1040 <xerror@plt>
mov    %eax,-0x4(%rbp)
jmp    11af <xseekread+0x7f>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <read@plt>
cmp    -0x20(%rbp),%rax
je     11a8 <xseekread+0x78>
lea    0xe71(%rip),%rdi
call   1040 <xerror@plt>
mov    %eax,-0x4(%rbp)
jmp    11af <xseekread+0x7f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xseekread>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %edi,%ebp
mov    0x2e9d(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    $0xffffffffffffffff,%rax
je     116c <xseekread+0x3c>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <read@plt>
cmp    %rbx,%rax
jne    1175 <xseekread+0x45>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe8d(%rip),%rdi
jmp    117c <xseekread+0x4c>
lea    0xe90(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <xerror@plt>

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

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