#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_END;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ check(int /*<<< orphan*/, char *);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ lseek(int, scalar_t__, int /*<<< orphan*/);
void check_seek(int fd, off_t off, const char *err_msg) {
  off_t end_off = check(lseek(fd, 0, SEEK_END), "lseek()");
  if (off >= end_off) {
    err(1, "lseek over end of file");
  }
  check(lseek(fd, off, SEEK_SET), "lseek()");
}


x86 assembly (clang, -O0):
<check_seek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1030 <lseek@plt>
mov    %eax,%edi
lea    0xe9f(%rip),%rsi
call   1050 <check@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jl     1189 <check_seek+0x59>
mov    $0x1,%edi
lea    0xe84(%rip),%rsi
call   1040 <err@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
mov    %eax,%edi
lea    0xe59(%rip),%rsi
call   1050 <check@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_seek>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
lea    0xeb1(%rip),%rsi
mov    %eax,%edi
call   1050 <check@plt>
cmp    %rbx,%rax
jg     116c <check_seek+0x3c>
lea    0xea6(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <lseek@plt>
lea    0xe7a(%rip),%rsi
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <check@plt>

LLVM IR (-O0):
@SEEK_END = global i32 0
@.str = [8 x i8] c"lseek()\00"
@.str.1 = [23 x i8] c"lseek over end of file\00"
@SEEK_SET = global i32 0
define void @check_seek(i32 %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
store i32 %0, i32* %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%8 = load i32, i32* %4
%9 = load i32, i32* @SEEK_END
%10 = call i32 @lseek(i32 %8, i64 0, i32 %9)
%11 = call i64 @check(i32 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i64 %11, i64* %7
%12 = load i64, i64* %5
%13 = load i64, i64* %7
%14 = icmp sge i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @err(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %3
%18 = load i32, i32* %4
%19 = load i64, i64* %5
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @lseek(i32 %18, i64 %19, i32 %20)
%22 = call i64 @check(i32 %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@.str = [8 x i8] c"lseek()\00"
@.str.1 = [23 x i8] c"lseek over end of file\00"
@SEEK_SET = global i32 0
define void @check_seek(i32 %0, i64 %1, i8* nocapture readnone %2) {
%4 = load i32, i32* @SEEK_END
%5 = tail call i32 @lseek(i32 %0, i64 0, i32 %4)
%6 = tail call i64 @check(i32 %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%7 = icmp sgt i64 %6, %1
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %3
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @lseek(i32 %0, i64 %1, i32 %11)
%13 = tail call i64 @check(i32 %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
ret void
}