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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *const, long const,
                         int /*<<< orphan*/);
long const ftell(int /*<<< orphan*/ *const);
size_t get_remaining_stream_size(FILE *const fp) {
  size_t remaining_size;
  const long pos = ftell(fp);
  assert(pos >= 0 && "Stream expected to support seek operation.");
  (void)fseek(fp, 0, SEEK_END);
  remaining_size = ftell(fp) - pos;
  (void)fseek(fp, pos, SEEK_SET);
  return remaining_size;
}


x86 assembly (clang, -O0):
<get_remaining_stream_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jl     1163 <get_remaining_stream_size+0x33>
mov    $0x1,%al
mov    %al,-0x19(%rbp)
jmp    1163 <get_remaining_stream_size+0x33>
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1050 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
sub    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_remaining_stream_size>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1040 <ftell@plt>
mov    %rax,%r14
mov    %rax,%rdi
shr    $0x3f,%rdi
xor    $0x1,%edi
call   1030 <assert@plt>
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
mov    %r15,%rdi
call   1040 <ftell@plt>
mov    %rax,%rbx
sub    %r14,%rbx
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <fseek@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Stream expected to support seek operation.\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i64 @get_remaining_stream_size(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i64
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = call i64 @ftell(i32* %5)
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp sge i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
br label %10
10: ; preds = %9, %1
%11 = phi i1 [ false, %1 ], [ true, %9 ]
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32*, i32** %2
%15 = load i32, i32* @SEEK_END
%16 = call i32 @fseek(i32* %14, i64 0, i32 %15)
%17 = load i32*, i32** %2
%18 = call i64 @ftell(i32* %17)
%19 = load i64, i64* %4
%20 = sub nsw i64 %18, %19
store i64 %20, i64* %3
%21 = load i32*, i32** %2
%22 = load i64, i64* %4
%23 = load i32, i32* @SEEK_SET
%24 = call i32 @fseek(i32* %21, i64 %22, i32 %23)
%25 = load i64, i64* %3
ret i64 %25
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i64 @get_remaining_stream_size(i32* nocapture %0) {
%2 = tail call i64 @ftell(i32* %0)
%3 = lshr i64 %2, 63
%4 = trunc i64 %3 to i32
%5 = xor i32 %4, 1
%6 = tail call i32 @assert(i32 %5)
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @fseek(i32* %0, i64 0, i32 %7)
%9 = tail call i64 @ftell(i32* %0)
%10 = sub nsw i64 %9, %2
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @fseek(i32* %0, i64 %2, i32 %11)
ret i64 %10
}