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

/* Variables and functions */
int /*<<< orphan*/ EBADF;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ENOSYS;
#define SEEK_CUR 130
#define SEEK_END 129
#define SEEK_SET 128
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
off_t __libc_lseek(int fd, off_t offset, int whence) {
  if (fd < 0) {
    __set_errno(EBADF);
    return -1;
  }
  switch (whence) {
  case SEEK_SET:
  case SEEK_CUR:
  case SEEK_END:
    break;
  default:
    __set_errno(EINVAL);
    return -1;
  }
  __set_errno(ENOSYS);
  return -1;
}


x86 assembly (clang, -O0):
<__libc_lseek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1145 <__libc_lseek+0x35>
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <__libc_lseek+0x7d>
mov    -0x10(%rbp),%eax
add    $0xffffff80,%eax
sub    $0x2,%eax
ja     115e <__libc_lseek+0x4e>
jmp    1159 <__libc_lseek+0x49>
jmp    1178 <__libc_lseek+0x68>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <__libc_lseek+0x7d>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__libc_lseek>:
push   %rax
add    $0xffffff80,%edx
cmp    $0x3,%edx
jae    1126 <__libc_lseek+0x16>
mov    0x2ec8(%rip),%rax
test   %edi,%edi
js     1131 <__libc_lseek+0x21>
jmp    1138 <__libc_lseek+0x28>
mov    0x2eab(%rip),%rax
test   %edi,%edi
jns    1138 <__libc_lseek+0x28>
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@EBADF = global i32 0
@EINVAL = global i32 0
@ENOSYS = global i32 0
define i32 @__libc_lseek(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i32, i32* @EBADF
%12 = call i32 @__set_errno(i32 %11)
store i32 -1, i32* %4
br label %22
13: ; preds = %3
%14 = load i32, i32* %7
switch i32 %14, label %16 [
i32 128, label %15
i32 130, label %15
i32 129, label %15
]
15: ; preds = %13, %13, %13
br label %19
16: ; preds = %13
%17 = load i32, i32* @EINVAL
%18 = call i32 @__set_errno(i32 %17)
store i32 -1, i32* %4
br label %22
19: ; preds = %15
%20 = load i32, i32* @ENOSYS
%21 = call i32 @__set_errno(i32 %20)
store i32 -1, i32* %4
br label %22
22: ; preds = %19, %16, %10
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@EBADF = global i32 0
@EINVAL = global i32 0
@ENOSYS = global i32 0
define i32 @__libc_lseek(i32 %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %0, 0
%5 = add i32 %2, -128
%6 = icmp ult i32 %5, 3
%7 = load i32, i32* @EBADF
%8 = load i32, i32* @ENOSYS
%9 = load i32, i32* @EINVAL
%10 = select i1 %6, i32 %8, i32 %9
%11 = select i1 %4, i32 %7, i32 %10
%12 = tail call i32 @__set_errno(i32 %11)
ret i32 -1
}