#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*/ fseek(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
size_t getlen(FILE *fp) {
  size_t retval, curpos;
  if (!fp)
    return 0;
  curpos = ftell(fp);
  fseek(fp, 0, SEEK_END);
  retval = ftell(fp);
  fseek(fp, curpos, SEEK_SET);
  return retval;
}


x86 assembly (clang, -O0):
<getlen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <getlen+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1192 <getlen+0x72>
mov    -0x10(%rbp),%rdi
call   1030 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8c(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1030 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e55(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getlen>:
test   %rdi,%rdi
je     1170 <getlen+0x50>
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <ftell@plt>
mov    %rax,%r14
mov    0x2eac(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <fseek@plt>
mov    %rbx,%rdi
call   1030 <ftell@plt>
mov    %rax,%r15
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <fseek@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %eax,%eax
ret

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

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