#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*/ __hosted_from_gdb_errno(int);
int /*<<< orphan*/ __hosted_to_gdb_lseek_flags(int);
scalar_t__ do_syscall(int, int, scalar_t__, int /*<<< orphan*/,
                      int /*<<< orphan*/, int *);
int /*<<< orphan*/ errno;
off_t lseek(int fildes, off_t offset, int whence) {
  off_t ret;
  int error;
  ret = do_syscall(7, fildes, offset, __hosted_to_gdb_lseek_flags(whence), 0,
                   &error);
  if (ret == (off_t)-1)
    errno = __hosted_from_gdb_errno(error);
  return ret;
}


x86 assembly (clang, -O0):
<lseek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <__hosted_to_gdb_lseek_flags@plt>
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
mov    $0x7,%edi
xor    %r8d,%r8d
lea    -0x24(%rbp),%r9
call   1030 <do_syscall@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    1194 <lseek+0x64>
mov    -0x24(%rbp),%edi
call   1040 <__hosted_from_gdb_errno@plt>
mov    %eax,%ecx
mov    0x2e4e(%rip),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lseek>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %edx,%edi
call   1050 <__hosted_to_gdb_lseek_flags@plt>
lea    0x4(%rsp),%r9
mov    $0x7,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1030 <do_syscall@plt>
mov    %rax,%rbx
cmp    $0xffffffffffffffff,%rax
jne    1173 <lseek+0x43>
mov    0x4(%rsp),%edi
call   1040 <__hosted_from_gdb_errno@plt>
mov    0x2e6f(%rip),%rcx
mov    %eax,(%rcx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define i64 @lseek(i32 %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
%10 = load i64, i64* %5
%11 = load i32, i32* %6
%12 = call i32 @__hosted_to_gdb_lseek_flags(i32 %11)
%13 = call i64 @do_syscall(i32 7, i32 %9, i64 %10, i32 %12, i32 0, i32* %8)
store i64 %13, i64* %7
%14 = load i64, i64* %7
%15 = icmp eq i64 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i32, i32* %8
%18 = call i32 @__hosted_from_gdb_errno(i32 %17)
store i32 %18, i32* @errno
br label %19
19: ; preds = %16, %3
%20 = load i64, i64* %7
ret i64 %20
}

LLVM IR (-O2):
@errno = global i32 0
define i64 @lseek(i32 %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 @__hosted_to_gdb_lseek_flags(i32 %2)
%7 = call i64 @do_syscall(i32 7, i32 %0, i64 %1, i32 %6, i32 0, i32* %4)
%8 = icmp eq i64 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* %4
%11 = call i32 @__hosted_from_gdb_errno(i32 %10)
store i32 %11, i32* @errno
br label %12
12: ; preds = %9, %3
ret i64 %7
}