#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 /*<<< orphan*/ off_t;

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ ENOSYS;
scalar_t__ errno;
long long lseek(unsigned int, int /*<<< orphan*/, unsigned int);
long long my_llseek(unsigned int, long long, unsigned int);
long long ext2_llseek(unsigned int fd, long long offset, unsigned int origin) {
  long long result;
  static int do_compat = 0;
  if (!do_compat) {
    result = my_llseek(fd, offset, origin);
    if (!(result == -1 && errno == ENOSYS))
      return result;
    do_compat = 1;
  }
  if ((sizeof(off_t) >= sizeof(long long)) ||
      (offset < ((long long)1 << ((sizeof(off_t) * 8) - 1))))
    return lseek(fd, (off_t)offset, origin);
  errno = EINVAL;
  return -1;
}


x86 assembly (clang, -O0):
<ext2_llseek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,0x2eff(%rip)
jne    118e <ext2_llseek+0x6e>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <my_llseek@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
jne    1177 <ext2_llseek+0x57>
mov    0x2e74(%rip),%rax
mov    (%rax),%rax
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%rax
je     1184 <ext2_llseek+0x64>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d3 <ext2_llseek+0xb3>
movl   $0x1,0x2eaa(%rip)
mov    $0x80000000,%eax
cmp    %rax,-0x18(%rbp)
jge    11b7 <ext2_llseek+0x97>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
call   1040 <lseek@plt>
mov    %rax,-0x8(%rbp)
jmp    11d3 <ext2_llseek+0xb3>
mov    0x2e12(%rip),%rax
mov    (%rax),%rcx
mov    0x2e10(%rip),%rax
mov    %rcx,(%rax)
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ext2_llseek>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
cmpb   $0x0,0x2f05(%rip)
je     114e <ext2_llseek+0x2e>
cmp    $0x7fffffff,%rbx
jg     118e <ext2_llseek+0x6e>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <lseek@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <my_llseek@plt>
cmp    $0xffffffffffffffff,%rax
jne    11a9 <ext2_llseek+0x89>
mov    0x2e70(%rip),%rax
mov    (%rax),%rcx
mov    0x2e76(%rip),%rdx
mov    $0xffffffffffffffff,%rax
cmp    (%rdx),%rcx
jne    11a9 <ext2_llseek+0x89>
movb   $0x1,0x2eb3(%rip)
cmp    $0x7fffffff,%rbx
jle    113e <ext2_llseek+0x1e>
mov    0x2e3b(%rip),%rax
mov    (%rax),%rax
mov    0x2e39(%rip),%rcx
mov    %rax,(%rcx)
mov    $0xffffffffffffffff,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@ext2_llseek.do_compat = internal global i32 0
@errno = global i64 0
@ENOSYS = global i64 0
@EINVAL = global i64 0
define i64 @ext2_llseek(i32 %0, i64 %1, i32 %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
store i32 %0, i32* %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%9 = load i32, i32* @ext2_llseek.do_compat
%10 = icmp ne i32 %9, 0
br i1 %10, label %25, label %11
11: ; preds = %3
%12 = load i32, i32* %5
%13 = load i64, i64* %6
%14 = load i32, i32* %7
%15 = call i64 @my_llseek(i32 %12, i64 %13, i32 %14)
store i64 %15, i64* %8
%16 = load i64, i64* %8
%17 = icmp eq i64 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = load i64, i64* @errno
%20 = load i64, i64* @ENOSYS
%21 = icmp eq i64 %19, %20
br i1 %21, label %24, label %22
22: ; preds = %18, %11
%23 = load i64, i64* %8
store i64 %23, i64* %4
br label %36
24: ; preds = %18
store i32 1, i32* @ext2_llseek.do_compat
br label %25
25: ; preds = %24, %3
%26 = load i64, i64* %6
%27 = icmp slt i64 %26, 2147483648
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i32, i32* %5
%30 = load i64, i64* %6
%31 = trunc i64 %30 to i32
%32 = load i32, i32* %7
%33 = call i64 @lseek(i32 %29, i32 %31, i32 %32)
store i64 %33, i64* %4
br label %36
34: ; preds = %25
%35 = load i64, i64* @EINVAL
store i64 %35, i64* @errno
store i64 -1, i64* %4
br label %36
36: ; preds = %34, %28, %22
%37 = load i64, i64* %4
ret i64 %37
}

LLVM IR (-O2):
@ext2_llseek.do_compat = internal unnamed_addr global i1 false
@errno = global i64 0
@ENOSYS = global i64 0
@EINVAL = global i64 0
define i64 @ext2_llseek(i32 %0, i64 %1, i32 %2) {
%4 = load i1, i1* @ext2_llseek.do_compat
br i1 %4, label %13, label %5
5: ; preds = %3
%6 = tail call i64 @my_llseek(i32 %0, i64 %1, i32 %2)
%7 = icmp eq i64 %6, -1
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOSYS
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %8
store i1 true, i1* @ext2_llseek.do_compat
br label %13
13: ; preds = %12, %3
%14 = icmp slt i64 %1, 2147483648
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = trunc i64 %1 to i32
%17 = tail call i64 @lseek(i32 %0, i32 %16, i32 %2)
br label %20
18: ; preds = %13
%19 = load i64, i64* @EINVAL
store i64 %19, i64* @errno
br label %20
20: ; preds = %5, %8, %18, %15
%21 = phi i64 [ %17, %15 ], [ -1, %18 ], [ -1, %8 ], [ %6, %5 ]
ret i64 %21
}