#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);
int fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
long FileLen(FILE *f) {
  long pos1 = ftell(f);
  int res = fseek(f, 0, SEEK_END);
  assert(res == 0);
  long pos2 = ftell(f);
  res = fseek(f, pos1, SEEK_SET);
  assert((res == 0) && "Could not rewind file");
  return pos2;
}


x86 assembly (clang, -O0):
<FileLen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e94(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1050 <fseek@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x21(%rbp)
jne    11b2 <FileLen+0x82>
mov    $0x1,%al
mov    %al,-0x21(%rbp)
jmp    11b2 <FileLen+0x82>
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileLen>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <ftell@plt>
mov    %rax,%r14
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <fseek@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
call   1040 <ftell@plt>
mov    %rax,%r15
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fseek@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1030 <assert@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str = [22 x i8] c"Could not rewind file\00"
define i64 @FileLen(i32* %0) {
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i64
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = call i64 @ftell(i32* %6)
store i64 %7, i64* %3
%8 = load i32*, i32** %2
%9 = load i32, i32* @SEEK_END
%10 = call i32 @fseek(i32* %8, i64 0, i32 %9)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32*, i32** %2
%16 = call i64 @ftell(i32* %15)
store i64 %16, i64* %5
%17 = load i32*, i32** %2
%18 = load i64, i64* %3
%19 = load i32, i32* @SEEK_SET
%20 = call i32 @fseek(i32* %17, i64 %18, i32 %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %1
br label %24
24: ; preds = %23, %1
%25 = phi i1 [ false, %1 ], [ true, %23 ]
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i64, i64* %5
ret i64 %28
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i64 @FileLen(i32* nocapture %0) {
%2 = tail call i64 @ftell(i32* %0)
%3 = load i32, i32* @SEEK_END
%4 = tail call i32 @fseek(i32* %0, i64 0, i32 %3)
%5 = icmp eq i32 %4, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i64 @ftell(i32* %0)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek(i32* %0, i64 %2, i32 %9)
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
ret i64 %8
}