#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*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int lseek(int, int, int /*<<< orphan*/);
off_t end_offset(int fd) {
  off_t orig_offset = lseek(fd, 0, SEEK_CUR);
  if (-1 == orig_offset) {
    return -1;
  }
  off_t end = lseek(fd, 0, SEEK_END);
  lseek(fd, orig_offset, SEEK_SET);
  return end;
}


x86 assembly (clang, -O0):
<end_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ebb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %eax,-0xc(%rbp)
mov    $0xffffffff,%eax
cmp    -0xc(%rbp),%eax
jne    114b <end_offset+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    117b <end_offset+0x6b>
mov    -0x8(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<end_offset>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    0x2ec3(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
cmp    $0xffffffff,%eax
je     1159 <end_offset+0x49>
mov    %eax,%ebp
mov    0x2eb4(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %eax,%r14d
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <lseek@plt>
mov    %r14d,%eax
jmp    115e <end_offset+0x4e>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @end_offset(i32 %0) {
%2 = load i32, i32* @SEEK_CUR
%3 = tail call i32 @lseek(i32 %0, i32 0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @lseek(i32 %0, i32 0, i32 %6)
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @lseek(i32 %0, i32 %3, i32 %8)
br label %10
10: ; preds = %1, %5
%11 = phi i32 [ %7, %5 ], [ -1, %1 ]
ret i32 %11
}