#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__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
scalar_t__ lseek(int, size_t, int /*<<< orphan*/);
scalar_t__ xread(int, void *, size_t);
ssize_t xread_offset(int fd, void *buf, size_t offset, size_t len) {
  ssize_t n;
  n = lseek(fd, offset, SEEK_SET);
  if (n < 0)
    return n;
  n = xread(fd, buf, len);
  if (n < 0)
    return n;
  return 0;
}


x86 assembly (clang, -O0):
<xread_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1168 <xread_offset+0x48>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119c <xread_offset+0x7c>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <xread@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    1194 <xread_offset+0x74>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119c <xread_offset+0x7c>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xread_offset>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %rdx,%rsi
mov    %eax,%edx
call   1030 <lseek@plt>
test   %rax,%rax
js     115b <xread_offset+0x3b>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <xread@plt>
mov    %rax,%rcx
sar    $0x3f,%rax
and    %rcx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i64 @xread_offset(i32 %0, i8* %1, i64 %2, i64 %3) {
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32 %0, i32* %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
%11 = load i32, i32* %6
%12 = load i64, i64* %8
%13 = load i32, i32* @SEEK_SET
%14 = call i64 @lseek(i32 %11, i64 %12, i32 %13)
store i64 %14, i64* %10
%15 = load i64, i64* %10
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i64, i64* %10
store i64 %18, i64* %5
br label %29
19: ; preds = %4
%20 = load i32, i32* %6
%21 = load i8*, i8** %7
%22 = load i64, i64* %9
%23 = call i64 @xread(i32 %20, i8* %21, i64 %22)
store i64 %23, i64* %10
%24 = load i64, i64* %10
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = load i64, i64* %10
store i64 %27, i64* %5
br label %29
28: ; preds = %19
store i64 0, i64* %5
br label %29
29: ; preds = %28, %26, %17
%30 = load i64, i64* %5
ret i64 %30
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i64 @xread_offset(i32 %0, i8* %1, i64 %2, i64 %3) {
%5 = load i32, i32* @SEEK_SET
%6 = tail call i64 @lseek(i32 %0, i64 %2, i32 %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = tail call i64 @xread(i32 %0, i8* %1, i64 %3)
%10 = icmp slt i64 %9, 0
%11 = select i1 %10, i64 %9, i64 0
br label %12
12: ; preds = %8, %4
%13 = phi i64 [ %6, %4 ], [ %11, %8 ]
ret i64 %13
}