#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 */

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
long lseek(int, long, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, unsigned char *, long);
int ifo_read(int fd, long pos, long count, unsigned char *data) {
  if ((pos = lseek(fd, pos, SEEK_SET)) < 0) {
    perror("ifo_read");
    return -1;
  }
  return read(fd, data, count);
}


x86 assembly (clang, -O0):
<ifo_read>:
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>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jge    1182 <ifo_read+0x52>
lea    0xe8f(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <ifo_read+0x65>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <read@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ifo_read>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %edi,%ebp
mov    0x2e9d(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
test   %rax,%rax
js     1160 <ifo_read+0x30>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <read@plt>
lea    0xe99(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [9 x i8] c"ifo_read\00"
define i32 @ifo_read(i32 %0, i64 %1, i64 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
store i32 %0, i32* %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i8* %3, i8** %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)
store i64 %13, i64* %7
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %22
17: ; preds = %4
%18 = load i32, i32* %6
%19 = load i8*, i8** %9
%20 = load i64, i64* %8
%21 = call i32 @read(i32 %18, i8* %19, i64 %20)
store i32 %21, i32* %5
br label %22
22: ; preds = %17, %15
%23 = load i32, i32* %5
ret i32 %23
}

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